HTTPClient::quickGet now supports headers as argument

They should be in a numeric array, already formatted as headers,
ready to go. (Header-Name: Content of the header)
This commit is contained in:
Mikael Nordfeldth 2016-03-24 02:44:11 +01:00
parent be22886be8
commit 9fa18fa366

View File

@ -173,7 +173,7 @@ class HTTPClient extends HTTP_Request2
/**
* Quick static function to GET a URL
*/
public static function quickGet($url, $accept=null, $params=array())
public static function quickGet($url, $accept=null, array $params=array(), array $headers=array())
{
if (!empty($params)) {
$params = http_build_query($params, null, '&');
@ -188,7 +188,7 @@ class HTTPClient extends HTTP_Request2
if (!is_null($accept)) {
$client->setHeader('Accept', $accept);
}
$response = $client->get($url);
$response = $client->get($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());
@ -262,10 +262,16 @@ class HTTPClient extends HTTP_Request2
}
/**
* @param string $url The URL including possible querystring
* @param string $method The HTTP method to use
* @param array $headers List of already formatted strings
* (not an associative array, to allow
* multiple same-named headers)
*
* @return GNUsocial_HTTPResponse
* @throws HTTP_Request2_Exception
*/
protected function doRequest($url, $method, $headers)
protected function doRequest($url, $method, array $headers=array())
{
$this->setUrl($url);
@ -278,10 +284,8 @@ class HTTPClient extends HTTP_Request2
}
$this->setMethod($method);
if ($headers) {
foreach ($headers as $header) {
$this->setHeader($header);
}
foreach ($headers as $header) {
$this->setHeader($header);
}
$response = $this->send();
if (is_null($response)) {