Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:miyagawa/Plack
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Sep 16, 2009
2 parents c7b6374 + 08ec432 commit f06c508
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 253 deletions.
2 changes: 1 addition & 1 deletion benchmarks/ab.pl
Expand Up @@ -16,7 +16,7 @@
Standalone => 0,
ServerSimple => 'HTTP::Server::Simple',
'Mojo::Prefork' => 'Mojo',
Coro => 'Coro',
Coro => 'Net::Server::Coro',
);

my @backends;
Expand Down
2 changes: 1 addition & 1 deletion eg/dot-psgi/cgi-script.psgi
@@ -1,5 +1,5 @@
use CGI::Emulate::PSGI;
my $handler = CGI::Emulate::PSGI->handler(sub {
do "hello.cgi";
CGI::_reset_globals() if %CGI::;
CGI::initialize_globals() if defined &CGI::initialize_globals;
});
2 changes: 1 addition & 1 deletion eg/dot-psgi/image.psgi
Expand Up @@ -2,5 +2,5 @@ use File::Basename;
my $path = $ENV{PSGI_IMAGE_FILE} || dirname(__FILE__) . "/../../t/assets/kyoto.jpg";
my $handler = sub {
open my $fh, "<", $path or die $!;
return [ 200, [ "Content-Type" => "image/jpeg", "Content-Length" => -s $fh ], $fh ];
return [ 200, [ "Content-Type" => "image/jpeg", "X-Sendfile" => $path, "Content-Length" => -s $fh ], $fh ];
};
17 changes: 15 additions & 2 deletions eg/dot-psgi/slowapp.psgi
@@ -1,6 +1,19 @@
# emulate a slow web app that does DB query etc.
use Time::HiRes qw(sleep);
use Time::HiRes;

sub _sleep {
# If it's running in Coro, you can use Coro's co-operative multi
# tasking to do time-consuming task by yeilding to other threads:
# we use Coro::Timer::sleep to demonstrate that:
if ($INC{"Coro.pm"}) {
require Coro::Timer;
Coro::Timer::sleep( $_[0] );
} else {
Time::HiRes::sleep( $_[0] );
}
}

my $handler = sub {
sleep 0.1;
_sleep 0.1; # emulate the DB/IO task that takes 0.1 second
return [ 200, [ "Content-Type" => "text/plain", "Content-Length" => 11 ], [ "Hello World" ] ];
};
2 changes: 1 addition & 1 deletion lib/CGI/Emulate/PSGI.pm
Expand Up @@ -118,7 +118,7 @@ variables in the handler loop yourself, so:
my $app = CGI::Emulate::PSGI->handler(sub {
do "script-that-uses-cgi-pm.cgi";
CGI::_reset_globals() if %CGI::;
CGI::initialize_globals() if defined &CGI::initialize_globals;
});
Otherwise previous request variables will be reused in the new
Expand Down
17 changes: 11 additions & 6 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 All @@ -137,7 +142,7 @@ sub _response_handler {
my $body = $res->[2];
my $disconnect_cb = sub { $handle->on_drain(sub { $handle->destroy }) };

if ( ref $body eq 'GLOB' && $HasAIO ) {
if ( $HasAIO && Plack::Util::is_real_fh($body) ) {
my $offset = 0;
my $length = -s $body;

Expand Down

0 comments on commit f06c508

Please sign in to comment.