Skip to content

Instantly share code, notes, and snippets.

@hernan604
Last active December 28, 2015 08:09
Show Gist options
  • Select an option

  • Save hernan604/7469329 to your computer and use it in GitHub Desktop.

Select an option

Save hernan604/7469329 to your computer and use it in GitHub Desktop.
http proxy interceptor example.
#build your proxy class with the plugins you want
package My::Proxy;
use Moose;
extends qw/HTTP::Proxy::Interceptor/;
with qw/
HTTP::Proxy::InterceptorX::Plugin::ContentModifier
/;
# with qw/
# HTTP::Proxy::InterceptorX::Plugin::File
# HTTP::Proxy::InterceptorX::Plugin::UrlReplacer
# HTTP::Proxy::InterceptorX::Plugin::ContentModifier
# /;
#HTTP::Proxy::InterceptorX::Plugin::ContentModifier;
#HTTP::Proxy::InterceptorX::Plugin::File;
#HTTP::Proxy::InterceptorX::Plugin::ImageInverter;
#HTTP::Proxy::InterceptorX::Plugin::RelativePath;
#HTTP::Proxy::InterceptorX::Plugin::UrlReplacer;
my $p = My::Proxy->new;
$p->run( port => $p->porta );
1;
perl -IHTTP-Proxy-Interceptor/lib/ -IHTTP-Proxy-InterceptorX-Plugin-ContentModifier/lib/ -IHTTP-Proxy-InterceptorX-Plugin-File/lib/ -IHTTP-Proxy-InterceptorX-Plugin-ImageInverter/lib/ -IHTTP-Proxy-InterceptorX-Plugin-RelativePath/lib/ -IHTTP-Proxy-InterceptorX-Plugin-UrlReplacer/lib/ proxy.pl --config urls.pl
#this is your proxy config, you can use any filename and formats: perl, json, yaml, etc
{
# Troca conteudo usando o Content Modifier... ele carrega um arquivo inteiro e joga como resposta parece que funciona melhor que o 'file'
"http://sitel.com/blabla.js" => {
ContentModifier => sub {
my ( $self, $content ) = @_;
use File::Slurp;
return read_file( "/home/hernan/perl/proxy/git/arquivo.js" );
}
},
"http://some/url/bla.js" => {
File => "/home/hernan/simulador.dados"
},
# Serve o conteudo de um arquivo local no lugar do conteudo de uma url
"http://site.com/h/2013/min-async.js?v=136" => {
File => "/home/hernan/teste.js"
},
# Troca uma url pelo conteudo de outra url
"http://um.site.com.br/arquivo.js" => {
UrlReplacer => "http://outro.site.com.br/outro.arquivo.js",
use_random_var => false #opcional, para colocar variavel randomica ao final da url
},
# Troca o conteudo de uma imagem pela imagem de outra url
"http://p1-cdn.trrsf.com/image/fget/cf/742/556/0/55/407/305/images.terra.com/2013/09/04/italianomortebrasileirafacereprod.jpg" => {
UrlReplacer => "http://h.imguol.com/1309/14beyonce23-gb.jpg"
},
# Carrega conteudo de arquivos locais ao inves do arquivo do site.
# Pega o caminho relativamente igual aos diretorios do site.
"http://publicador.intranet/resources/(?<caminho>.+)" => {
RelativePath => "/home/hernan/publicador/resources/"
},
# Troca o conteudo de um site pelo conteudo de ouro site
"http://www.site1.com.br/" => {
UrlReplacer => "http://www.site2.com.br/"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment