Skip Menu |
 

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

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

People
Owner: book [...] cpan.org
Requestors: stennie [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.17
Fixed in: 0.18



Subject: Use $ua->agent->request instead of $ua->agent->simple_request
Download (untitled) / with headers
text/plain 925b
Hi, I'm using HTTP::Proxy to forward connections to an svn server which requires HTTP authentication. I have setup the agent similar to: my $agent = LWP::UserAgent->new(); $agent->credentials('http://my.trac.url','trac', $login, $password); .. however because HTTP::Proxy uses the $self->agent->simple_request() method, the credentials are not being passed through. Changing to agent->request() method provides full support. Patch attached against 0.17. Cheers, Stephen --- HTTP-Proxy-0.17/lib/HTTP/Proxy.pm.dist 2005-09-29 07:26:09.000000000 +1000 +++ HTTP-Proxy-0.17/lib/HTTP/Proxy.pm 2006-03-20 03:49:55.000000000 +1100 @@ -356,7 +355,7 @@ # pop a response my ( $sent, $chunked ) = ( 0, 0 ); - $response = $self->agent->simple_request( + $response = $self->agent->request( $req, sub { my ( $data, $response, $proto ) = @_;
Download (untitled) / with headers
text/plain 1.4k
Le Dim. Mar. 19 11:57:42 2006, stennie a écrit : Show quoted text
> Hi, > > I'm using HTTP::Proxy to forward connections to an svn server which > requires HTTP > authentication. > > I have setup the agent similar to:
You shouldn't have to change the default agent and daemon. This possibility will probably be removed in the future, anyway. Show quoted text
> my $agent = LWP::UserAgent->new(); > $agent->credentials('http://my.trac.url','trac', $login, $password); > > .. however because HTTP::Proxy uses the $self->agent->simple_request() > method, the > credentials are not being passed through. Changing to agent-
> >request() method provides
> full support.
Adding the credentials should be done with the help of a filter. I'd suggest something like the following in your proxy code : use HTTP::Proxy; use HTTP::Proxy::HeaderFilter::simple; use MIME::Base64 qw( encode_base64 ); my $proxy = HTTP::Proxy->new( @ARGV ); my $methods = join ',', qw( COPY MOVE PROPFIND ... ); my $credentials = 'Basic ' . encode_base64( "$login:$password", '' ); # transparently add the Authorization line $proxy->push_filter( method => $methods, # all WebDAV/DeltaV methods host => 'my.trac.url', # specific host request => HTTP::Proxy::HeaderFilter::simple->new( sub { my ( $self, $headers, $message) = @_; $headers->header( 'Authorization' => $credentials ); } ), ); $proxy->start(); This should do the trick.
Show quoted text
> You shouldn't have to change the default agent and daemon. This > possibility will probably be removed in the future, anyway.
Hi Phillipe, Thanks for the example code, I will try that out. I think it would be a shame to completely remove the possibility of providing a user $agent as there is some helpful behaviour that makes it easy to proxy other protocols based on HTTP transport which require additional config (e.g. svn, which is what I actually need to use this module for!). I guess it should be possible to do the equivalent of requests_redirectable via filters as well, but the additional setup required is a bit tedious when there is a simple and workable solution already ;). Also from your example .. in order to filter properly it would seem I need to peek inside HTTP::Proxy to get a list of supported methods I want to filter: method => $methods, # all WebDAV/DeltaV methods Perhaps you could provide a constructor option to choose agent->request() instead of the default agent->simple_request() ? That would be a welcome compromise. Cheers, Stephen
Download (untitled) / with headers
text/plain 1.7k
Le Dim. Mar. 19 12:51:14 2006, stennie a écrit : Show quoted text
> > You shouldn't have to change the default agent and daemon. This > > possibility will probably be removed in the future, anyway.
> > Thanks for the example code, I will try that out. I think it would be > a shame to completely > remove the possibility of providing a user $agent as there is some > helpful behaviour that > makes it easy to proxy other protocols based on HTTP transport which > require additional > config (e.g. svn, which is what I actually need to use this module > for!).
I know HTTP::Recorder works by providing a specific agent, but again, what it does could be done with a filter. Anyway, the agent-changing-code is still there, for the moment. :-) Show quoted text
> Also from your example .. in order to filter properly it would seem I > need to peek inside > HTTP::Proxy to get a list of supported methods I want to filter: > method => $methods, # all WebDAV/DeltaV methods
I could probably add a simple read-only accessor to get to those method names. Something like: $proxy->known_methods(); # all of @METHODS $proxy->known_methods( 'HTTP' ); # various $proxy->known_methods( 'WebDAV', 'DeltaV' ); # subsets But I don't know if people expect PUT or OPTIONS (which are part of HTTP) to be returned if they only ask for 'WebDAV'. So maybe each list should overlap a little (I should check what the RFC say) but the known_methods() would return the appropriately grep()ed list. Show quoted text
> Perhaps you could provide a constructor option to choose agent-
> >request() instead of the
> default agent->simple_request() ? That would be a welcome compromise.
That would change the behaviour of the proxy a lot. I'm not sure about this right now.
Show quoted text
> I could probably add a simple read-only accessor to get to those > method names. Something like: > > $proxy->known_methods(); # all of @METHODS > $proxy->known_methods( 'HTTP' ); # various > $proxy->known_methods( 'WebDAV', 'DeltaV' ); # subsets
Cool, that would be helpful. Since both WebDAV and DeltaV RFCs describe extensions to existing protocols, I think the methods should be additive (e.g. WebDAV = HTTP + WebDAV, DeltaV = WebDAV + DeltaV). Show quoted text
> > Perhaps you could provide a constructor option to choose agent-
> > >request() instead of the
> > default agent->simple_request() ? That would be a welcome compromise.
> > That would change the behaviour of the proxy a lot. I'm not sure about > this right now.
FWIW, I have been using this method for subversion proxying without problems for some time now (just hadn't got around to submitting the patches). I used some filters for debugging request/response as well, and these worked fine. Maybe you can add an "experimental option" disclaimer for this .. use at your own peril ;). Cheers, Stephen
Download (untitled) / with headers
text/plain 683b
Le Dim. Mar. 19 13:35:52 2006, stennie a écrit : Show quoted text
> > I could probably add a simple read-only accessor to get to those > > method names. Something like: > > > > $proxy->known_methods(); # all of @METHODS > > $proxy->known_methods( 'HTTP' ); # various > > $proxy->known_methods( 'WebDAV', 'DeltaV' ); # subsets
> > Cool, that would be helpful. Since both WebDAV and DeltaV RFCs describe > extensions to existing protocols, I think the methods should be additive > (e.g. WebDAV = HTTP + WebDAV, DeltaV = WebDAV + DeltaV).
The known_methods() method has been added in version 0.18, with WebDAV = HTTP + WebDAV extensions, DeltaV = WebDAV + DeltaV extensions.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.