views:

101

answers:

1

I'm having some trouble getting filters working with HTTP::Proxy and I just can't seem to figure out what I should add to the logmask() function to get that information.

I've got a log file, that part is fine, logging is happening, but no information about filters, although they're implemented and (sometimes) working.

I've tried

  • logmask(['FILTERS'])
  • logmask('FILTERS')
  • logmask(FILTERS)

and none of those work! What am I missing?

Also, what's all that about the powers of two for the mask? And the constants being exported by :log?

I'm rather confused, as you can tell.

EDIT:

going by the advice below, I have the following script:

#!/sw/bin/perl
use strict;
use warnings;
use HTTP::Proxy qw( :log );
use HTTP::Proxy::BodyFilter::tags;
use HTTP::Proxy::BodyFilter::simple;
open( LOG, '>>', "/Users/ambrose/proxy-log.txt" ) or die "$!";

my $proxy = HTTP::Proxy->new;
$proxy->port(3128);
$proxy->logfh(*LOG);
$proxy->logmask( ALL );

$proxy->push_filter(
 mime     => 'text/html',
 response => HTTP::Proxy::BodyFilter::tags->new(),
 response => HTTP::Proxy::BodyFilter::simple->new(
  sub { ${ $_[1] } =~ s!(</?)i>!$1b>!ig }
 )
);

$proxy->start;

which doesn't log anything about filters, although the filter is in operation, I can see that italics have been changed to bold, as in the example.

If I change the line:

$proxy->logmask( ALL );

to

$proxy->logmask( FILTERS );

nothing gets added to the log file at all.

+1  A: 

Note that the logging constants are not exported by default, but by the :log tag. They can also be exported one-by-one.

They're symbolic constants, so you want to do $proxy->logmask( FILTERS ), but first you need to use HTTP::Proxy qw(:log) or use HTTP::Proxy qw(FILTERS).

Or if you don't like namespace pollution you should be able to do $proxy->logmask( HTTP::Proxy::FILTERS() )

hobbs