Yes, I forgot to say that init() is required in my example. It creates the default useragent used by HTTP::Proxy.
As for the "Unsupported scheme" error, I've written the following test script (note the use of Devel::SimpleTrace, a very useful little module):
use strict;
use warnings;
use HTTP::Proxy;
use HTTP::Proxy::HeaderFilter::simple;
my $proxy = HTTP::Proxy->new(@ARGV);
$proxy->init();
$proxy->agent->protocols_allowed(
[ @{ $proxy->agent->protocols_allowed() }, 'proxy' ] );
print "$_ => ", $proxy->agent->is_protocol_supported($_), "\n"
for qw( http https ftp gopher wais plonk proxy );
$proxy->push_filter(
scheme => 'proxy',
request => HTTP::Proxy::HeaderFilter::simple->new(
sub {
my ( $self, $headers, $message ) = @_;
$message->uri('http://www.perdu.com/');
}
),
);
$proxy->start;
which dies with the same error, and a little more information:
http => 1
https => 1
ftp => 1
gopher => 1
wais => 0
plonk => 0
proxy => 0
Unsupported scheme: proxy at foo.pl line 19
at Carp::croak(unknown source)
at HTTP::Proxy::push_filter(lib/HTTP/Proxy.pm:622)
at main::(foo.pl:19)
(don't look at the line numbers, I'm working with the CVS version of HTTP::Proxy)
The code that triggers the error is here:
for (@scheme) {
croak "Unsupported scheme: $_"
if !$self->agent->is_protocol_supported($_);
}
The is_protocol_supported() of LWP::UserAgent not only checks the protocols_allowed() value, but also verifies that there exists an implementor for the scheme. This is done by the method implementor() of LWP::Protocol.
Since I don't want to overwrite LWP::Protocol::implementor, I guess I'll have to take another approach. Probably by checking that the protocol is supported by directly looking into protocols_allowed.
Well, I've just added a is_protocol_supported method to HTTP::Proxy, to check if scheme is supported directly by the proxy, even if LWP doesn't support it. It's in the CVS. The above example works perfectly.
HTTP::Proxy 0.16 will be released before YAPC::Europe (Aug 30, 2005). If you heavily use HTTP::Proxy, I suggest that you subscribe to the mailing lists listed at http://http-proxy.mongueurs.net/ : the mailing list is the main point of contact for people
using HTTP::Proxy. And you can even receive commit emails, if you want!
|