Plack:...::Proxy(3pm)
π Plack::App::Proxy π
okay bestie, gather round, because we're talking about Plack::App::Proxy β it's the Plack::App::Proxy page from the User Contributed Perl Documentation, section 3pm, and it's literally the "proxy requests" app. yes that's the whole NAME. short, sweet, iconic. π
β¨ SYNOPSIS β¨
use Plack::Builder;
# proxy all requests for /static to 127.0.0.1:80
builder {
mount "/static" => Plack::App::Proxy->new(remote => "http://127.0.0.1:80")->to_app;
};
# Call from other app
my $proxy = Plack::App::Proxy->new->to_app;
my $app = sub {
my $env = shift;
...
$env->{'plack.proxy.url'} = $url;
$proxy->($env);
};
see how chill that is?? mount it, or call it from another app like a little helper. we love range. π
πΈ DESCRIPTION πΈ
Plack::App::Proxy is a middleware-aware proxy application for Plack. that's it. that's the whole vibe. it proxies. it's middleware-aware. it slays. π¦
π OPTIONS π
remoteβ specifies the base remote URL you're proxying requests to. like:
Plack::App::Proxy->new(remote => 'http://perl.org')->to_app;
and here's the mount-y version:
builder {
mount "/example",
Plack::App::Proxy->new(remote => 'http://example.com/app/foo')->to_app;
};
so incoming requests for /example/bar get proxied to http://example.com/app/foo/bar. the path just snaps onto the end like a lil magnet bestie. π§²
preserve_host_headerβ keeps the originalHostheader intact. super useful when you're doing reverse proxying to internal hosts. don't let anyone rewrite your identity, fr fr. πbackendβ which HTTP backend to use. this dist ships withLWPandAnyEvent::HTTPbackends. and if you don't specify one?AnyEvent::HTTPis the default. periodt. β¨optionsβ the options for the HTTP backend instance. give it what it needs. π«Ά
π MIDDLEWARE CONFIGURATIONS π
this app is just a normal PSGI application, and it's middleware aware β meaning you can modify proxy requests (and responses) using a Plack middleware stack. chef's kiss. π
it also supports these special environment variables:
plack.proxy.url
overrides the proxy request URL. π₯
plack.proxy.remote
overrides the base URL path to proxy to. π₯
for example β and yes this is a silly example, the original page literally calls it silly, so we're all in agreement β the following builder code proxies all GET requests for .png paths to the lolcat image, and proxies to the internal host otherwise:
my $mw = sub {
my $app = shift;
sub {
my $env = shift;
if ($env->{REQUEST_METHOD} eq 'GET' && $env->{PATH_INFO} =~ /\.png$/) {
$env->{'plack.proxy.url'} = 'http://lolcat.example.com/lol.png';
}
$app->($env);
};
};
use Plack::Builder;
builder {
enable $mw;
Plack::App::Proxy->new(remote => 'http://10.0.0.1:8080')->to_app;
};
lolcat proxy. no notes. π₯
π« AUTHOR π«
- Lee Aylward
- Masahiro Honma
- Tatsuhiko Miyagawa
- Jesse Luehrs
the whole squad, honestly. π
π LICENSE π
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. free as in freedom bestie, go wild. π
π SEE ALSO π
Plack::Builder
ok that's the whole page, no skips, no cuts. π
this page came from perl v5.32.0, dated 2021-01-09, and it's the Plack:...::Proxy(3pm) manual. bye bestie, go proxy something responsibly π
β¨
π¦ where this page comes from
- debian bookworm: libplack-app-proxy-perl 0.29-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libplack-app-proxy-perl 0.29-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libplack-app-proxy-perl 0.29-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libplack-app-proxy-perl 0.29-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms