From 5c7ad2e031db651613ddbbdcff45900618f03978 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Thu, 22 Jan 2015 12:16:01 +0100 Subject: [PATCH] Added a quickGet in HTTPClient --- lib/httpclient.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/httpclient.php b/lib/httpclient.php index c7abe12116..960cd400f4 100644 --- a/lib/httpclient.php +++ b/lib/httpclient.php @@ -170,6 +170,21 @@ class HTTPClient extends HTTP_Request2 return new HTTPClient(); } + /** + * Quick static function to GET a URL + */ + public static function quickGet($url, $accept='text/html,application/xhtml+xml') + { + $client = new HTTPClient(); + $client->setHeader('Accept', $accept); + $response = $client->get($url); + if (!$response->isOk()) { + // TRANS: Exception. %s is a profile URL. + throw new Exception(sprintf(_m('Could not GET URL %s.'), $url), $response->getStatus()); + } + return $response->getBody(); + } + /** * Convenience function to run a GET request. * -- 2.39.2