Skip Menu |

This queue is for tickets about the libwww-perl CPAN distribution.

Report information
The Basics
Id: 20727
Status: resolved
Priority: 0/
Queue: libwww-perl

Owner: Nobody in particular
Requestors: cebratcher [...]

Bug Information
Severity: Important
Broken in: 5.805
Fixed in: (no value)

Subject: LWP::UserAgent 302/303 redirection incorrect
Download (untitled) / with headers
text/plain 1.1k
When UserAgent->request is called on a page that returns either 302 or 303, the method resets itself to GET. The following snippet (from the request subroutine) clearly shows the GET method being set unless the method is GET or HEAD. if ($code == &HTTP::Status::RC_SEE_OTHER || $code == &HTTP::Status::RC_FOUND) { my $method = uc($referral->method); unless ($method eq "GET" || $method eq "HEAD") { $referral->method("GET"); $referral->content(""); $referral->remove_content_headers; } } By W3C HTTP/1.1 standards (rfc2616), 302 should not redirect, but rather prompt the user for redirection. Now, very very few browsers actually do this, they just continue on. However, reformatting the data as GET is not a viable solution when a host only allows POST. The 303 should only contain a link and should not redirect at all. (Again, most browsers ignore this and just continue on.) As for a solution... Simply modifying the routine to check based on the "requests_redirectable" data rather than what's hardcoded seems like a logical route to me. If you need more info or help, feel free to ask! Thanks! -Clif
From: cebratcher [...]
Download (untitled) / with headers
text/plain 700b
Here's a quick fix to replace the previously posted routine. It shuffles through the requests_method array and if the method does not exist in the array, it switches to GET. A for loop would probably be faster, but this is a bit more legible. <code> if ($code == &HTTP::Status::RC_SEE_OTHER || $code == &HTTP::Status::RC_FOUND) { my $method = uc($referral->method); my $keep_method = 0; foreach (@{$self->requests_redirectable}) { if ($method eq $_) { $keep_method++; last; } } unless ($keep_method) { $referral->method("GET"); $referral->content(""); $referral->remove_content_headers; } } </code> -Clif

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

Please report any issues with to