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:
parent
be22886be8
commit
9fa18fa366
@ -173,7 +173,7 @@ class HTTPClient extends HTTP_Request2
|
|||||||
/**
|
/**
|
||||||
* Quick static function to GET a URL
|
* 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)) {
|
if (!empty($params)) {
|
||||||
$params = http_build_query($params, null, '&');
|
$params = http_build_query($params, null, '&');
|
||||||
@ -188,7 +188,7 @@ class HTTPClient extends HTTP_Request2
|
|||||||
if (!is_null($accept)) {
|
if (!is_null($accept)) {
|
||||||
$client->setHeader('Accept', $accept);
|
$client->setHeader('Accept', $accept);
|
||||||
}
|
}
|
||||||
$response = $client->get($url);
|
$response = $client->get($url, $headers);
|
||||||
if (!$response->isOk()) {
|
if (!$response->isOk()) {
|
||||||
// TRANS: Exception. %s is the URL we tried to GET.
|
// TRANS: Exception. %s is the URL we tried to GET.
|
||||||
throw new Exception(sprintf(_m('Could not GET URL %s.'), $url), $response->getStatus());
|
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
|
* @return GNUsocial_HTTPResponse
|
||||||
* @throws HTTP_Request2_Exception
|
* @throws HTTP_Request2_Exception
|
||||||
*/
|
*/
|
||||||
protected function doRequest($url, $method, $headers)
|
protected function doRequest($url, $method, array $headers=array())
|
||||||
{
|
{
|
||||||
$this->setUrl($url);
|
$this->setUrl($url);
|
||||||
|
|
||||||
@ -278,11 +284,9 @@ class HTTPClient extends HTTP_Request2
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->setMethod($method);
|
$this->setMethod($method);
|
||||||
if ($headers) {
|
|
||||||
foreach ($headers as $header) {
|
foreach ($headers as $header) {
|
||||||
$this->setHeader($header);
|
$this->setHeader($header);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$response = $this->send();
|
$response = $this->send();
|
||||||
if (is_null($response)) {
|
if (is_null($response)) {
|
||||||
// TRANS: Failed to retrieve a remote web resource, %s is the target URL.
|
// TRANS: Failed to retrieve a remote web resource, %s is the target URL.
|
||||||
|
Loading…
Reference in New Issue
Block a user