From 2d18b7ff9dc47aa6b492d671b4765173b63299fc Mon Sep 17 00:00:00 2001 From: Adam Thomason Date: Thu, 4 Aug 2011 16:11:48 -0700 Subject: [PATCH 1/3] Suppress 400 if client disconnected --- lib/Twiggy/Server.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Twiggy/Server.pm b/lib/Twiggy/Server.pm index 579c884..debcd3d 100644 --- a/lib/Twiggy/Server.pm +++ b/lib/Twiggy/Server.pm @@ -160,7 +160,7 @@ sub _accept_handler { 1; }) { - $self->_bad_request($sock); + $self->_bad_request($sock) unless $@ eq 'client disconnected'; } }; } @@ -217,7 +217,7 @@ sub _create_req_parsing_watcher { } catch { undef $headers_io_watcher; undef $timeout_timer; - $self->_bad_request($sock); + $self->_bad_request($sock) unless $_ eq 'client disconnected'; } }; } From d5e803ed310e2b993a195760153960c4529c04e7 Mon Sep 17 00:00:00 2001 From: Adam Thomason Date: Fri, 2 Sep 2011 11:44:09 -0700 Subject: [PATCH 2/3] Allow for error messages that have line numbers --- lib/Twiggy/Server.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Twiggy/Server.pm b/lib/Twiggy/Server.pm index debcd3d..0978e2b 100644 --- a/lib/Twiggy/Server.pm +++ b/lib/Twiggy/Server.pm @@ -160,7 +160,7 @@ sub _accept_handler { 1; }) { - $self->_bad_request($sock) unless $@ eq 'client disconnected'; + $self->_bad_request($sock) unless $@ =~ /^client disconnected/; } }; } @@ -217,7 +217,7 @@ sub _create_req_parsing_watcher { } catch { undef $headers_io_watcher; undef $timeout_timer; - $self->_bad_request($sock) unless $_ eq 'client disconnected'; + $self->_bad_request($sock) unless /^client disconnected/; } }; } From f9fbf8b99a4eb5cae433a1e68af46fd3bb31f44a Mon Sep 17 00:00:00 2001 From: Adam Thomason Date: Wed, 7 Sep 2011 17:16:51 -0700 Subject: [PATCH 3/3] On bad_request, go through _write_psgi_response even if sending nothing back --- lib/Twiggy/Server.pm | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/Twiggy/Server.pm b/lib/Twiggy/Server.pm index 0978e2b..1741362 100644 --- a/lib/Twiggy/Server.pm +++ b/lib/Twiggy/Server.pm @@ -160,7 +160,8 @@ sub _accept_handler { 1; }) { - $self->_bad_request($sock) unless $@ =~ /^client disconnected/; + my $disconnected = ($@ =~ /^client disconnected/); + $self->_bad_request($sock, $disconnected); } }; } @@ -217,24 +218,27 @@ sub _create_req_parsing_watcher { } catch { undef $headers_io_watcher; undef $timeout_timer; - $self->_bad_request($sock) unless /^client disconnected/; + my $disconnected = /^client disconnected/; + $self->_bad_request($sock, $disconnected); } }; } sub _bad_request { - my ( $self, $sock ) = @_; + my ( $self, $sock, $disconnected ) = @_; return unless defined $sock and defined fileno $sock; - $self->_write_psgi_response( - $sock, - [ - 400, - [ 'Content-Type' => 'text/plain' ], - [ ], - ], - ); + my $response = [ + 400, + [ 'Content-Type' => 'text/plain' ], + [ ], + ]; + + # if client is already gone, don't try to write to it + $response = [] if $disconnected; + + $self->_write_psgi_response($sock, $response); return; }