Skip to content

Instantly share code, notes, and snippets.

@miyagawa
Created February 1, 2010 02:47
Show Gist options
  • Save miyagawa/291417 to your computer and use it in GitHub Desktop.
Save miyagawa/291417 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment