use strict; use HTTP::Proxy qw(:log); my $proxy = new HTTP::Proxy( host => "localhost", port => 9999, logmask => HEADERS | STATUS, agent => new myagent, ); unlink "querylog.pl" if -f "querylog.pl"; $proxy->start; package myagent; use strict; use base 'LWP::UserAgent'; use Data::Dumper; local $Data::Dumper::Indent = 1; sub new { my $class = shift; my $this = $class->SUPER::new(@_); $this->timeout( 20 ); $this->agent("SniffProxy/0.9"); $this->requests_redirectable([qw(GET POST)]); return $this; } sub simple_request { my $this = shift; my ($req) = @_; if( $req->isa("HTTP::Request") ) { # and $req->method eq "POST" ) { open my $out, ">>", "querylog.pl" or die "couldn't open query log: $!"; print $out "#############################\n# $req->{_method} $req->{_uri}\n# HTTP::Request {", "{{\n"; print $out "use strict;\n"; print $out "use URI::http;\n"; print $out "use HTTP::Request;\n"; print $out "use LWP::UserAgent;\n"; print $out "use HTTP::Request::Common qw(POST GET);\n\n"; print $out "my ", Dumper( $_[0] ); print $out "# }}", "}\n\n"; print $out "my \$ua = new LWP::UserAgent;\n"; print $out " \$ua->timeout( 10 );\n"; print $out " \$ua->requests_redirectable([qw(GET POST)]);\n"; print $out "\n"; print $out "\$ua->simple_request( \$VAR1, \"content.dat\" );\n"; close $out; } return $this->SUPER::simple_request(@_); }