Skip Menu |

This queue is for tickets about the HTTP-Proxy CPAN distribution.

Report information
The Basics
Id: 33465
Status: resolved
Priority: 0/
Queue: HTTP-Proxy

People
Owner: Nobody in particular
Requestors: bitcard [...] jrs-s.net
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.20
Fixed in: (no value)



Subject: BodyFilter::complete does not function
HTTP::Proxy::BodyFilter::complete does not function as advertised. [code]#!/usr/bin/perl use HTTP::Proxy; use HTTP::Proxy::BodyFilter::complete; use HTTP::Proxy::BodyFilter::simple; my $proxy = HTTP::Proxy->new; $proxy->port( 3128 ); $proxy->push_filter( mime => 'image/jpeg', response => HTTP::Proxy::BodyFilter::complete->new, response => HTTP::Proxy::BodyFilter::simple->new( sub { ${ $_[1] } = 'filtered!' } ), ); $proxy->start;[/code] Proxy starts and runs, but test download of a jpg shows that the simple filter is being run multiple times, not just once on the entire body: [code]# telnet localhost 3128 Trying 127.0.0.1... Connected to localhost.redacted.com. Escape character is '^]'. GET http://redacted.com/test.jpg filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!filtered!Connection closed by foreign host. [/code] Also does not work if BodyFilter::complete is called in an entirely separate push_filter invocation.
On Wed Feb 20 14:25:55 2008, Jimbo wrote: Show quoted text
> HTTP::Proxy::BodyFilter::complete does not function as advertised.
Yes, it does. Try with this code: #!/usr/bin/perl use strict; use warnings; use HTTP::Proxy; use HTTP::Proxy::BodyFilter::complete; use HTTP::Proxy::BodyFilter::simple; my $proxy = HTTP::Proxy->new(@ARGV); $proxy->push_filter( mime => 'image/*', response => HTTP::Proxy::BodyFilter::complete->new, response => HTTP::Proxy::BodyFilter::simple->new( sub { # size of data received ${ $_[1] } = length( ${$_[1]} ) . ' '; } ), ); $proxy->start; Here's an example session: $ telnet localhost 3128 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GET http://www.yapceurope.org/img/logo.png HTTP/1.0 HTTP/1.0 200 OK Date: Mon, 21 Apr 2008 00:38:59 GMT Via: 1.1 plop (HTTP::Proxy/0.21) Accept-Ranges: bytes ETag: "12c0b7-336c-4802a338" Server: Apache/1.3.36 (Unix) Content-Type: image/png Last-Modified: Mon, 14 Apr 2008 00:20:08 GMT 0 0 0 0 0 0 0 0 0 0 0 13164 Connection closed by foreign host. Show quoted text
> Proxy starts and runs, but test download of a jpg shows that the > simple > filter is being run multiple times, not just once on the entire body:
What happens is that the filter stores the data, and simply passes an empty $dataref to the next filter. So your filter is called many times with no data, and only receives the full set of data when called for the very last time (when the $buffer parameter to filter() is undefined). Regarding $buffer, HTTP::Proxy::BodyFilter says: "When the reference is C<undef>, it means that the filter cannot store any data, because this is the very last run, needed to gather all the data left in all buffers." I've patched the documentation of HTTP::Proxy::BodyFilter::complete to be more explicit. The documentation fixes will appear in version 0.22. Show quoted text
> Also does not work if BodyFilter::complete is called in an entirely > separate push_filter invocation.
This shouldn't make any difference, as the filter stack is computed for each request, independently of how the filters where configured with push_filter(). Thanks for your input. -- BooK