Skip to content

Commit

Permalink
write header in one shot
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Sep 16, 2009
1 parent a2066aa commit 1c4ee13
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions benchmarks/ab.pl
Expand Up @@ -13,6 +13,7 @@

my %backends = (
AnyEvent => 'AnyEvent',
'AnyEvent::HTTPD' => 'AnyEvent::HTTPD',
Standalone => 0,
ServerSimple => 'HTTP::Server::Simple',
'Mojo::Prefork' => 'Mojo',
Expand Down
15 changes: 10 additions & 5 deletions lib/Plack/Impl/AnyEvent.pm
Expand Up @@ -83,8 +83,7 @@ sub run {
}
);
} else {
my $data = '';
open my $input, "<", \$data;
open my $input, "<", \"";
$env->{'psgi.input'} = $input;
$response_handler->($app, $env);
}
Expand All @@ -108,11 +107,17 @@ sub _start_response {

return sub {
my ($status, $headers) = @_;
$handle->push_write("HTTP/1.0 $status @{[ HTTP::Status::status_message($status) ]}\015\012");

my $hdr;
$hdr .= "HTTP/1.0 $status @{[ HTTP::Status::status_message($status) ]}\015\012";
while (my ($k, $v) = splice(@$headers, 0, 2)) {
$handle->push_write("$k: $v\015\012");
$hdr .= "$k: $v\015\012";
}
$handle->push_write("\015\012");
$hdr .= "\015\012";

$handle->push_write($hdr);

return unless defined wantarray;
return Plack::Util::response_handle(
write => sub { $handle->push_write($_[0]) },
close => sub { $handle->push_shutdown },
Expand Down

0 comments on commit 1c4ee13

Please sign in to comment.