]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/httpclient.php
Merge remote-tracking branch 'upstream/nightly' into nightly
[quix0rs-gnu-social.git] / lib / httpclient.php
index 1e399bd83e9ead32b464cefaa7774ff7eef28c28..04a365274d3e5cf1bf778322f68923aacda09232 100644 (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.
      *