我正在尝试为我的需求实现某种转发器。作为测试设备,它应该检测谷歌验证码请求以响应搜索请求。我的意思是如果初始请求是:
http://www.google.com/search?=example
并且搜索引擎将以URI
回复http://www.google.com/sorry/?continue=http://www.google.com/search%3Fq%3Fexample
自定义代理必须:
通过“/ sorry /”
将其转换为初始URI ... www.google.com/search?=example
我是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, like Gecko) Chrome/11.0.696.60 Safari/534.24');
open ( LOGFILE, ">>", "/var/log/repeater.log");
my $proxy = HTTP::Proxy->new(
port => '38374',
agent => $ua,
logfh => <LOGFILE>,
);
#HTTP::Proxy->new(@ARGV); #<- ???
$proxy->logmask( ALL );
$proxy->push_filter(
host => 'google.com', # only apply to this domain
response => HTTP::Proxy::HeaderFilter::simple->new( sub { my ( $self, $headers, $response ) = @_;
# skip non redirects
return if $response->code !~ /^3/;
# pick up location
my $location = $headers->header('Location');
# find bad redirections
if ( $location =~ m{google.com/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;
问题是,我已经为某些参数使用new()方法(接近“&lt; - ???”注释),但现在我需要传递@ARGV。由于缺乏经验,我无法完成这个脚本,但我真的需要这个工作:(。 提前谢谢。