From: Mikael Nordfeldth Date: Fri, 24 Jun 2016 13:43:20 +0000 (+0200) Subject: Allow a quickHead request, will only return headers X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0adb7af9a03a16fd45d900c5e15e8d386c454778;p=quix0rs-gnu-social.git Allow a quickHead request, will only return headers --- diff --git a/lib/httpclient.php b/lib/httpclient.php index 1e399bd83e..04a365274d 100644 --- a/lib/httpclient.php +++ b/lib/httpclient.php @@ -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. *