# HG changeset patch # User Sergey Kandaurov # Date 1562945231 -10800 # Node ID c2bbf805388dcaae7985630af57e4494ada03732 # Parent 8f79fac049df5d51a2370706d517579d34337710 Tests: more perl request body tests. diff --git a/perl.t b/perl.t --- a/perl.t +++ b/perl.t @@ -23,7 +23,7 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(20) +my $t = Test::Nginx->new()->has(qw/http perl rewrite/)->plan(24) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -107,6 +107,25 @@ http { } }'; } + + location /discard { + perl 'sub { + use warnings; + use strict; + + my $r = shift; + + $r->discard_request_body; + + $r->send_http_header("text/plain"); + + return OK if $r->header_only; + + $r->print("host: ", $r->header_in("Host"), "\n"); + + return OK; + }'; + } } } @@ -202,6 +221,8 @@ like(http( # various request body tests +like(http_get('/body'), qr/400 Bad Request/, 'perl no body'); + like(http( 'GET /body HTTP/1.0' . CRLF . 'Host: localhost' . CRLF @@ -256,4 +277,39 @@ like(http( body => '67890' . CRLF . '0' . CRLF . CRLF ), qr/body: 1234567890/, 'perl body chunked split'); +like(http( + 'GET /discard HTTP/1.1' . CRLF + . 'Host: localhost' . CRLF + . 'Connection: close' . CRLF + . 'Transfer-Encoding: chunked' . CRLF . CRLF + . 'a' . CRLF + . '1234567890' . CRLF + . '0' . CRLF . CRLF +), qr/host: localhost/, 'perl body discard'); + +TODO: { +local $TODO = 'not yet' unless $t->has_version('1.17.2'); + +like(http( + 'GET /discard HTTP/1.1' . CRLF + . 'Host: localhost' . CRLF + . 'Connection: close' . CRLF + . 'Transfer-Encoding: chunked' . CRLF . CRLF + . 'ak' . CRLF + . '1234567890' . CRLF + . '0' . CRLF . CRLF +), qr/400 Bad Request/, 'perl body discard bad chunk'); + +like(http( + 'GET /body HTTP/1.1' . CRLF + . 'Host: localhost' . CRLF + . 'Connection: close' . CRLF + . 'Transfer-Encoding: chunked' . CRLF . CRLF + . 'ak' . CRLF + . '1234567890' . CRLF + . '0' . CRLF . CRLF +), qr/400 Bad Request/, 'perl body bad chunk'); + +} + ###############################################################################