Skip Menu |

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

Report information
The Basics
Id: 89775
Status: resolved
Priority: 0/
Queue: Net-Async-HTTP

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.30
Fixed in: 0.31



Subject: Parse username/password out of request URL
LWP::UA does this itself; $ua->request( GET => "http://user:pass@hostname/" ); sets the Basic Auth header on the request. NaHTTP should probably do the same. -- Paul Evans
On Fri Oct 25 10:57:21 2013, PEVANS wrote: Show quoted text
> LWP::UA does this itself; > > $ua->request( GET => "http://user:pass@hostname/" ); > > sets the Basic Auth header on the request. NaHTTP should probably do > the same.
Also raised #89968 on the underlying HTTP::Request. -- Paul Evans
Patch attached. Will be in 0.31. -- Paul Evans
Subject: rt89775.patch
=== modified file 'lib/Net/Async/HTTP/Connection.pm' --- lib/Net/Async/HTTP/Connection.pm 2013-11-01 20:55:57 +0000 +++ lib/Net/Async/HTTP/Connection.pm 2013-11-01 22:08:47 +0000 @@ -468,7 +468,15 @@ my $uri = $req->uri; $path = $uri->path_query; $path = "/$path" unless $path =~ m{^/}; - $headers->init_header( Host => $uri->authority ); + my $authority = $uri->authority; + if( defined $authority and + my ( $user, $pass, $host ) = $authority =~ m/^(.*?):(.*)@(.*)$/ ) { + $headers->init_header( Host => $host ); + $headers->authorization_basic( $user, $pass ); + } + else { + $headers->init_header( Host => $authority ); + } } my $protocol = $req->protocol || "HTTP/1.1"; === modified file 't/01request.t' --- t/01request.t 2013-09-13 19:39:45 +0000 +++ t/01request.t 2013-11-01 22:08:47 +0000 @@ -478,4 +478,25 @@ expect_res_code => 200, ); +$req = HTTP::Request->new( GET => "http://user:pass\@somehost2/with/secret" ); + +do_test_req( "request-implied authentication", + req => $req, + no_host => 1, + + expect_req_firstline => "GET /with/secret HTTP/1.1", + expect_req_headers => { + Host => "somehost2", + Authorization => "Basic dXNlcjpwYXNz", # determined using 'wget' + }, + + response => "HTTP/1.1 200 OK$CRLF" . + "Content-Length: 4$CRLF" . + "Content-Type: text/plain$CRLF" . + $CRLF . + "Booo", + + expect_res_code => 200, +); + done_testing;
Now released in 0.31. -- Paul Evans