Revisions
-
hiratara renamed this gist
Feb 1, 2010 . 1 changed file with 12 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,11 @@ sub call { $env->{HTTP_X_PROXY_CAPABILITIES} = 'reproxy-file'; return sub { my $orig_respond = shift; my $cv = AE::cv; my $orig_nonblocking = $env->{"psgi.nonblocking"}; $env->{"psgi.nonblocking"} = 1; my $respond; $respond = sub { my $res = shift; @@ -23,12 +27,18 @@ sub call { write => sub { warn @_ }, close => sub { }; } else { my $orig_writer = $orig_respond->( $res ); return Plack::Util::inline_object write => sub { $orig_writer->write( @_ ) }, close => sub { $cv->send; }; } }; my $cb = $self->app->($env); $cb->($respond); $cv->recv unless $orig_nonblocking; $env->{"psgi.nonblocking"} = $orig_nonblocking; }; } -
hiratara renamed this gist
Feb 1, 2010 . 1 changed file with 21 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,34 +3,33 @@ package Plack::Middleware::Proxy::Reproxy; use parent 'Plack::Middleware'; use Plack::Util; sub call { my($self, $env) = @_; $env->{HTTP_X_PROXY_CAPABILITIES} = 'reproxy-file'; return sub { my $orig_respond = shift;; my $respond; $respond = sub { my $res = shift; if (my $url = Plack::Util::header_get($res->[1], 'X-Reproxy-URL')) { $env->{'plack.proxy.url'} = $url; $env->{REQUEST_METHOD} = 'GET'; my $cb = $self->app->($env); $cb->($respond); return Plack::Util::inline_object write => sub { warn @_ }, close => sub { }; } else { return $orig_respond->( $res ); } }; my $cb = $self->app->($env); $cb->($respond); }; } 1; @@ -64,3 +63,4 @@ =head1 SEE ALSO L<Plack::App::Proxy> =cut -
miyagawa created this gist
Feb 1, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ package Plack::Middleware::Proxy::Reproxy; use strict; use parent 'Plack::Middleware'; use Plack::Util; use Try::Tiny; sub call { my($self, $env) = @_; $env->{HTTP_X_PROXY_CAPABILITIES} = 'reproxy-file'; my $cv = AE::cv; my $respond; $respond = sub { my $res = shift; if (my $url = Plack::Util::header_get($res->[1], 'X-Reproxy-URL')) { $env->{'plack.proxy.url'} = $url; $env->{REQUEST_METHOD} = 'GET'; my $cb = $self->app->($env); $cb->($respond); } else { $cv->send($res); } return Plack::Util::inline_object write => sub { warn @_ }, close => sub { }; }; my $cb = $self->app->($env); $cb->($respond); return $cv; } 1; __END__ =head1 NAME Plack::Middleware::Proxy::Reproxy - Adds reproxy behavior to Plack::App::Proxy =head1 SYNOPSIS use Plack::Builder; use Plack::App::Proxy; builder { enable "Proxy::Reproxy"; Plack::App::Proxy->new(host => "http://10.0.1.2:8080/")->to_app; }; =head1 DESCRIPTION Plack::Middleware::Proxy::Reproxy adds reproxy capability to Plack::App::Proxy. =head1 AUTHOR Tatsuhiko Miyagawa =head1 SEE ALSO L<Plack::App::Proxy> =cut