Use "HttpClientOptions"
This commit is contained in:
parent
1fae0123ec
commit
908d2594ed
5 changed files with 9 additions and 7 deletions
|
@ -26,6 +26,7 @@ use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Storage\Exception\ReferenceStorageException;
|
use Friendica\Core\Storage\Exception\ReferenceStorageException;
|
||||||
use Friendica\Core\Storage\Capability\ICanReadFromStorage;
|
use Friendica\Core\Storage\Capability\ICanReadFromStorage;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClient;
|
use Friendica\Network\HTTPClient\Client\HttpClient;
|
||||||
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,7 +55,7 @@ class ExternalResource implements ICanReadFromStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, ['accept_content' => [HttpClient::ACCEPT_IMAGE]]);
|
$fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, [HttpClientOptions::ACCEPT_CONTENT => [HttpClient::ACCEPT_IMAGE]]);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception);
|
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ use Friendica\Core\Logger;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClient;
|
use Friendica\Network\HTTPClient\Client\HttpClient;
|
||||||
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Network\HTTPException\NotModifiedException;
|
use Friendica\Network\HTTPException\NotModifiedException;
|
||||||
use Friendica\Object\Image;
|
use Friendica\Object\Image;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
|
@ -82,7 +83,7 @@ class Proxy extends BaseModule
|
||||||
$request['url'] = str_replace(' ', '+', $request['url']);
|
$request['url'] = str_replace(' ', '+', $request['url']);
|
||||||
|
|
||||||
// Fetch the content with the local user
|
// Fetch the content with the local user
|
||||||
$fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['accept_content' => [HttpClient::ACCEPT_IMAGE], 'timeout' => 10]);
|
$fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), [HttpClientOptions::ACCEPT_CONTENT => [HttpClient::ACCEPT_IMAGE], 'timeout' => 10]);
|
||||||
$img_str = $fetchResult->getBody();
|
$img_str = $fetchResult->getBody();
|
||||||
|
|
||||||
if (!$fetchResult->isSuccess() || empty($img_str)) {
|
if (!$fetchResult->isSuccess() || empty($img_str)) {
|
||||||
|
|
|
@ -267,9 +267,9 @@ class HttpClient implements ICanSendHttpRequests
|
||||||
return $this->get(
|
return $this->get(
|
||||||
$url,
|
$url,
|
||||||
[
|
[
|
||||||
'timeout' => $timeout,
|
HttpClientOptions::TIMEOUT => $timeout,
|
||||||
'accept_content' => $accept_content,
|
HttpClientOptions::ACCEPT_CONTENT => $accept_content,
|
||||||
'cookiejar' => $cookiejar
|
HttpClientOptions::COOKIEJAR => $cookiejar
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -932,7 +932,7 @@ class Probe
|
||||||
{
|
{
|
||||||
$xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
|
$xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
|
||||||
|
|
||||||
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => [$type]]);
|
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => $type]);
|
||||||
if ($curlResult->isTimeout()) {
|
if ($curlResult->isTimeout()) {
|
||||||
self::$istimeout = true;
|
self::$istimeout = true;
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -416,7 +416,7 @@ class HTTPSignature
|
||||||
* @return \Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses CurlResult
|
* @return \Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses CurlResult
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function fetchRaw($request, $uid = 0, $opts = ['accept_content' => [HttpClient::ACCEPT_JSON_AS]])
|
public static function fetchRaw($request, $uid = 0, $opts = [HttpClientOptions::ACCEPT_CONTENT => [HttpClient::ACCEPT_JSON_AS]])
|
||||||
{
|
{
|
||||||
$header = [];
|
$header = [];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue