/usr/share/doc/libhttp-proxy-perl/examples/javascript.pl is in libhttp-proxy-perl 0.300-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #!/usr/bin/perl -w
use HTTP::Proxy;
use HTML::Parser;
use HTTP::Proxy::BodyFilter::htmlparser;
# define the filter (the most difficult part)
# filters not using HTML::Parser are much simpler :-)
my $parser = HTML::Parser->new( api_version => 3 );
$parser->handler(
start => sub {
my ( $self, $tag, $text ) = @_;
$self->{output} .= $text;
$self->{output} .= "YOUR JAVASCRIPT HERE" if $tag eq 'body';
},
"self,tagname,text"
);
$parser->handler(
default => sub {
my ($self, $text) = @_;
$self->{output} .= $text;
},
"self,text"
);
# this is a read-write filter (rw => 1)
# that is the reason why we had to copy everything into $self->{output}
my $filter = HTTP::Proxy::BodyFilter::htmlparser->new( $parser, rw => 1 );
# create and launch the proxy
my $proxy = HTTP::Proxy->new(@ARGV);
$proxy->push_filter( response => $filter, mime => 'text/html' );
$proxy->start();
|