comparison proxy.t @ 83:6e5884419e4a

Tests: whitespace cleanup.
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 12 Apr 2009 06:46:21 +0400
parents 726c3c2a8b8c
children 1c0ec30614c6
comparison
equal deleted inserted replaced
82:a2fc9b9e9a2b 83:6e5884419e4a
64 64
65 ############################################################################### 65 ###############################################################################
66 66
67 sub http_daemon { 67 sub http_daemon {
68 my $server = IO::Socket::INET->new( 68 my $server = IO::Socket::INET->new(
69 Proto => 'tcp', 69 Proto => 'tcp',
70 LocalHost => '127.0.0.1:8081', 70 LocalHost => '127.0.0.1:8081',
71 Listen => 5, 71 Listen => 5,
72 Reuse => 1 72 Reuse => 1
73 ) 73 )
74 or die "Can't create listening socket: $!\n"; 74 or die "Can't create listening socket: $!\n";
75 75
76 while (my $client = $server->accept()) { 76 while (my $client = $server->accept()) {
77 $client->autoflush(1); 77 $client->autoflush(1);
78 78
79 my $headers = ''; 79 my $headers = '';
80 my $uri = ''; 80 my $uri = '';
81 81
82 while (<$client>) { 82 while (<$client>) {
83 $headers .= $_; 83 $headers .= $_;
84 last if (/^\x0d?\x0a?$/); 84 last if (/^\x0d?\x0a?$/);
85 } 85 }
86 86
87 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; 87 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i;
88 88
89 if ($uri eq '/') { 89 if ($uri eq '/') {
90 print $client <<'EOF'; 90 print $client <<'EOF';
95 print $client "TEST-OK-IF-YOU-SEE-THIS" 95 print $client "TEST-OK-IF-YOU-SEE-THIS"
96 unless $headers =~ /^HEAD/i; 96 unless $headers =~ /^HEAD/i;
97 97
98 } elsif ($uri eq '/multi') { 98 } elsif ($uri eq '/multi') {
99 99
100 print $client <<"EOF"; 100 print $client <<"EOF";
101 HTTP/1.1 200 OK 101 HTTP/1.1 200 OK
102 Connection: close 102 Connection: close
103 103
104 TEST-OK-IF-YOU-SEE-THIS 104 TEST-OK-IF-YOU-SEE-THIS
105 EOF 105 EOF
107 select undef, undef, undef, 0.1; 107 select undef, undef, undef, 0.1;
108 print $client 'AND-THIS'; 108 print $client 'AND-THIS';
109 109
110 } else { 110 } else {
111 111
112 print $client <<"EOF"; 112 print $client <<"EOF";
113 HTTP/1.1 404 Not Found 113 HTTP/1.1 404 Not Found
114 Connection: close 114 Connection: close
115 115
116 Oops, '$uri' not found 116 Oops, '$uri' not found
117 EOF 117 EOF
118 } 118 }
119 119
120 close $client; 120 close $client;
121 } 121 }
122 } 122 }
123 123
124 ############################################################################### 124 ###############################################################################