# HG changeset patch # User Maxim Dounin # Date 1711774122 -10800 # Node ID 5cf0e07d63a11cf92e55209e832e8f34939d9025 # Parent 33b54de4ee231ec095889f14636f8a8836ae35a6 Tests: tests for request body chunked extensions and trailers. diff --git a/body_chunked.t b/body_chunked.t --- a/body_chunked.t +++ b/body_chunked.t @@ -22,7 +22,7 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(18); +my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(24); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -68,6 +68,7 @@ http { } location /large { client_max_body_size 1k; + client_body_buffer_size 2k; proxy_pass http://127.0.0.1:8081; } location /discard { @@ -119,6 +120,8 @@ like(http_get_body('/single', '012345678 qr/X-Body: (0123456789){128}\x0d?$/ms, 'body in single buffer'); like(http_get_body('/large', '0123456789' x 128), qr/ 413 /, 'body too large'); +like(http_get_body('/large', 'X' x 1024), qr/ 200 /, 'body exact limit'); +like(http_get_body('/large', 'X' x 1025), qr/ 413 /, 'body just above limit'); # pipelined requests @@ -162,6 +165,66 @@ like( qr/400 Bad/, 'runaway chunk discard' ); +# chunk extensions and trailers + +like( + http( + 'GET /large HTTP/1.1' . CRLF + . 'Host: localhost' . CRLF + . 'Connection: close' . CRLF + . 'Transfer-Encoding: chunked' . CRLF . CRLF + . ('1; foo' . CRLF . 'X' . CRLF) x 16 + . '0' . CRLF . CRLF + ), + qr/ 200 /, 'chunk extensions' +); + +TODO: { +local $TODO = 'not yet' unless $t->has_version('1.25.5'); + +like( + http( + 'GET /large HTTP/1.1' . CRLF + . 'Host: localhost' . CRLF + . 'Connection: close' . CRLF + . 'Transfer-Encoding: chunked' . CRLF . CRLF + . ('1; foo' . CRLF . 'X' . CRLF) x 512 + . '0' . CRLF . CRLF + ), + qr/ 413 /, 'too many chunk extensions' +); + +} + +like( + http( + 'GET /large HTTP/1.1' . CRLF + . 'Host: localhost' . CRLF + . 'Connection: close' . CRLF + . 'Transfer-Encoding: chunked' . CRLF . CRLF + . '1' . CRLF . 'X' . CRLF + . '0' . CRLF . ('X-Trailer: foo' . CRLF) x 16 . CRLF + ), + qr/ 200 /, 'trailers' +); + +TODO: { +local $TODO = 'not yet' unless $t->has_version('1.25.5'); + +like( + http( + 'GET /large HTTP/1.1' . CRLF + . 'Host: localhost' . CRLF + . 'Connection: close' . CRLF + . 'Transfer-Encoding: chunked' . CRLF . CRLF + . '1' . CRLF . 'X' . CRLF + . '0' . CRLF . ('X-Trailer: foo' . CRLF) x 512 . CRLF + ), + qr/ 413 /, 'too many trailers' +); + +} + # proxy_next_upstream like(http_get_body('/next', '0123456789'),