Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion body_chunked.t
Original file line number Diff line number Diff line change
Expand Up @@ -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(21);

$t->write_file_expand('nginx.conf', <<'EOF');

Expand Down Expand Up @@ -73,6 +73,10 @@ http {
location /discard {
return 200 "TEST\n";
}
location /discard-large {
client_max_body_size 1k;
return 200 "TEST\n";
}
location /next {
proxy_pass http://u/;
}
Expand Down Expand Up @@ -134,6 +138,13 @@ like(http_get_body('/discard', '0123456789' x 128, '0123456789' x 512,
'0123456789', 'foobar'), qr/(TEST.*){4}/ms,
'chunked body discard 2');

like(http_chunked_body('/discard-large', 'A' x 512, 'B' x 512),
qr/ 200 /, 'chunked body discard at limit');
like(http_chunked_body('/discard-large', 'A' x 1025),
qr/ 413 /, 'chunked body discard too large');
like(http_chunked_body('/discard-large', 'A' x 512, 'B' x 512, 'C'),
qr/ 413 /, 'chunked body discard too large in multiple chunks');

# invalid chunks

like(
Expand Down Expand Up @@ -219,6 +230,21 @@ sub http_get_body {
);
}

sub http_chunked_body {
my ($uri, @chunks) = @_;

return http(
"POST $uri HTTP/1.1" . CRLF
. "Host: localhost" . CRLF
. "Connection: close" . CRLF
. "Transfer-Encoding: chunked" . CRLF . CRLF
. join('', map {
sprintf("%x", length $_) . CRLF . $_ . CRLF
} @chunks)
. "0" . CRLF . CRLF
);
}

sub http_transfer_encoding {
my ($encoding, $version) = @_;
$version ||= "1.1";
Expand Down