A simple perl proxy server which listens for web requests and log them to a file. Very useful for debugging web requests on the server side. Especially traditional form POSTs , which are not displayed by FireBug.
Usage:
> ./proxy-server.pl
Change your browser to use a proxy server. Point it to the host running this script and port 8001.
#!/usr/bin/perl use strict; use HTTP::Proxy qw(:log); use HTTP::Proxy::BodyFilter::simple; use HTTP::Proxy::BodyFilter::complete; use Data::Dumper; my $proxy = HTTP::Proxy->new(port => 8001); $proxy->host(undef); #$proxy->logmask(ALL); $proxy->push_filter( mime => undef, response => HTTP::Proxy::BodyFilter::complete->new ); $proxy->push_filter( mime => undef, request => HTTP::Proxy::BodyFilter::simple->new(sub { my ($self, $dataref, $req, $protocol, $buffer ) = @_; open (my $fh, '>>', ($ARGV[0] || 'http-recorder.txt')); my $cookie = $req->header('cookie'); my $xhr = $req->header('x-requested-with'); print $fh $req->method,' ',$req->uri; my @headers; if($cookie) { push(@headers, ['cookie', $cookie]); } if ($xhr) { push(@headers, ['x-requested-with', $xhr]); } my $content_type = $req->header('content-type'); if($content_type) { push(@headers, ['content-type', $content_type]); } if(@headers > 0) { local $Data::Dumper::Indent=0; local $Data::Dumper::Varname=""; my $str = Data::Dumper::Dumper(\@headers); $str =~ s/^\$1\s+=\s+//; print $fh " HEADERS: $str" if $str; } print $fh 'CONTENT: ',$req->content if $req->content; print $fh "\n"; $fh->close; }), response => HTTP::Proxy::BodyFilter::simple->new(sub { my ($self, $dataref, $req, $protocol, $buffer ) = @_; open (my $fh, '>>', 'http-response.txt'); print $fh $$dataref, "\n"; $fh->close; }) ); # start the proxy $proxy->start(); 1;
It listens on port 8001 and writes headers and incoming data (including POSTed data) in a file called http-recorder.txt and outgoing response to http-response.txt
