1use strict; 2use warnings; 3use Net::EmptyPort qw(check_port empty_port); 4use Test::More; 5use t::Util; 6 7plan skip_all => 'nghttp not found' 8 unless prog_exists('nghttp'); 9 10my $upstream_port = empty_port(); 11$| = 1; 12my $socket = new IO::Socket::INET ( 13 LocalHost => '127.0.0.1', 14 LocalPort => $upstream_port, 15 Proto => 'tcp', 16 Listen => 1, 17 Reuse => 1 18); 19die "cannot create socket $!\n" unless $socket; 20 21check_port($upstream_port) or die "can't connect to server socket"; 22# accent and close check_port's connection 23my $client_socket = $socket->accept(); 24close($client_socket); 25 26my $server = spawn_h2o(<< "EOT"); 27hosts: 28 default: 29 paths: 30 "/": 31 proxy.reverse.url: http://127.0.0.1:$upstream_port 32EOT 33 34my $msg = "this is the message"; 35open(NGHTTP, "nghttp -t 3 -w 1 -v http://127.0.0.1:$server->{'port'}/ -H 'host: host.example.com' 2>&1 |"); 36 37my $req; 38$client_socket = $socket->accept(); 39$client_socket->recv($req, 1024); 40$client_socket->send("HTTP/1.1 200 Ok\r\nConnection:close\r\n\r\n$msg"); 41close($client_socket); 42 43my $worked = 1; 44while(<NGHTTP>) { 45 if (/Timeout/) { 46 $worked = 0; 47 } 48} 49 50ok($worked == 1, "The connection didn't timeout"); 51 52$socket->close(); 53done_testing(); 54