Posted on 2007-02-23 21:15:29-08 by jtk
http login id and password patch
There is a bug report 7554 regarding the ability for module to support login:password@ in the http URI. I made a small patch against module version 2.120 on http.pm that seems to work well enough for this purpose. I basically used the same approach that already exists in ftp.pm. Patch as follows:
--- old.http.pm +++ new.http.pm @@ -7,7 +7,8 @@ use Regexp::Common qw /pattern clean no_defaults/; use Regexp::Common::URI qw /register_uri/; -use Regexp::Common::URI::RFC2396 qw /$host $port $path_segments $query/; +use Regexp::Common::URI::RFC2396 qw /$host $port $path_segments $query + $userinfo $userinfo_no_colon/; use vars qw /$VERSION/; @@ -16,12 +17,20 @@ my $http_uri = "(?k:(?k:http)://(?k:$host)(?::(?k:$port))?" . "(?k:/(?k:(?k:$path_segments)(?:[?](?k:$query))?))?)"; +my $http_uri_password = + "(?k:(?k:http)://(?k:(?k:$userinfo_no_colon)" . + "(?::(?k:$userinfo_no_colon))?\@)?(?k:$host)" . + "(?::(?k:$port))?(?k:/(?k:(?k:$path_segments)" . + "(?:[?](?k:$query))?))?)"; + register_uri HTTP => $http_uri; -pattern name => [qw (URI HTTP), "-scheme=http"], +pattern name => [qw (URI HTTP), "-scheme=http", "-password="], create => sub { my $scheme = $_ [1] -> {-scheme}; - my $uri = $http_uri; + my $uri = exists $_ [1] -> {-password} && + !defined $_ [1] -> {-password} ? $http_uri_password + : $http_uri; $uri =~ s/http/$scheme/; $uri; }
To use:
/$RE{HTTP}{-password}/
John
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.