Skip to content

Commit

Permalink
Merge pull request #20 from athomason/master
Browse files Browse the repository at this point in the history
Suppress 400 if client disconnected (mk 2)
  • Loading branch information
miyagawa committed Sep 18, 2011
2 parents 24c5eb8 + f9fbf8b commit 505bb86
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/Twiggy/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ sub _accept_handler {

1;
}) {
$self->_bad_request($sock);
my $disconnected = ($@ =~ /^client disconnected/);
$self->_bad_request($sock, $disconnected);
}
};
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 505bb86

Please sign in to comment.