Skip to content

Commit

Permalink
On bad_request, go through _write_psgi_response even if sending nothi…
Browse files Browse the repository at this point in the history
…ng back
  • Loading branch information
athomason committed Sep 8, 2011
1 parent d5e803e commit f9fbf8b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/Twiggy/Server.pm
Expand Up @@ -160,7 +160,8 @@ sub _accept_handler {

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

0 comments on commit f9fbf8b

Please sign in to comment.