0

I set

 add_filter( 'http_request_redirection_count', array($instance,'SetDirectionCount'));

to 0

I try to get 'http://boards.ign.com/The_Vestibule/b5296/' or 'http://www.informationweek.com/story/' but that gives me:

 WP_Error Object ( [errors] => Array ( [http_request_failed] 
 => Array ( [0] => Maximum (0) redirects followed ) ) [error_data] => Array ( ) )

The head does not show me a redirection:

Array ( [headers] => Array ( [connection] => close [date] => 
Mon, 14 Mar 2011 01:40:19 GMT [server] => Microsoft-IIS/6.0 [p3p] => Array ( [0] =>  
CP='NOI ADMa OUR STP' [1] => CP="TST" ) [x-powered-by] => ASP.NET [cluster-server] => \      ignprdappw64212 [x-aspnet-version] => 2.0.50727 [pragma] => no-cache [x-aspnetmvc-version] 
=> 1.0 [set-cookie] => BoardCookieV3%5Fboards%2Eign%2Ecom=dc=no&ra=False; expires=Wed,     14-Mar-2012 01:40:19 GMT; path=/; HttpOnly [cache-control] => private [expires] => Wed, 14     
Mar 2001 01:40:19 GMT [content-type] => text/html; charset=utf-8 ) [body] => [response]   =>   
Array ( [code] => 200 [message] => OK ) [cookies] => Array ( [0] => WP_Http_Cookie 
Object ( [name] => BoardCookieV3%5Fboards%2Eign%2Ecom [value] => dc=no&ra=False   
[expires] => 1331689219 [path] => / [domain] => [httponly] => ) ) )

Now... what I would have liked is information back from the head request that a 301 or 302 would be happening or even a 404, so that I could wp_remote_get that one instead.

Am I doing something wrong?

FYI: I need to manually redirect because I need to determine the base_href of an image if none is given in the HTML source (code: http://plugins.trac.wordpress.org/browser/wp-favicons/trunk/includes/class-http.php ) or some more background: http://wp.leau.co/2011/03/18/handling-redirects-for-wp-favicons-with-redirects-set-to-0-with-wordpress-wp_remote_get/

1 Answer 1

2

Taking a look at the WordPress HTTP API, it seems there ain't no simple way to do this. In fact, it might even be a calling for a trac ticket.

See, although it allows you to specify the maximum number of redirects, there's no abstract option to control if redirects should even be followed.

So setting a max redirect count of 0, the HTTP API will simply fail with something like 'Maximum redirects followed'.

For the time being, you'll need to examine the request method of each HTTP transport class (WP_Http_Curl, WP_Http_ExtHttp...) and look for ideal filters and actions you can use to set the 'nofollow' option for that particular transport.

On further inspection, I believe only the cURL component of the API is affected;

function __set_curl_nofollow( &$handle )
{
    curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false );  
}
add_action( 'http_api_curl', '__set_curl_nofollow' );

As I mentioned about submitting to trac, I think there should be another option for the API, such as 'follow_redirection', that will then do what it is intended - abstract and take out the hassle!

Trac ticket 16855

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.