Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: LWP::UserAgent : setting max_redirect to 0 yields 'Client-Warning: Redirect loop detected

by genio (Beadle)
on Mar 13, 2018 at 20:43 UTC ( [id://1210846]=note: print w/replies, xml ) Need Help??


in reply to LWP::UserAgent : setting max_redirect to 0 yields 'Client-Warning: Redirect loop detected

Hi,

There seems to be a bit of confusion, but that's not your fault. The documentation is probably a bit lacking in this area.

my $ua = LWP::UserAgent->new(requests_redirectable => []);

There shouldn't be a need to worry about setting how many redirects to allow if you're already not allowing redirects on those types of requests.

Can you give that a try and maybe take a crack at helping fix the documentation lack in this area so nobody else falls into the same problem? We're always happy to have documentation patches!

-- Chase

  • Comment on Re: LWP::UserAgent : setting max_redirect to 0 yields 'Client-Warning: Redirect loop detected
  • Download Code

Replies are listed 'Best First'.
Re^2: LWP::UserAgent : setting max_redirect to 0 yields 'Client-Warning: Redirect loop detected
by bliako (Monsignor) on Mar 13, 2018 at 21:59 UTC

    Thanks for your reply,

    I can confirm that by just setting ONLY requests_redirectable => [], LWP::UserAgent does not follow redirects and does not warn about a loop detected.

    So, I guess you are asking me to write a documentation patch where to say:

    "If you do not want LWP::UserAgent to follow redirects for a certain request then prepare a new array with only the request names you wish redirects to be followed and insert it via requests_redirectable => $array_of_requests_to_follow_redirect. If you do not want LWP::UserAgent to follow ANY request then set this to an empty array ref."

    That's no problem, I can do that.

    As a side remark (but quite important imo):

    when looking at the code of LWP::UserAgent at the place where it gives the loop warning (just search for 'loop') one can see that when the alleged loop is detected, the warning is inserted in the headers AND the sub returns immediately thus omitting code for running the handlers or normalising (absolutising) the Location url from the returned headers and lots of other stuff.

    So that "warning" is not that innocent and people should care about it. Maybe it should be clarified. I will agree with the "Anonymous Monk" (Mar 13, 2018 at 20:21 UTC) who considers this as a bug because the logic (with my limited understanding of that code) should be to make a request, increment the redirect count (its name probably is confusing because there is no redirect yet but just one - and maybe the only - request) and then check if that count exceeds the max_redirect limit (and not check if it is equal to it too).

    In view of the above, a second documentation patch could go like this:

    "Redirect loop detection is a bit petulant and one should not upset it further by demanding zero max_redirect. Notice that max_redirect counts the first request as a redirect. And so if one wants zero redirects, one should set max_redirect to 1 really. The side-effect of LWP::UserAgent detecting a loop and acting on it, appart from inserting a Client-Warning in the response headers, is that the request() will immediately return albeit half-finished. For example no handlers will be run."

      That's no problem, I can do that GLADLY.

        ... And so if one wants zero redirects, one should set max_redirect to 1 really ...

        NO, that's wrong. Use only  requests_redirectable method.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210846]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-16 19:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found