develooper Front page | perl.libwww | Postings from March 2001

Re: Need help with my code?

Thread Previous
March 15, 2001 18:13
Re: Need help with my code?
Message ID:
>>>>> "Dave" == Dave Faraldo <> writes:

Dave> Yup, you got it.  Override LWP::UserAgent::redirect_ok with the 
Dave> following, and you should be golden:

Dave>   # Overloaded function to allow GET redirects following POSTs
Dave>   sub redirect_ok {
Dave>     my ($ua, $req) = @_;

Dave>     if (uc($req->method()) eq 'GET') {

Dave>       # Allow redirects on GET requests;
Dave>       return 1;

Dave>     } else {

Dave>       # Allow GET redirects from POSTs
Dave>       $req->method('GET');
Dave>       return 1;
Dave>     }

Dave>   }

Of course, overriding really only makes sense if you think someone
else in the same program needs the documented behavior.  I found it
much easier to just do this:

    use LWP::UserAgent;
    BEGIN { *LWP::UserAgent::redirect_ok = sub { 1 } }

Don't subclass.  Patch.

But then, I'm perverse. :)

Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<> <URL:>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See for onsite and open-enrollment Perl training!

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About