Mercurial > hg > nginx-tests
changeset 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 | e82bbe71f50c |
children | fa48f8a195a3 |
files | fastcgi_request_buffering.t fastcgi_request_buffering_chunked.t proxy_request_buffering.t proxy_request_buffering_chunked.t proxy_request_buffering_ssl.t |
diffstat | 5 files changed, 35 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/fastcgi_request_buffering.t Tue Apr 07 16:45:14 2015 +0300 +++ b/fastcgi_request_buffering.t Wed Apr 08 20:16:40 2015 +0300 @@ -49,15 +49,14 @@ client_header_buffer_size 1k; fastcgi_request_buffering off; fastcgi_param REQUEST_URI $request_uri; + fastcgi_param CONTENT_LENGTH $content_length; location / { client_body_buffer_size 2k; - add_header X-Body "$request_body"; fastcgi_pass 127.0.0.1:8081; } location /single { client_body_in_single_buffer on; - add_header X-Body "$request_body"; fastcgi_pass 127.0.0.1:8081; } location /preread { @@ -83,7 +82,7 @@ ############################################################################### -unlike(http_get('/'), qr/X-Body:/ms, 'no body'); +like(http_get('/'), qr/X-Body: \x0d\x0a?/ms, 'no body'); like(http_get_body('/', '0123456789'), qr/X-Body: 0123456789\x0d?$/ms, 'body'); @@ -337,12 +336,11 @@ $socket); my $count; + my $body; + while( $request->Accept() >= 0 ) { $count++; - - if ($ENV{REQUEST_URI} eq '/stderr') { - warn "sample stderr text" x 512; - } + read(STDIN, $body, $ENV{'CONTENT_LENGTH'}); if ($ENV{REQUEST_URI} eq '/error_page') { print "Status: 404 Not Found" . CRLF . CRLF; @@ -352,6 +350,7 @@ print <<EOF; Location: http://127.0.0.1:8080/redirect Content-Type: text/html +X-Body: $body SEE-THIS $count
--- a/fastcgi_request_buffering_chunked.t Tue Apr 07 16:45:14 2015 +0300 +++ b/fastcgi_request_buffering_chunked.t Wed Apr 08 20:16:40 2015 +0300 @@ -53,12 +53,10 @@ location / { client_body_buffer_size 2k; - add_header X-Body "$request_body"; fastcgi_pass 127.0.0.1:8081; } location /single { client_body_in_single_buffer on; - add_header X-Body "$request_body"; fastcgi_pass 127.0.0.1:8081; } location /preread { @@ -84,7 +82,7 @@ ############################################################################### -unlike(http_get('/'), qr/X-Body:/ms, 'no body'); +like(http_get('/'), qr/X-Body: \x0d\x0a?/ms, 'no body'); like(http_get_body('/', '0123456789'), qr/X-Body: 0123456789\x0d?$/ms, 'body'); @@ -155,14 +153,18 @@ my $body = $_; "GET $uri HTTP/1.1" . CRLF . "Host: localhost" . CRLF - . "Content-Length: " . (length $body) . CRLF . CRLF - . $body + . "Transfer-Encoding: chunked" . CRLF . CRLF + . sprintf("%x", length $body) . CRLF + . $body . CRLF + . "0" . CRLF . CRLF } @_), "GET $uri HTTP/1.1" . CRLF . "Host: localhost" . CRLF . "Connection: close" . CRLF - . "Content-Length: " . (length $last) . CRLF . CRLF - . $last + . "Transfer-Encoding: chunked" . CRLF . CRLF + . sprintf("%x", length $last) . CRLF + . $last . CRLF + . "0" . CRLF . CRLF ); } @@ -378,12 +380,16 @@ $socket); my $count; + my ($body, $buf); + while( $request->Accept() >= 0 ) { $count++; + $body = ''; - if ($ENV{REQUEST_URI} eq '/stderr') { - warn "sample stderr text" x 512; - } + do { + read(STDIN, $buf, 1024); + $body .= $buf; + } while (length $buf); if ($ENV{REQUEST_URI} eq '/error_page') { print "Status: 404 Not Found" . CRLF . CRLF; @@ -393,6 +399,7 @@ print <<EOF; Location: http://127.0.0.1:8080/redirect Content-Type: text/html +X-Body: $body SEE-THIS $count
--- a/proxy_request_buffering.t Tue Apr 07 16:45:14 2015 +0300 +++ b/proxy_request_buffering.t Wed Apr 08 20:16:40 2015 +0300 @@ -80,7 +80,7 @@ server_name localhost; location / { - return 204; + proxy_pass http://127.0.0.1:8080/discard; } location /404 { } }
--- a/proxy_request_buffering_chunked.t Tue Apr 07 16:45:14 2015 +0300 +++ b/proxy_request_buffering_chunked.t Wed Apr 08 20:16:40 2015 +0300 @@ -81,7 +81,7 @@ server_name localhost; location / { - return 204; + proxy_pass http://127.0.0.1:8080/discard; } location /404 { } } @@ -193,14 +193,18 @@ my $body = $_; "GET $uri HTTP/1.1" . CRLF . "Host: localhost" . CRLF - . "Content-Length: " . (length $body) . CRLF . CRLF - . $body + . "Transfer-Encoding: chunked" . CRLF . CRLF + . sprintf("%x", length $body) . CRLF + . $body . CRLF + . "0" . CRLF . CRLF } @_), "GET $uri HTTP/1.1" . CRLF . "Host: localhost" . CRLF . "Connection: close" . CRLF - . "Content-Length: " . (length $last) . CRLF . CRLF - . $last + . "Transfer-Encoding: chunked" . CRLF . CRLF + . sprintf("%x", length $last) . CRLF + . $last . CRLF + . "0" . CRLF . CRLF ); }
--- a/proxy_request_buffering_ssl.t Tue Apr 07 16:45:14 2015 +0300 +++ b/proxy_request_buffering_ssl.t Wed Apr 08 20:16:40 2015 +0300 @@ -78,16 +78,16 @@ ssl_certificate_key localhost.key; ssl_certificate localhost.crt; - proxy_request_buffering off; location /preread { client_body_buffer_size 2k; add_header X-Body "$request_body"; proxy_pass http://127.0.0.1:8082/; + proxy_request_buffering off; } location / { - return 204; + proxy_pass http://127.0.0.1:8080/discard; } location /404 { } }