Perl http :: proxy - discard all messages

You have a web page with a very complex JavaScript structure and logic with many ajax calls, some requests received only clean (applaton / json) objects, some ajax receives html, etc .... (

We need to analyze the full connection between the browser and the server, so we decided to write perl-proxy that "simple" dump all text messages in any direction (requests and answers too).

Found HTTP :: Proxy , but im completely confused with filters.

Main code:

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

works beautifully, but I don’t know how to write filters for it.

There are millions of complicated examples in the eg directory in the distribution, how to change the contents of the response body, etc., but there is no basic dump_all_communication .

Can someone help me how to write a simple filter for:

  • upload all http requests that go from browser to server
  • and unload the contents of all answers when they have mime: text/* and application/json and application/x-javascript (or better: for anything other than images, pdf and flash)

Here is a similar question , but he wants to filter JSON, and I need a simpler one - reset everything (all requests and all answers (but without images))

+4
source share
1 answer

Based on one example, I would do this. It simply prints to stderr everything that passes through this proxy.

Adjust your filter accordingly.

Hello,

 { 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()); 
+2
source

Source: https://habr.com/ru/post/1432110/


All Articles