Scroll to navigation

Plack::App::Proxy(3pm) User Contributed Perl Documentation Plack::App::Proxy(3pm)


Plack::App::Proxy - proxy requests


  use Plack::Builder;
  # proxy all requests for /static to
  builder {
      mount "/static" => Plack::App::Proxy->new(remote => "")->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;


Plack::App::Proxy is a middleware-aware proxy application for Plack.


  Plack::App::Proxy->new(remote => '')->to_app;

Specifies the base remote URL to proxy requests to.

  builder {
      mount "/example",
          Plack::App::Proxy->new(remote => '')->to_app;

This proxies incoming requests for "/example/bar" proxied to "".

Preserves the original Host header, which is useful when you do reverse proxying to the internal hosts.
The HTTP backend to use. This dist comes with "LWP" and "AnyEvent::HTTP" backends. "AnyEvent::HTTP" is the default if no backend is specified.
The options for the HTTP backend instance.


This application is just like a normal PSGI application and is middleware aware, which means you can modify proxy requests (and responses) using Plack middleware stack.

It also supports the following special environment variables:

Overrides the proxy request URL.
Overrides the base URL path to proxy to.

For example, the following builder code allows you to proxy all GET requests for .png paths to the lolcat image (yes, a silly example) but 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'} = '';
  use Plack::Builder;
  builder {
      enable $mw;
      Plack::App::Proxy->new(remote => '')->to_app;


Lee Aylward

Masahiro Honma

Tatsuhiko Miyagawa

Jesse Luehrs


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.



2021-01-09 perl v5.32.0