Howdy Bros. I am trying to figure out how to use HTTP::Proxy to do a simple filter on a response. Based on the docs, I implemented the following code:
#!/usr/bin/perl -w use HTTP::Proxy; use HTTP::Proxy::BodyFilter::simple; use HTTP::Proxy::BodyFilter::complete; my $proxy = HTTP::Proxy->new; # pass the complete response body to our filter (in one pass) $proxy->push_filter( mime => 'text/html', response => HTTP::Proxy::BodyFilter::complete->new, response => HTTP::Proxy::BodyFilter::simple->new( sub { my ( $self, $dataref, $message, $protocol, $buffer ) = @_; $dataref =~ s/Perl/PERL/; } ) ); $proxy->start;
When I access the Wikipedia Perl page through this proxy, it delivers the page but it does not substitute Perl with PERL.

It seems like the target of the substitution statement should be the right one because related docs say "$dataref is a reference to the chunk of body data received." I also tried changing the target to ${ $_[1] } as suggested here but that doesn't work either. The debugger indicates there is nothing like HTML in either of those variables.

So what am I doing wrong?

BTW my eventual goal is to intercept the html, parse/modify it with HTML::TreeParser, then send the modded data back to the client, if that mattes. But I thought I should start with something simple.

TIA

Steve


In reply to HTTP::Proxy::BodyFilter Shezza No Voik by cormanaz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.