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!