4

Have a web-page with very complex structure and javascript logic with many ajax calls, some requests only got a respond pure (applicaton/json) objects, some ajax gets html and so on... ;(

Need analyze the full communication between the browser and server, so decided write a perl-proxy what "simple" dump all text communication in any direction (requests and responses too).

Found the HTTP::Proxy module, but im totally confused with the filters.

The basic code:

use strict;
use warnings;
use HTTP::Proxy;

my $proxy = HTTP::Proxy->new( port => 3128 );
$proxy->start;

works nicely, but i havn't any idea how to write the filters for it.

The "eg" directory in the distribution have milion complicated examples how to modify the response body contents and so on, but the basic dump_all_communication is missing.

Can anybody guide me, how to write a simple filter for:

  • dump out all http-requests what are going from browser to server
  • and dump out the content of all responses, when they have mime: text/* and application/json and application/x-javascript (or better: for anything but no images, pdf and flash)

Here is similiar question, but it is want filter JSON and me want more simple - dump everything (all requests and all responses (but no images))

4

1 回答 1

2

基于一个例子,我会这样做。它只是将在此代理中经过的所有内容打印到 stderr。

相应地调整您的过滤器。

问候,

{
    package DumpAllBody;
    use base qw( HTTP::Proxy::BodyFilter );
    use Data::Dumper;
    sub filter {
        my ( $self, $dataref, $message, $protocol, $buffer ) = @_;
        warn "Body:\n".Dumper($dataref,$message,$protocol,$buffer);
    }
}
{
    package DumpAllHeader;
    use base qw( HTTP::Proxy::HeaderFilter );
    use Data::Dumper; 
    sub filter {
        my ( $self, $headers, $message ) = @_;

        warn "Body:\n".Dumper($headers,$message);
    }
}
$proxy->push_filter( request  => DumpAllHeader->new(), response => DumpAllHeader->new());
$proxy->push_filter( request  => DumpAllBody->new(),   response => DumpAllBody->new());
于 2012-09-04T12:20:49.647 回答