comparison t/proxy_keepalive.t @ 48:450ad1052368 draft

Keepalive: tests style fixes.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 24 Jan 2013 01:54:11 +0400
parents 5cab730994f3
children
comparison
equal deleted inserted replaced
47:5cab730994f3 48:450ad1052368
215 215
216 ############################################################################### 216 ###############################################################################
217 217
218 sub http_daemon { 218 sub http_daemon {
219 my $server = IO::Socket::INET->new( 219 my $server = IO::Socket::INET->new(
220 Proto => 'tcp', 220 Proto => 'tcp',
221 LocalHost => '127.0.0.1:8081', 221 LocalHost => '127.0.0.1:8081',
222 Listen => 5, 222 Listen => 5,
223 Reuse => 1 223 Reuse => 1
224 ) 224 )
225 or die "Can't create listening socket: $!\n"; 225 or die "Can't create listening socket: $!\n";
226 226
227 my $ccount = 0; 227 my $ccount = 0;
228 my $rcount = 0; 228 my $rcount = 0;
229 229
230 # dumb server which is able to keep connections alive 230 # dumb server which is able to keep connections alive
231 231
232 while (my $client = $server->accept()) { 232 while (my $client = $server->accept()) {
233 Test::Nginx::log_core('||', "connection from " . $client->peerhost()); 233 Test::Nginx::log_core('||',
234 $client->autoflush(1); 234 "connection from " . $client->peerhost());
235 $client->autoflush(1);
235 $ccount++; 236 $ccount++;
236 237
237 while (1) { 238 while (1) {
238 my $headers = ''; 239 my $headers = '';
239 my $uri = ''; 240 my $uri = '';
240 241
241 while (<$client>) { 242 while (<$client>) {
242 Test::Nginx::log_core('||', $_); 243 Test::Nginx::log_core('||', $_);
243 $headers .= $_; 244 $headers .= $_;
244 last if (/^\x0d?\x0a?$/); 245 last if (/^\x0d?\x0a?$/);
245 } 246 }
246 247
247 last if $headers eq ''; 248 last if $headers eq '';
248 $rcount++; 249 $rcount++;
249 250
250 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; 251 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i;
257 "Content-Length: 26" . CRLF . CRLF; 258 "Content-Length: 26" . CRLF . CRLF;
258 print $client "TEST-OK-IF-YOU-SEE-THIS" . 259 print $client "TEST-OK-IF-YOU-SEE-THIS" .
259 sprintf("%03d", $ccount) 260 sprintf("%03d", $ccount)
260 unless $headers =~ /^HEAD/i; 261 unless $headers =~ /^HEAD/i;
261 262
262 } elsif ($uri =~ m/empty/) { 263 } elsif ($uri =~ m/empty/) {
263 print $client 264 print $client
264 "HTTP/1.1 200 OK" . CRLF . 265 "HTTP/1.1 200 OK" . CRLF .
265 "X-Request: $rcount" . CRLF . 266 "X-Request: $rcount" . CRLF .
266 "X-Connection: $ccount" . CRLF . 267 "X-Connection: $ccount" . CRLF .
267 "Content-Length: 0" . CRLF . CRLF; 268 "Content-Length: 0" . CRLF . CRLF;
268 269
269 } elsif ($uri =~ m/304nolen/) { 270 } elsif ($uri =~ m/304nolen/) {
270 print $client 271 print $client
271 "HTTP/1.1 304 Not Modified" . CRLF . 272 "HTTP/1.1 304 Not Modified" . CRLF .
272 "X-Request: $rcount" . CRLF . 273 "X-Request: $rcount" . CRLF .
273 "X-Connection: $ccount" . CRLF . CRLF; 274 "X-Connection: $ccount" . CRLF . CRLF;
274 275
275 } elsif ($uri =~ m/304len/) { 276 } elsif ($uri =~ m/304len/) {
276 print $client 277 print $client
277 "HTTP/1.1 304 Not Modified" . CRLF . 278 "HTTP/1.1 304 Not Modified" . CRLF .
278 "X-Request: $rcount" . CRLF . 279 "X-Request: $rcount" . CRLF .
279 "X-Connection: $ccount" . CRLF . 280 "X-Connection: $ccount" . CRLF .
280 "Content-Length: 100" . CRLF . CRLF; 281 "Content-Length: 100" . CRLF . CRLF;
317 "0" . CRLF; 318 "0" . CRLF;
318 select undef, undef, undef, 0.05; 319 select undef, undef, undef, 0.05;
319 print $client CRLF; 320 print $client CRLF;
320 } 321 }
321 322
322 } elsif ($uri =~ m/chunk0/) { 323 } elsif ($uri =~ m/chunk0/) {
323 print $client 324 print $client
324 "HTTP/1.1 200 OK" . CRLF . 325 "HTTP/1.1 200 OK" . CRLF .
325 "X-Request: $rcount" . CRLF . 326 "X-Request: $rcount" . CRLF .
326 "X-Connection: $ccount" . CRLF . 327 "X-Connection: $ccount" . CRLF .
327 "Transfer-Encoding: chunked" . CRLF . 328 "Transfer-Encoding: chunked" . CRLF .
339 "Content-Length: 12" . CRLF . CRLF . 340 "Content-Length: 12" . CRLF . CRLF .
340 "0123456789" . CRLF; 341 "0123456789" . CRLF;
341 last; 342 last;
342 343
343 } else { 344 } else {
344 print $client 345 print $client
345 "HTTP/1.1 404 Not Found" . CRLF . 346 "HTTP/1.1 404 Not Found" . CRLF .
346 "X-Request: $rcount" . CRLF . 347 "X-Request: $rcount" . CRLF .
347 "X-Connection: $ccount" . CRLF . 348 "X-Connection: $ccount" . CRLF .
348 "Connection: close" . CRLF . CRLF . 349 "Connection: close" . CRLF . CRLF .
349 "Oops, '$uri' not found" . CRLF; 350 "Oops, '$uri' not found" . CRLF;
350 last; 351 last;
351 } 352 }
352 } 353 }
353 354
354 close $client; 355 close $client;
355 } 356 }
356 } 357 }
357 358
358 ############################################################################### 359 ###############################################################################