in reply to LWP redirect problem, produces malformed URL?
I believe this could be considered an LWP bug. It is triggered by the double "Location:" header.
When LWP is processing the redirect request, it gets the new URI from the Location header with this bit of code:
and since the "header()" method (in scalar mode) helpfully returns a comma separated list of all instances of the requested header, you end up with a weird URI.# And then we update the URL based on the Location:-header. my $referral_uri = $response->header('Location');
There are several possible solutions:
Here is some untested code that should do the trick:
package FixRedirectLWPUserAgent; ########################################################## # Derived from LWP::UserAgent # Handle redirect_ok method to fix double Location header. ########################################################## use strict; use warnings; use LWP::UserAgent; our @ISA = qw( LWP::UserAgent ); sub redirect_ok { my ($self, $prospective_request, $response) = @_; # Check response for multiple location headers. my @locations = $response->header('Location'); if (scalar(@locations) > 1) { my $uri = $prospective_request->uri(); my @uris = split /, /,$uri; $prospective_request->uri($uris[0]) if scalar @uris; } # Call parent to do all the boring work. my $ok = $self->SUPER::redirect_ok($prospective_request, $response +); return $ok; } 1;
|
|---|