++ed by:
1 non-PAUSE user
Author image Tobias Oetiker
and 1 contributors


 package ProxyFun;
 use Mojo::Base 'Mojolicious';

 sub startup {
    my $app = shift;

        # mandatory
        destination_url => 'http://www.oetiker.ch',
        # optional
        routes => $app->routes, # default 
        mount_point => '/', # default
        req_processor => sub { 
            my ($c,$req) = @_; 
            # do something to the request object prior
            # to passing it on to the destination_url
            # maybe fix the Origin or Referer headers
            for (qw(Origin Referer)){
                my $value = $req->headers->header($_) or next;
                if ( $value =~ s{http://www.oetiker.ch}{http://localhost:3000} ){
        res_processor => sub {
            my ($c,$res) = @_;
            # do something to the response object prior
            # to passing it on to the client
            # maybe fixing the location header
            # or absolute URLs in the body
            if (my $location = $res->headers->location){
                if ( $location =~ s{http://www.oetiker.ch}{http://localhost:3000} ){
            if ($res->headers->content_type =~ m{text/html} and my $body = $res->body){
                if ( $body =~ s{http://www.oetiker.ch}{http://localhost:3000}g){


The Mojolicious::Plugin::ReverseProxy lets your register a proxy route. The module is rather mindless in the sense that it does not try to help you with fixing headers or content to actually work with the proxy, apart from the Host header.

What makes this Plugin really useful, is that you can supply a req_processor and a res_processor callback which will act on the request prior to passing it on to the destination and on the response prior to returning it to the client respectively.

The plugin takes the following options:


Where should the proxy connect to

  destination_url => 'http://www.oetiker.ch'
routes (defaults to app->routes)

the routes object to use for adding the proxy route

mount_point (defaults to /)

under which path should the proxy appear.


Can be pointed to an anonymous subroutine which is called prior to handing control over to the user agent.

If you render the page in the req_processor callback, the page will be returned immediately without calling the destination_url


Can be pointed to an anonymous subroutine which is called prior to rendering the response.


Tobias Oetiker, <tobi@oetiker.ch>




This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 162:

You forgot a '=back' before '=head1'