Mojolicious-Plugin-MountPSGI
view release on metacpan or search on metacpan
0.09 2015-12-19 20:30:00
- Include CONTENT_TYPE and CONTENT_LENGTH psgi env keys
- Fix odd test failure
0.08 2015-12-10 23:00:00
- Add rewrite option ala Plack::App::URLMap
0.07 2015-11-17 20:30:00
- Handle the request body more correctly
0.06 2015-11-16 03:00:00
- Fix packaging
0.05 2015-11-15 23:00:00
- Added handling for PSGI delayed and streaming responses
0.04 2015-06-03 20:45:00
- Allow instantiated PSGI app instances
0.03 2015-06-03 14:30:00
- Fix psgi app location when plugin is installed
0.02 2014-04-04 15:31:00
- Fix dependency on Plack
0.01 2010-08-29 17:28:00
- Initial release
t/chunked.t
t/delayed.t
t/env.t
t/formdata.t
t/instance.t
t/script/basic.psgi
t/script/chunked.psgi
t/script/delayed.psgi
t/script/env.psgi
t/script/formdata.psgi
t/script/streaming.psgi
t/streaming.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
lib/Mojolicious/Plugin/MountPSGI/Proxy.pm view on Meta::CPAN
}
# PSGI responses must be ARRAY or CODE
die 'PSGI response not understood'
unless ref $plack_res eq 'CODE';
#TODO do something with $self->mode in delayed response
# delayed (code reference) response
my $responder = sub {
my $plack_res = shift;
my ($mojo_res, $streaming) = _psgi_res_to_mojo_res($plack_res);
$c->tx->res($mojo_res);
return $c->rendered unless $streaming;
# streaming response, possibly chunked
my $chunked = $mojo_res->content->is_chunked;
my $write = $chunked ? sub { $c->write_chunk(@_) } : sub { $c->write(@_) };
$write->(); # finalize header response
return Plack::Util::inline_object(
write => $write,
close => sub { $c->finish(@_) }
);
};
$plack_res->($responder);
}
lib/Mojolicious/Plugin/MountPSGI/Proxy.pm view on Meta::CPAN
'REQUEST_URI' => $url->to_string,
'QUERY_STRING' => $url->query->to_string,
'psgi.url_scheme' => $base->scheme,
'psgi.multithread' => Plack::Util::FALSE,
'psgi.version' => [1,1],
'psgi.errors' => *STDERR,
'psgi.input' => $input,
'psgi.multithread' => Plack::Util::FALSE,
'psgi.multiprocess' => Plack::Util::TRUE,
'psgi.run_once' => Plack::Util::FALSE,
'psgi.streaming' => Plack::Util::TRUE,
'psgi.nonblocking' => Plack::Util::FALSE,
};
}
sub _psgi_res_to_mojo_res {
my $psgi_res = shift;
my $mojo_res = Mojo::Message::Response->new;
$mojo_res->code($psgi_res->[0]);
my $headers = $mojo_res->headers;
Plack::Util::header_iter $psgi_res->[1] => sub { $headers->header(@_) };
$headers->remove('Content-Length'); # should be set by mojolicious later
my $streaming = 0;
if (@$psgi_res == 3) {
my $asset = $mojo_res->content->asset;
Plack::Util::foreach($psgi_res->[2], sub {$asset->add_chunk($_[0])});
} else {
$streaming = 1;
}
return ($mojo_res, $streaming);
}
1;
t/streaming.t view on Meta::CPAN
#!/usr/bin/env perl
use Mojo::Base -strict;
use Test::More tests => 3;
use Mojolicious::Lite;
use Test::Mojo;
plugin 'MountPSGI', { '/' => 't/script/streaming.psgi' };
my $t = Test::Mojo->new;
$t->get_ok('/foo')->status_is(200)->content_is("hello, world\n");
( run in 0.300 second using v1.01-cache-2.11-cpan-4d50c553e7e )