From 5053daa98adc4f966893173480990b7c4ca49325 Mon Sep 17 00:00:00 2001 From: Hernan Lopes Date: Thu, 12 Apr 2012 01:43:36 -0300 Subject: [PATCH 1/2] added support for simple redirect of url, man in the middle style. I added support for simple redirect of urls, because i need to debug some javascript which is on production websites and i cant debug them online.. so i use this proxy to show my local js contents and this allows to modify the js, reload the webpage just like when i visit the web site . --- lib/HTTP/Proxy.pm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/HTTP/Proxy.pm b/lib/HTTP/Proxy.pm index 878a5bf..a4cfe37 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,32 @@ 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: +- Your browser requests http://www.somepage.com/page.htm +- Your proxy handles the request and checks if there is any redirect + for that url +- If there is a redirect, get the content and return it to browser + +And, 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; + +This would result in yahoo.com showing up in your browser when you +open http://www.google.com while on the properly configured proxy. + + =over 4 =item start_servers From 289e0e65d33c92dececa5a7d88582ff93865f7f9 Mon Sep 17 00:00:00 2001 From: Hernan Lopes Date: Thu, 12 Apr 2012 02:15:54 -0300 Subject: [PATCH 2/2] Better man for redirect url secion --- lib/HTTP/Proxy.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/HTTP/Proxy.pm b/lib/HTTP/Proxy.pm index a4cfe37..1c0fa09 100644 --- a/lib/HTTP/Proxy.pm +++ b/lib/HTTP/Proxy.pm @@ -1263,13 +1263,15 @@ 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: -- Your browser requests http://www.somepage.com/page.htm -- Your proxy handles the request and checks if there is any redirect - for that url -- If there is a redirect, get the content and return it to browser -And, an usage example of simple url redirect with C: + - 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 ); @@ -1279,8 +1281,10 @@ And, an usage example of simple url redirect with C: $proxy->start; 1; -This would result in yahoo.com showing up in your browser when you -open http://www.google.com while on the properly configured proxy. +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