| 1 |
NAME |
| 2 |
Plack::App::Proxy - proxy requests |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use Plack::Builder; |
| 6 |
|
| 7 |
# proxy all requests for /static to 127.0.0.1:80 |
| 8 |
builder { |
| 9 |
mount "/static" => Plack::App::Proxy->new(remote => "http://127.0.0.1:80")->to_app; |
| 10 |
}; |
| 11 |
|
| 12 |
# Call from other app |
| 13 |
my $proxy = Plack::App::Proxy->new->to_app; |
| 14 |
my $app = sub { |
| 15 |
my $env = shift; |
| 16 |
... |
| 17 |
$env->{'plack.proxy.url'} = $url; |
| 18 |
$proxy->($env); |
| 19 |
}; |
| 20 |
|
| 21 |
DESCRIPTION |
| 22 |
Plack::App::Proxy is a middleware-aware proxy application for Plack. |
| 23 |
|
| 24 |
OPTIONS |
| 25 |
remote |
| 26 |
Plack::App::Proxy->new(remote => 'http://perl.org')->to_app; |
| 27 |
|
| 28 |
Specifies the base remote URL to proxy requests to. |
| 29 |
|
| 30 |
builder { |
| 31 |
mount "/example", |
| 32 |
Plack::App::Proxy->new(remote => 'http://example.com/app/foo')->to_app; |
| 33 |
}; |
| 34 |
|
| 35 |
This proxies incoming requests for "/example/bar" proxied to |
| 36 |
"http://example.com/app/foo/bar". |
| 37 |
|
| 38 |
preserve_host_header |
| 39 |
Preserves the original Host header, which is useful when you do |
| 40 |
reverse proxying to the internal hosts. |
| 41 |
|
| 42 |
backend |
| 43 |
The HTTP backend to use. This dist comes with "LWP" and |
| 44 |
"AnyEvent::HTTP" backends. "AnyEvent::HTTP" is the default if no |
| 45 |
backend is specified. |
| 46 |
|
| 47 |
options |
| 48 |
The options for the HTTP backend instance. |
| 49 |
|
| 50 |
MIDDLEWARE CONFIGURATIONS |
| 51 |
This application is just like a normal PSGI application and is |
| 52 |
middleware aware, which means you can modify proxy requests (and |
| 53 |
responses) using Plack middleware stack. |
| 54 |
|
| 55 |
It also supports the following special environment variables: |
| 56 |
|
| 57 |
plack.proxy.url |
| 58 |
Overrides the proxy request URL. |
| 59 |
|
| 60 |
plack.proxy.remote |
| 61 |
Overrides the base URL path to proxy to. |
| 62 |
|
| 63 |
For example, the following builder code allows you to proxy all GET |
| 64 |
requests for .png paths to the lolcat image (yes, a silly example) but |
| 65 |
proxies to the internal host otherwise. |
| 66 |
|
| 67 |
my $mw = sub { |
| 68 |
my $app = shift; |
| 69 |
sub { |
| 70 |
my $env = shift; |
| 71 |
if ($env->{REQUEST_METHOD} eq 'GET' && $env->{PATH_INFO} =~ /\.png$/) { |
| 72 |
$env->{'plack.proxy.url'} = 'http://lolcat.example.com/lol.png'; |
| 73 |
} |
| 74 |
$app->($env); |
| 75 |
}; |
| 76 |
}; |
| 77 |
|
| 78 |
use Plack::Builder; |
| 79 |
|
| 80 |
builder { |
| 81 |
enable $mw; |
| 82 |
Plack::App::Proxy->new(remote => 'http://10.0.0.1:8080')->to_app; |
| 83 |
}; |
| 84 |
|
| 85 |
AUTHOR |
| 86 |
Lee Aylward |
| 87 |
|
| 88 |
Masahiro Honma |
| 89 |
|
| 90 |
Tatsuhiko Miyagawa |
| 91 |
|
| 92 |
Jesse Luehrs |
| 93 |
|
| 94 |
LICENSE |
| 95 |
This library is free software; you can redistribute it and/or modify it |
| 96 |
under the same terms as Perl itself. |
| 97 |
|
| 98 |
SEE ALSO |
| 99 |
Plack::Builder |
| 100 |
|