http://www.google.com/search?=perlmonks
and search engine will respond
http://www.google.com/sorry/?continue=http://www.google.com/search%3Fq%3Fperlmonks
Custom proxy must:1. Detect this response by "/sorry/"
2. Turn it into initial request again :
http://www.google.com/search?=perlmonks
3. Redirect client on
http://www.google.com/search?=perlmonks
I'm new to perl, so this code may contain mistakes:The thing is, I've allready used new() method for some parameters, but now I need to pass @ARGV. I can't finish this script due to a lack of experience but I really need this thing to work :(. Thanks in advance.#!/usr/bin/perl use strict; use warnings; use HTTP::Proxy qw( :log ); use HTTP::Proxy::HeaderFilter::simple; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); $ua->proxy(['http'],'http://127.0.0.1:29999'); $ua->timeout(10); $ua->agent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, li +ke Gecko) Chrome/11.0.696.60 Safari/534.24'); #open ( LOGFILE, ">>", "/var/log/repeater.log"); my $fname = "/var/log/repeater.log"; open my $logfh, ">>", $fname or die "couldn't open '$fname': $!"; my $proxy = HTTP::Proxy->new( port => '38374', agent => $ua, logfh => $logfh, @ARGV ); #HTTP::Proxy->new(@ARGV); ### <------- Is there any method that will +allow to pass @ARGV or something else if new() method was used earlie +r. $proxy->logmask( ALL ); $proxy->push_filter( # host => 'google.com', # only apply to this domain response => HTTP::Proxy::HeaderFilter::simple->new( sub { my ( $s +elf, $headers, $response ) = @_; # skip non redirects return if $response->code !~ /^3/; # pick up location my $location = $headers->header('Location'); # find bad redirections if ( $location =~ m{\/sorry.*} ) { # change the redirect my $new_location = $location ; $new_location =~ s/.*(\/sorry\/\?continue=.*)/$1/gx ; $new_location =~ s/\/sorry\/\?continue=//; $headers->header( Location => $new_location ); # print some logging information $self->proxy->log( ALL, LOCATION => "$location => $new_location" ); } } ) ); $proxy->start;
In reply to Unfinished custom proxy by kazak
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |