Enclosed: Patch for LWP::UserAgent.pm

Chris W. Unger (cunger@cas.org)
Thu, 19 Mar 1998 13:00:47 -0500


I am enclosing a change to UserAgent.pm that will allow it to better handle
non-standard redirects by servers that return a relative URL in the "Location"
field.  For example, one of my Perl applications received the following
redirect:

HTTP/1.1 302 Moved Temporarily
Date: Tue, 17 Mar 1998 18:22:33 GMT
Server: Apache/1.2.5
Location: http:/cgi-bin/fai.idealibrary.com_8011/iplogin/citation/0022-2836/269/623
Connection: close
Content-Type: text/html

Notice how the relative URL specified in the "Location" field begins with
"http:".  The current version of UserAgent.pm cannot handle a relative URL
in this type of format, but the popular browsers like Netscape and IE have
no problem with these types of redirects.  I added the following code to
UserAgent.pm handle this:

 CHANGED:

	# And then we update the URL based on the Location:-header.
	# Some servers erroneously return a relative URL for redirects,
	# so make it absolute if it not already is.
	my $referral_uri = (URI::URL->new($response->header('Location'),
					  $response->base))->abs();

 TO:

	# And then we update the URL based on the Location:-header.
	# Some servers erroneously return a relative URL for redirects,
	# so make it absolute if it not already is.
	my $location = $response->header('Location');
	$location =~ s!^http:(/[^/])!$1!;
	my $referral_uri = (URI::URL->new($location,
					  $response->base))->abs();


Thank you in advance for considering my enhancement/fix request.

			Chris

================================================================================
Chris W. Unger                               Chemical Abstracts Service
Phone: (614) 447-3600 (x2310)                2540 Olentangy River Road
Internet: cunger@cas.org                     Columbus, OH 43210
================================================================================