Allow a quickHead request, will only return headers

This commit is contained in:
Mikael Nordfeldth 2016-06-24 15:43:20 +02:00
parent c19f87f867
commit 0adb7af9a0

View File

@ -206,6 +206,29 @@ class HTTPClient extends HTTP_Request2
return $data;
}
/**
* If you want an Accept header, put it in $headers
*/
public static function quickHead($url, array $params=array(), array $headers=array())
{
if (!empty($params)) {
$params = http_build_query($params, null, '&');
if (strpos($url, '?') === false) {
$url .= '?' . $params;
} else {
$url .= '&' . $params;
}
}
$client = new HTTPClient();
$response = $client->head($url, $headers);
if (!$response->isOk()) {
// TRANS: Exception. %s is the URL we tried to GET.
throw new Exception(sprintf(_m('Could not GET URL %s.'), $url), $response->getStatus());
}
return $response->getHeader();
}
/**
* Convenience function to run a GET request.
*