comparison fastcgi_request_buffering_chunked.t @ 545:dbf8fb0f3d30

Tests: fixed unbuffered request body tests. In particular, made sure that the whole request body is read on backend.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 08 Apr 2015 20:16:40 +0300
parents e7e3ced702f5
children 907e89fba9c3
comparison
equal deleted inserted replaced
544:e82bbe71f50c 545:dbf8fb0f3d30
51 fastcgi_request_buffering off; 51 fastcgi_request_buffering off;
52 fastcgi_param REQUEST_URI $request_uri; 52 fastcgi_param REQUEST_URI $request_uri;
53 53
54 location / { 54 location / {
55 client_body_buffer_size 2k; 55 client_body_buffer_size 2k;
56 add_header X-Body "$request_body";
57 fastcgi_pass 127.0.0.1:8081; 56 fastcgi_pass 127.0.0.1:8081;
58 } 57 }
59 location /single { 58 location /single {
60 client_body_in_single_buffer on; 59 client_body_in_single_buffer on;
61 add_header X-Body "$request_body";
62 fastcgi_pass 127.0.0.1:8081; 60 fastcgi_pass 127.0.0.1:8081;
63 } 61 }
64 location /preread { 62 location /preread {
65 fastcgi_pass 127.0.0.1:8082; 63 fastcgi_pass 127.0.0.1:8082;
66 } 64 }
82 80
83 $t->waitforsocket('127.0.0.1:8081'); 81 $t->waitforsocket('127.0.0.1:8081');
84 82
85 ############################################################################### 83 ###############################################################################
86 84
87 unlike(http_get('/'), qr/X-Body:/ms, 'no body'); 85 like(http_get('/'), qr/X-Body: \x0d\x0a?/ms, 'no body');
88 86
89 like(http_get_body('/', '0123456789'), 87 like(http_get_body('/', '0123456789'),
90 qr/X-Body: 0123456789\x0d?$/ms, 'body'); 88 qr/X-Body: 0123456789\x0d?$/ms, 'body');
91 89
92 like(http_get_body('/', '0123456789' x 128), 90 like(http_get_body('/', '0123456789' x 128),
153 my $last = pop; 151 my $last = pop;
154 return http( join '', (map { 152 return http( join '', (map {
155 my $body = $_; 153 my $body = $_;
156 "GET $uri HTTP/1.1" . CRLF 154 "GET $uri HTTP/1.1" . CRLF
157 . "Host: localhost" . CRLF 155 . "Host: localhost" . CRLF
158 . "Content-Length: " . (length $body) . CRLF . CRLF 156 . "Transfer-Encoding: chunked" . CRLF . CRLF
159 . $body 157 . sprintf("%x", length $body) . CRLF
158 . $body . CRLF
159 . "0" . CRLF . CRLF
160 } @_), 160 } @_),
161 "GET $uri HTTP/1.1" . CRLF 161 "GET $uri HTTP/1.1" . CRLF
162 . "Host: localhost" . CRLF 162 . "Host: localhost" . CRLF
163 . "Connection: close" . CRLF 163 . "Connection: close" . CRLF
164 . "Content-Length: " . (length $last) . CRLF . CRLF 164 . "Transfer-Encoding: chunked" . CRLF . CRLF
165 . $last 165 . sprintf("%x", length $last) . CRLF
166 . $last . CRLF
167 . "0" . CRLF . CRLF
166 ); 168 );
167 } 169 }
168 170
169 # Simple FastCGI responder implementation. 171 # Simple FastCGI responder implementation.
170 172
376 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5); 378 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5);
377 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, 379 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
378 $socket); 380 $socket);
379 381
380 my $count; 382 my $count;
383 my ($body, $buf);
384
381 while( $request->Accept() >= 0 ) { 385 while( $request->Accept() >= 0 ) {
382 $count++; 386 $count++;
383 387 $body = '';
384 if ($ENV{REQUEST_URI} eq '/stderr') { 388
385 warn "sample stderr text" x 512; 389 do {
386 } 390 read(STDIN, $buf, 1024);
391 $body .= $buf;
392 } while (length $buf);
387 393
388 if ($ENV{REQUEST_URI} eq '/error_page') { 394 if ($ENV{REQUEST_URI} eq '/error_page') {
389 print "Status: 404 Not Found" . CRLF . CRLF; 395 print "Status: 404 Not Found" . CRLF . CRLF;
390 next; 396 next;
391 } 397 }
392 398
393 print <<EOF; 399 print <<EOF;
394 Location: http://127.0.0.1:8080/redirect 400 Location: http://127.0.0.1:8080/redirect
395 Content-Type: text/html 401 Content-Type: text/html
402 X-Body: $body
396 403
397 SEE-THIS 404 SEE-THIS
398 $count 405 $count
399 EOF 406 EOF
400 } 407 }