}
async function keepalive_head(r) {
+ const loc = r.args.loc || 'count';
+ const port = r.args.port || $p1;
let responses = [];
for (let i = 0; i < 3; i++) {
- let reply = await ngx.fetch('http://127.0.0.1:$p1/count',
+ let reply = await ngx.fetch(`http://127.0.0.1:\${port}/\${loc}`,
{method: 'HEAD'});
responses.push(reply.headers.get('Connection-ID'));
}
$t->run_daemon(\&http_daemon, $p2);
$t->waitforsocket('127.0.0.1:' . $p2);
-$t->plan(17);
+$t->plan(20);
###############################################################################
'normal keepalive');
like(http_get("/keepalive?path=assumed_keepalive&port=$p2&sleep=1"), qr/4,5,6/,
'assumed keepalive');
+my $r = http_get("/keepalive?path=trailing&port=$p2");
+my ($connections) = $r =~ /(\d+,\d+,\d+)\s*$/;
+my @connections = split /,/, ($connections // '');
+my %seen;
+$seen{$_} = 1 for @connections;
+is(scalar(keys %seen), 3, 'upstream trailing response data');
+
+$r = http_get("/keepalive_head?loc=trailing_head&port=$p2");
+($connections) = $r =~ /(\d+,\d+,\d+)\s*$/;
+@connections = split /,/, ($connections // '');
+%seen = ();
+$seen{$_} = 1 for @connections;
+is(scalar(keys %seen), 3, 'upstream trailing head response data');
+
+$r = http_get("/keepalive?path=trailing_chunked&port=$p2");
+($connections) = $r =~ /(\d+,\d+,\d+)\s*$/;
+@connections = split /,/, ($connections // '');
+%seen = ();
+$seen{$_} = 1 for @connections;
+is(scalar(keys %seen), 3, 'upstream trailing chunked response data');
###############################################################################
"HTTP/1.0 200 OK" . CRLF .
"Content-Length: " . length($body) . CRLF . CRLF .
$body;
+
+ } elsif ($uri eq '/trailing') {
+ print $client
+ "HTTP/1.1 200 OK" . CRLF .
+ "Content-Length: " . length($ccount) . CRLF .
+ "Connection: keep-alive" . CRLF . CRLF .
+ $ccount . "trailing";
+
+ } elsif ($uri eq '/trailing_head') {
+ print $client
+ "HTTP/1.1 200 OK" . CRLF .
+ "Content-Length: " . length($ccount) . CRLF .
+ "Connection-ID: $ccount" . CRLF .
+ "Connection: keep-alive" . CRLF . CRLF .
+ $ccount . "trailing";
+
+ } elsif ($uri eq '/trailing_chunked') {
+ print $client
+ "HTTP/1.1 200 OK" . CRLF .
+ "Transfer-Encoding: chunked" . CRLF .
+ "Connection: keep-alive" . CRLF . CRLF .
+ length($ccount) . CRLF . $ccount . CRLF .
+ "0" . CRLF . CRLF . "trailing";
}
}