# HG changeset patch # User Sergey Kandaurov # Date 1616584429 -10800 # Node ID a40f94bc92d47484b443ae94909fb200999d0402 # Parent 0fae67763be55d76db7ab4aa8199bb19981a6d92 Tests: keepalive test with EOF in discard body (ticket #2145). diff -r 0fae67763be5 -r a40f94bc92d4 http_keepalive.t --- a/http_keepalive.t Wed Mar 24 14:01:50 2021 +0300 +++ b/http_keepalive.t Wed Mar 24 14:13:49 2021 +0300 @@ -24,7 +24,7 @@ select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->has(qw/http/)->plan(15) +my $t = Test::Nginx->new()->has(qw/http/)->plan(16) ->write_file_expand('nginx.conf', <<'EOF'); %%TEST_GLOBALS%% @@ -52,6 +52,7 @@ location / { } location /r { keepalive_requests 4; + keepalive_timeout 30s; } location /safari { @@ -109,6 +110,26 @@ like(http_keepalive('/zero'), qr/Connection: close/, 'keepalive timeout 0'); +# cancel keepalive on EOF while discarding body + +my $s = http(< 1); +POST /r HTTP/1.1 +Host: localhost +Content-Length: 10 + +EOF + +read_keepalive($s); +shutdown($s, 1); + +TODO: { +local $TODO = 'not yet' unless ($^O eq 'MSWin32' or $^O eq 'solaris') + or $t->has_version('1.19.9'); + +ok(IO::Select->new($s)->can_read(3), 'EOF in discard body'); + +} + $t->stop(); TODO: { @@ -145,22 +166,26 @@ EOF - my $data = ''; - - while (IO::Select->new($s)->can_read(3)) { - sysread($s, my $buffer, 4096) or last; - $data .= $buffer; - last if $data =~ /^\x0d\x0a/ms; - } - - log_in($data); - - $total .= $data; + $total .= read_keepalive($s); } return $total; } +sub read_keepalive { + my ($s) = @_; + my $data = ''; + + while (IO::Select->new($s)->can_read(3)) { + sysread($s, my $buffer, 4096) or last; + $data .= $buffer; + last if $data =~ /^\x0d\x0a/ms; + } + + log_in($data); + return $data; +} + sub count_keepalive { my ($str) = @_; return $str =~ s/Connection: keep-alive//g;