Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by bliako (Vicar)
on Mar 13, 2018 at 21:59 UTC ( #1210852=note: print w/replies, xml ) Need Help??


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

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."

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

Replies are listed 'Best First'.
Re^3: LWP::UserAgent : setting max_redirect to 0 yields 'Client-Warning: Redirect loop detected
by bliako (Vicar) on Mar 13, 2018 at 22:00 UTC
    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.

        imho, max_redirect => 0 should not warn. I'm with AnonyMonk above in that this smells like a bug (whether doc or code, I digress).

        If a parameter such as one that has "max" in its name is set to zero, it should not trigger a warning like this.

        Perhaps there's a good reason for it, but that would make it a doc bug. Otherwise, if I say "max something is zero", then any warnings/errors should be ignored, which would be a code bug.

        After a cursory review, the documentation does not handle this situation, and it should.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2019-12-11 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?