Skip to content

added support for simple redirect of url, man in the middle style. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/HTTP/Proxy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ sub serve_connections {
if $conn->reason ne 'No more requests from this connection';
return;
}
if ( defined $self->stash('redirects') and exists $self->stash( 'redirects' )->{ $req->uri->as_string } ) {
$req->uri( $self->stash( 'redirects' )->{ $req->uri->as_string } );
}
$self->log( STATUS, "REQUEST", $req->method . ' '
. ( $req->method eq 'CONNECT' ? $req->uri->host_port : $req->uri ) );

Expand Down Expand Up @@ -1254,6 +1257,36 @@ The following attributes control the TCP connection. They are passed to
the underlying C<HTTP::Proxy::Engine>, which may (or may not) use them
to change its behaviour.

=head2 Redirect url ( style man in the middle )

C<HTTP::Proxy> offers you the possibility of easily url redirect.
This redirect feature can be useful on scenarios where you want to
load a developer version of a javascript or css file on a production
website.

It works like this:

- The browser requests http://www.somepage.com/page.htm
- Foreach request within this page, verify if there is any redirect for url
- If there is a redirect, get the content from the defined redirect url
and return it to browser, as it is comming from the original url.

An usage example of simple url redirect with C<HTTP::Proxy>:

use HTTP::Proxy;
my $proxy = HTTP::Proxy->new( port => 13128 );
$proxy->stash( redirects => {
'http://www.google.com/' => 'http://www.yahoo.com/',
} );
$proxy->start;
1;

And open http://www.google.com while on the properly configured proxy.
This will result in:
browser url http://www.google.com with content from http://www.yahoo.com



=over 4

=item start_servers
Expand Down