diff --git a/lib/HTTP/Proxy.pm b/lib/HTTP/Proxy.pm index 878a5bf..1c0fa09 100644 --- a/lib/HTTP/Proxy.pm +++ b/lib/HTTP/Proxy.pm @@ -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 ) ); @@ -1254,6 +1257,36 @@ The following attributes control the TCP connection. They are passed to the underlying C, which may (or may not) use them to change its behaviour. +=head2 Redirect url ( style man in the middle ) + +C 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: + + 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