use HTTP::Proxy qw( :log );
use HTTP::Proxy::HeaderFilter::simple;
use MIME::Base64 qw( encode_base64 );
use strict;
my $token = "Basic " . encode_base64( "http:proxy", '' );
my $proxy = HTTP::Proxy->new(@ARGV);
$proxy->push_filter(
request => HTTP::Proxy::HeaderFilter::simple->new(
sub {
my ( $self, $headers, $request ) = @_;
my $auth = $self->proxy->hop_headers->header('Proxy-Authorization')
|| "";
if ( $auth ne $token ) {
my $response = HTTP::Response->new(407);
$response->header(
Proxy_Authenticate => 'Basic realm="HTTP::Proxy"' );
$self->proxy->response($response);
}
}
)
);
$proxy->start;