I'm using HTTP::Proxy but I'm not able to understand how to make it fail for certain domain.
Here is some code.
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;
Can you please help me to understand what I have to write in place of HEADER_HERE?
I tried with Status => '403 Forbidden'
but it didn't work. I'm able to modify every line of the http response, but the first.
Thank you very much.
See method code
in HTTP::Response
.
use HTTP::Status qw(HTTP_FORBIDDEN);
⋮
my $fail_filter
= HTTP::Proxy::HeaderFilter::simple->new(sub {
$_[2]->code(HTTP_FORBIDDEN);
});