[wp-trac] [WordPress Trac] #16855: HTTP API No Follow Redirection

WordPress Trac wp-trac at lists.automattic.com
Fri Mar 18 18:10:25 UTC 2011


#16855: HTTP API No Follow Redirection
--------------------------+------------------------------
 Reporter:  TheDeadMedic  |       Owner:  dd32
     Type:  defect (bug)  |      Status:  reviewing
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  HTTP          |     Version:  3.1
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+------------------------------

Comment (by hakre):

 I can understand what you're looking for but I have problems to
 understand.

 The meanin of a sentence like "When we don't want to follow redirects" is
 pretty broad. Do I want to prevent that the HTTP compontent is performing
 redirects? Then the error returning message is quite right.

 If I only want to get the response headers of a request but not the HTTP
 component following any redirects, then this might need an additional
 switch, like `do-not-redirect = true` or `get-response = true`.

 But settings the maximum redirects switch to 0 must not mean that the
 component genreally should not follow redirects at all.

 The defnition of that '''redirection''' switch is inside the code:

 > 'redirection' is used to track how many redirects were taken and used to
 sent the amount for other transports, but not all transports accept
 setting that value.

 That's for the general WP_Http class. As this ticket is about cUrl, it's
 important to say that the cUrl imlementation lacks of any additional
 information.

 It's known from other tickets that cUrl supports redirection and that the
 ''redirection'' parameter is to be supported but subject to
 interpretation. It was roughly fixed once. See #11305 .

 The default `redirection` value is 5.

 That means that a request will automatically perform a redirection up to 5
 times before giving an error which means up to 6 HTTP requests, of which
 the last 5 ones are triggered by a 3xx redirect response and a related
 location header.

 Becase an automatic redirect is by definition a response with a 3xx status
 code and a location header.

 ''Some'' wordpress HTTP implementations will process any response as an
 automatic redirect only if they have a location header and regardless of
 the HTTP response code (see #16889) but this problem is out of the scope
 of this ticket so I would prefer for clarification purposes to stick to
 the HTTP RFC definition of an automatic redirect while writing about it.

 So I think the discussion of this issue will benefit of some clarification
 what should be achieved and how.

 As far as I can see, the ''redirection'' argument (flag, switch whatever
 it is called) does only limit the maximum number of redirects that will be
 performed before returning WP_Error.

 It is totally inappropriate to prevent redirects and only perform the
 request w/o automatic handling.

 Instead of setting that value to 0 (which is highly undefined, especially
 with the hotfix for cUrl in [12745]) you must instead propery interfere
 with cUrl request context options and set your suggested value manually if
 you don't want to let WP_Http_Curl follow redirect locations:

   curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false );

 So this is different to the scope of the current redirection argument, at
 least it can be different due to different opinions and the missing
 specification.

 However for what you ask for I would suggest that we add another argument,
 namely ''followlocation'' (like curl has) and implement that.

 So we don't mix things with number of redirects and enable users of the
 API to do requests w/o performing automatic redirects.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16855#comment:11>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list