我正在使用HTTP::Proxy,但我无法理解如何让某些域失败。
这是一些代码。
use HTTP::Proxy;
use HTTP::Proxy::BodyFilter::simple;
use HTTP::Proxy::HeaderFilter::simple;
use Getopt::Long;
my $port = 3128;
my $fail_at;
my $ret = GetOptions ( "port=i" => \$port,
"fail=s" => \$fail_at );
my @fail_at = split(/,/, $fail_at);
my $proxy = HTTP::Proxy->new;
$proxy->port( $port );
my $fail_filter = HTTP::Proxy::HeaderFilter::simple->new(
sub { $_[1]->header( HEADERS_HERE ); }
);
foreach my $url (@fail_at) {
$proxy->push_filter(
host => $url,
response => $fail_filter
);
}
$proxy->start;
请你帮我理解我要写的东西代替HEADER_HERE?
我尝试使用Status => '403 Forbidden'
,但它没有用。我能够修改http响应的每一行,但第一行。
非常感谢。
答案 0 :(得分:0)
请参阅method code
in HTTP::Response
。
use HTTP::Status qw(HTTP_FORBIDDEN);
⋮
my $fail_filter
= HTTP::Proxy::HeaderFilter::simple->new(sub {
$_[2]->code(HTTP_FORBIDDEN);
});