reintroduce the old getRedirectUrl()

cc @mmn

the new getRedirectUrl() didn't work with quitter.es, either from
quitter.se or quitter.no

it also looked like the HTTPClient-based function downloaded the whole
file, instead of only the headers. (but i'm not sure)
This commit is contained in:
Hannes Mannerheim 2015-06-02 09:13:21 +02:00
parent a016241dea
commit 4677503011

View File

@ -143,14 +143,19 @@ class ApiExternalUserShowAction extends ApiPrivateAuthAction
/** /**
* Get redirect(s) for an url * Get redirect(s) for an url
* *
* @return mixed Location URL if redirect, null if no Location header (through HTTP_Request2_Response getHeader())
*/ */
function getRedirectUrl ($url) { function getRedirectUrl ($url) {
$client = new HTTPClient(); stream_context_set_default(array(
$response = $client->head($url); 'http' => array(
return $response->getHeader('Location'); // null if it isn't set 'method' => 'HEAD'
)
));
$headers = get_headers($url, 1);
if ($headers !== false && isset($headers['Location'])) {
return $headers['Location'];
}
return false;
} }
} }