changeset 1491:c2bbf805388d

Tests: more perl request body tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 12 Jul 2019 18:27:11 +0300
parents 8f79fac049df
children 760fdf2865bb
files perl.t
diffstat 1 files changed, 57 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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');
+
+}
+
 ###############################################################################