Permalink
Browse files

Merge pull request #20 from athomason/master

Suppress 400 if client disconnected (mk 2)
  • Loading branch information...
2 parents 24c5eb8 + f9fbf8b commit 505bb8621a76e00ca53f284bf15b62c9238d5afb @miyagawa committed Sep 18, 2011
Showing with 15 additions and 11 deletions.
  1. +15 −11 lib/Twiggy/Server.pm
View
@@ -160,7 +160,8 @@ sub _accept_handler {
1;
}) {
- $self->_bad_request($sock);
+ 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);
+ 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;
}

0 comments on commit 505bb86

Please sign in to comment.