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

Re: Need help with my code?

Thread Previous
From:
merlyn
Date:
March 15, 2001 18:13
Subject:
Re: Need help with my code?
Message ID:
m1d7bi5umt.fsf@halfdome.holdit.com
>>>>> "Dave" == Dave Faraldo <dfaraldo@nocpulse.com> 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
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About