Plack:...::Proxy(3pm)

πŸ“¦
version 0.29 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– 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 original Host header 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 with LWP and AnyEvent::HTTP backends. and if you don't specify one? AnyEvent::HTTP is 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