X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FHTTP%2FDaemon.pm;h=00daf22454918583ad5f0755ca9ada046e573ca7;hp=40cd596f93259eee869178f6842a8489f1cead33;hb=21465c884872c1ec8c30acd72796445f9eaacb31;hpb=16d65a0eefcca6f2210d6d3fb48f385052b2711a diff --git a/lib/Catalyst/Engine/HTTP/Daemon.pm b/lib/Catalyst/Engine/HTTP/Daemon.pm index 40cd596..00daf22 100644 --- a/lib/Catalyst/Engine/HTTP/Daemon.pm +++ b/lib/Catalyst/Engine/HTTP/Daemon.pm @@ -3,6 +3,7 @@ package Catalyst::Engine::HTTP::Daemon; use strict; use base 'Catalyst::Engine::HTTP::Base'; +use Catalyst::Exception; use IO::Select; use IO::Socket; @@ -95,7 +96,10 @@ sub run { ); unless ( defined $daemon ) { - die(qq/Failed to create daemon. Reason: '$!'/); + + Catalyst::Exception->throw( + message => qq/Failed to create daemon. Reason: '$!'/ + ); } my $base = URI->new( $daemon->url )->canonical; @@ -121,7 +125,11 @@ sub run { my $nread = $client->sysread( my $buf, 4096 ); - unless ( defined($nread) && length($buf) ) { + unless ( $nread ) { + + next if $! == EWOULDBLOCK; + next if $! == EINPROGRESS; + next if $! == EINTR; $select->remove($client); $client->close; @@ -165,14 +173,20 @@ sub run { unless ( $client->response_buffer ) { - my $connection = $client->request->header('Connection'); + $client->response->header( Server => $daemon->product_tokens ); + + my $connection = $client->request->header('Connection') || ''; - if ( $connection && $connection =~ /Keep-Alive/i ) { + if ( $connection =~ /Keep-Alive/i ) { $client->response->header( 'Connection' => 'Keep-Alive' ); $client->response->header( 'Keep-Alive' => 'timeout=60, max=100' ); } - $client->response_buffer = $client->response->as_string; + if ( $connection =~ /close/i ) { + $client->response->header( 'Connection' => 'close' ); + } + + $client->response_buffer = $client->response->as_string("\x0D\x0A"); $client->response_offset = 0; } @@ -180,7 +194,11 @@ sub run { $client->response_length, $client->response_offset ); - unless ( defined($nwrite) ) { + unless ( $nwrite ) { + + next if $! == EWOULDBLOCK; + next if $! == EINPROGRESS; + next if $! == EINTR; $select->remove($client); $client->close; @@ -192,9 +210,19 @@ sub run { if ( $client->response_offset == $client->response_length ) { - my $connection = $client->request->header('Connection'); + my $connection = $client->request->header('Connection') || ''; + my $protocol = $client->request->protocol; + my $persistent = 0; + + if ( $protocol eq 'HTTP/1.1' && $connection !~ /close/i ) { + $persistent++; + } + + if ( $protocol ne 'HTTP/1.1' && $connection =~ /Keep-Alive/i ) { + $persistent++; + } - unless ( $connection && $connection =~ /Keep-Alive/i ) { + unless ( $persistent ) { $select->remove($client); $client->close; }