Rename HTTPRequestOptions to HTTPClientOptions
This commit is contained in:
parent
478f69c403
commit
505100bdd7
13 changed files with 50 additions and 50 deletions
|
@ -39,7 +39,7 @@ use Friendica\Model\Event;
|
|||
use Friendica\Model\Photo;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Tag;
|
||||
use Friendica\Network\HTTPRequestOptions;
|
||||
use Friendica\Network\HTTPClientOptions;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\Images;
|
||||
|
@ -1194,7 +1194,7 @@ class BBCode
|
|||
$text = DI::cache()->get($cache_key);
|
||||
|
||||
if (is_null($text)) {
|
||||
$curlResult = DI::httpRequest()->head($match[1], [HTTPRequestOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]);
|
||||
$curlResult = DI::httpRequest()->head($match[1], [HTTPClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]);
|
||||
if ($curlResult->isSuccess()) {
|
||||
$mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
|
||||
} else {
|
||||
|
@ -1265,7 +1265,7 @@ class BBCode
|
|||
return $text;
|
||||
}
|
||||
|
||||
$curlResult = DI::httpRequest()->head($match[1], [HTTPRequestOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]);
|
||||
$curlResult = DI::httpRequest()->head($match[1], [HTTPClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]);
|
||||
if ($curlResult->isSuccess()) {
|
||||
$mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
|
||||
} else {
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Core;
|
|||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPRequestOptions;
|
||||
use Friendica\Network\HTTPClientOptions;
|
||||
use Friendica\Object\Search\ContactResult;
|
||||
use Friendica\Object\Search\ResultList;
|
||||
use Friendica\Util\Network;
|
||||
|
@ -228,7 +228,7 @@ class Search
|
|||
$return = Contact::searchByName($search, $mode);
|
||||
} else {
|
||||
$p = $page > 1 ? 'p=' . $page : '';
|
||||
$curlResult = DI::httpRequest()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), [HTTPRequestOptions::ACCEPT_CONTENT => ['application/json']]);
|
||||
$curlResult = DI::httpRequest()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), [HTTPClientOptions::ACCEPT_CONTENT => ['application/json']]);
|
||||
if ($curlResult->isSuccess()) {
|
||||
$searchResult = json_decode($curlResult->getBody(), true);
|
||||
if (!empty($searchResult['profiles'])) {
|
||||
|
|
|
@ -32,7 +32,7 @@ use Friendica\Database\Database;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\Register;
|
||||
use Friendica\Network\HTTPRequestOptions;
|
||||
use Friendica\Network\HTTPClientOptions;
|
||||
use Friendica\Network\IHTTPResult;
|
||||
use Friendica\Protocol\Relay;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -315,7 +315,7 @@ class GServer
|
|||
|
||||
// When a nodeinfo is present, we don't need to dig further
|
||||
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
|
||||
$curlResult = DI::httpRequest()->get($url . '/.well-known/nodeinfo', [HTTPRequestOptions::TIMEOUT => $xrd_timeout]);
|
||||
$curlResult = DI::httpRequest()->get($url . '/.well-known/nodeinfo', [HTTPClientOptions::TIMEOUT => $xrd_timeout]);
|
||||
if ($curlResult->isTimeout()) {
|
||||
self::setFailure($url);
|
||||
return false;
|
||||
|
@ -323,7 +323,7 @@ class GServer
|
|||
|
||||
// On a redirect follow the new host but mark the old one as failure
|
||||
if ($curlResult->isSuccess() && (parse_url($url, PHP_URL_HOST) != parse_url($curlResult->getRedirectUrl(), PHP_URL_HOST))) {
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPRequestOptions::TIMEOUT => $xrd_timeout]);
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPClientOptions::TIMEOUT => $xrd_timeout]);
|
||||
if (parse_url($url, PHP_URL_HOST) != parse_url($curlResult->getRedirectUrl(), PHP_URL_HOST)) {
|
||||
Logger::info('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $curlResult->getRedirectUrl()]);
|
||||
self::setFailure($url);
|
||||
|
@ -359,7 +359,7 @@ class GServer
|
|||
$basedata = ['detection-method' => self::DETECT_MANUAL];
|
||||
}
|
||||
|
||||
$curlResult = DI::httpRequest()->get($baseurl, [HTTPRequestOptions::TIMEOUT => $xrd_timeout]);
|
||||
$curlResult = DI::httpRequest()->get($baseurl, [HTTPClientOptions::TIMEOUT => $xrd_timeout]);
|
||||
if ($curlResult->isSuccess()) {
|
||||
if ((parse_url($baseurl, PHP_URL_HOST) != parse_url($curlResult->getRedirectUrl(), PHP_URL_HOST))) {
|
||||
Logger::info('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $curlResult->getRedirectUrl()]);
|
||||
|
@ -383,7 +383,7 @@ class GServer
|
|||
// When the base path doesn't seem to contain a social network we try the complete path.
|
||||
// Most detectable system have to be installed in the root directory.
|
||||
// We checked the base to avoid false positives.
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPRequestOptions::TIMEOUT => $xrd_timeout]);
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPClientOptions::TIMEOUT => $xrd_timeout]);
|
||||
if ($curlResult->isSuccess()) {
|
||||
$urldata = self::analyseRootHeader($curlResult, $serverdata);
|
||||
$urldata = self::analyseRootBody($curlResult, $urldata, $url);
|
||||
|
@ -959,7 +959,7 @@ class GServer
|
|||
private static function validHostMeta(string $url)
|
||||
{
|
||||
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
|
||||
$curlResult = DI::httpRequest()->get($url . '/.well-known/host-meta', [HTTPRequestOptions::TIMEOUT => $xrd_timeout]);
|
||||
$curlResult = DI::httpRequest()->get($url . '/.well-known/host-meta', [HTTPClientOptions::TIMEOUT => $xrd_timeout]);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1729,7 +1729,7 @@ class GServer
|
|||
|
||||
if (!empty($accesstoken)) {
|
||||
$api = 'https://instances.social/api/1.0/instances/list?count=0';
|
||||
$curlResult = DI::httpRequest()->get($api, [HTTPRequestOptions::HEADERS => ['Authorization' => ['Bearer ' . $accesstoken]]]);
|
||||
$curlResult = DI::httpRequest()->get($api, [HTTPClientOptions::HEADERS => ['Authorization' => ['Bearer ' . $accesstoken]]]);
|
||||
|
||||
if ($curlResult->isSuccess()) {
|
||||
$servers = json_decode($curlResult->getBody(), true);
|
||||
|
|
|
@ -26,7 +26,7 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPRequestOptions;
|
||||
use Friendica\Network\HTTPClientOptions;
|
||||
use Friendica\Util\Proxy;
|
||||
|
||||
/**
|
||||
|
@ -88,7 +88,7 @@ class Link
|
|||
{
|
||||
$timeout = DI::config()->get('system', 'xrd_timeout');
|
||||
|
||||
$curlResult = DI::httpRequest()->head($url, [HTTPRequestOptions::TIMEOUT => $timeout]);
|
||||
$curlResult = DI::httpRequest()->head($url, [HTTPClientOptions::TIMEOUT => $timeout]);
|
||||
if ($curlResult->isSuccess()) {
|
||||
if (empty($media['mimetype'])) {
|
||||
return $curlResult->getHeader('Content-Type')[0] ?? '';
|
||||
|
|
|
@ -30,7 +30,7 @@ use Friendica\DI;
|
|||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Network\HTTPRequestOptions;
|
||||
use Friendica\Network\HTTPClientOptions;
|
||||
use Friendica\Util\Images;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\ParseUrl;
|
||||
|
@ -168,7 +168,7 @@ class Media
|
|||
// Fetch the mimetype or size if missing.
|
||||
if (empty($media['mimetype']) || empty($media['size'])) {
|
||||
$timeout = DI::config()->get('system', 'xrd_timeout');
|
||||
$curlResult = DI::httpRequest()->head($media['url'], [HTTPRequestOptions::TIMEOUT => $timeout]);
|
||||
$curlResult = DI::httpRequest()->head($media['url'], [HTTPClientOptions::TIMEOUT => $timeout]);
|
||||
if ($curlResult->isSuccess()) {
|
||||
if (empty($media['mimetype'])) {
|
||||
$media['mimetype'] = $curlResult->getHeader('Content-Type')[0] ?? '';
|
||||
|
|
|
@ -28,7 +28,7 @@ use Friendica\Database\DBA;
|
|||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\HTTPRequestOptions;
|
||||
use Friendica\Network\HTTPClientOptions;
|
||||
use Friendica\Util\HTTPSignature;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
|
@ -102,7 +102,7 @@ class Magic extends BaseModule
|
|||
);
|
||||
|
||||
// Try to get an authentication token from the other instance.
|
||||
$curlResult = DI::httpRequest()->get($basepath . '/owa', [HTTPRequestOptions::HEADERS => $header]);
|
||||
$curlResult = DI::httpRequest()->get($basepath . '/owa', [HTTPClientOptions::HEADERS => $header]);
|
||||
|
||||
if ($curlResult->isSuccess()) {
|
||||
$j = json_decode($curlResult->getBody(), true);
|
||||
|
|
|
@ -95,39 +95,39 @@ class HTTPClient implements IHTTPClient
|
|||
|
||||
$conf = [];
|
||||
|
||||
if (!empty($opts[HTTPRequestOptions::COOKIEJAR])) {
|
||||
$jar = new FileCookieJar($opts[HTTPRequestOptions::COOKIEJAR]);
|
||||
if (!empty($opts[HTTPClientOptions::COOKIEJAR])) {
|
||||
$jar = new FileCookieJar($opts[HTTPClientOptions::COOKIEJAR]);
|
||||
$conf[RequestOptions::COOKIES] = $jar;
|
||||
}
|
||||
|
||||
$headers = [];
|
||||
|
||||
if (!empty($opts[HTTPRequestOptions::ACCEPT_CONTENT])) {
|
||||
$headers['Accept'] = $opts[HTTPRequestOptions::ACCEPT_CONTENT];
|
||||
if (!empty($opts[HTTPClientOptions::ACCEPT_CONTENT])) {
|
||||
$headers['Accept'] = $opts[HTTPClientOptions::ACCEPT_CONTENT];
|
||||
}
|
||||
|
||||
if (!empty($opts[HTTPRequestOptions::LEGACY_HEADER])) {
|
||||
if (!empty($opts[HTTPClientOptions::LEGACY_HEADER])) {
|
||||
$this->logger->notice('Wrong option \'headers\' used.');
|
||||
$headers = array_merge($opts[HTTPRequestOptions::LEGACY_HEADER], $headers);
|
||||
$headers = array_merge($opts[HTTPClientOptions::LEGACY_HEADER], $headers);
|
||||
}
|
||||
|
||||
if (!empty($opts[HTTPRequestOptions::HEADERS])) {
|
||||
$headers = array_merge($opts[HTTPRequestOptions::HEADERS], $headers);
|
||||
if (!empty($opts[HTTPClientOptions::HEADERS])) {
|
||||
$headers = array_merge($opts[HTTPClientOptions::HEADERS], $headers);
|
||||
}
|
||||
|
||||
$conf[RequestOptions::HEADERS] = array_merge($this->client->getConfig(RequestOptions::HEADERS), $headers);
|
||||
|
||||
if (!empty($opts[HTTPRequestOptions::TIMEOUT])) {
|
||||
$conf[RequestOptions::TIMEOUT] = $opts[HTTPRequestOptions::TIMEOUT];
|
||||
if (!empty($opts[HTTPClientOptions::TIMEOUT])) {
|
||||
$conf[RequestOptions::TIMEOUT] = $opts[HTTPClientOptions::TIMEOUT];
|
||||
}
|
||||
|
||||
if (!empty($opts[HTTPRequestOptions::BODY])) {
|
||||
$conf[RequestOptions::BODY] = $opts[HTTPRequestOptions::BODY];
|
||||
if (!empty($opts[HTTPClientOptions::BODY])) {
|
||||
$conf[RequestOptions::BODY] = $opts[HTTPClientOptions::BODY];
|
||||
}
|
||||
|
||||
$conf[RequestOptions::ON_HEADERS] = function (ResponseInterface $response) use ($opts) {
|
||||
if (!empty($opts[HTTPRequestOptions::CONTENT_LENGTH]) &&
|
||||
(int)$response->getHeaderLine('Content-Length') > $opts[HTTPRequestOptions::CONTENT_LENGTH]) {
|
||||
if (!empty($opts[HTTPClientOptions::CONTENT_LENGTH]) &&
|
||||
(int)$response->getHeaderLine('Content-Length') > $opts[HTTPClientOptions::CONTENT_LENGTH]) {
|
||||
throw new TransferException('The file is too big!');
|
||||
}
|
||||
};
|
||||
|
@ -185,14 +185,14 @@ class HTTPClient implements IHTTPClient
|
|||
{
|
||||
$opts = [];
|
||||
|
||||
$opts[HTTPRequestOptions::BODY] = $params;
|
||||
$opts[HTTPClientOptions::BODY] = $params;
|
||||
|
||||
if (!empty($headers)) {
|
||||
$opts[HTTPRequestOptions::HEADERS] = $headers;
|
||||
$opts[HTTPClientOptions::HEADERS] = $headers;
|
||||
}
|
||||
|
||||
if (!empty($timeout)) {
|
||||
$opts[HTTPRequestOptions::TIMEOUT] = $timeout;
|
||||
$opts[HTTPClientOptions::TIMEOUT] = $timeout;
|
||||
}
|
||||
|
||||
return $this->request('post', $url, $opts);
|
||||
|
|
|
@ -7,7 +7,7 @@ use GuzzleHttp\RequestOptions;
|
|||
/**
|
||||
* This class contains a list of possible HTTPClient request options.
|
||||
*/
|
||||
class HTTPRequestOptions
|
||||
class HTTPClientOptions
|
||||
{
|
||||
/**
|
||||
* accept_content: (array) supply Accept: header with 'accept_content' as the value
|
|
@ -170,7 +170,7 @@ class Probe
|
|||
Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url, 'callstack' => System::callstack(20)]);
|
||||
$xrd = null;
|
||||
|
||||
$curlResult = DI::httpRequest()->get($ssl_url, [HTTPRequestOptions::TIMEOUT => $xrd_timeout, HTTPRequestOptions::ACCEPT_CONTENT => ['application/xrd+xml']]);
|
||||
$curlResult = DI::httpRequest()->get($ssl_url, [HTTPClientOptions::TIMEOUT => $xrd_timeout, HTTPClientOptions::ACCEPT_CONTENT => ['application/xrd+xml']]);
|
||||
$ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
|
||||
if ($curlResult->isSuccess()) {
|
||||
$xml = $curlResult->getBody();
|
||||
|
@ -187,7 +187,7 @@ class Probe
|
|||
}
|
||||
|
||||
if (!is_object($xrd) && !empty($url)) {
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPRequestOptions::TIMEOUT => $xrd_timeout, HTTPRequestOptions::ACCEPT_CONTENT => ['application/xrd+xml']]);
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPClientOptions::TIMEOUT => $xrd_timeout, HTTPClientOptions::ACCEPT_CONTENT => ['application/xrd+xml']]);
|
||||
$connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
|
||||
if ($curlResult->isTimeout()) {
|
||||
Logger::info('Probing timeout', ['url' => $url]);
|
||||
|
@ -424,7 +424,7 @@ class Probe
|
|||
*/
|
||||
private static function getHideStatus($url)
|
||||
{
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPRequestOptions::CONTENT_LENGTH => 1000000]);
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPClientOptions::CONTENT_LENGTH => 1000000]);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -940,7 +940,7 @@ class Probe
|
|||
{
|
||||
$xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
|
||||
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPRequestOptions::TIMEOUT => $xrd_timeout, HTTPRequestOptions::ACCEPT_CONTENT => [$type]]);
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPClientOptions::TIMEOUT => $xrd_timeout, HTTPClientOptions::ACCEPT_CONTENT => [$type]]);
|
||||
if ($curlResult->isTimeout()) {
|
||||
self::$istimeout = true;
|
||||
return [];
|
||||
|
|
|
@ -38,7 +38,7 @@ use Friendica\Model\ItemURI;
|
|||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Tag;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\HTTPRequestOptions;
|
||||
use Friendica\Network\HTTPClientOptions;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Images;
|
||||
|
@ -728,7 +728,7 @@ class OStatus
|
|||
|
||||
self::$conv_list[$conversation] = true;
|
||||
|
||||
$curlResult = DI::httpRequest()->get($conversation, [HTTPRequestOptions::ACCEPT_CONTENT => ['application/atom+xml', 'text/html']]);
|
||||
$curlResult = DI::httpRequest()->get($conversation, [HTTPClientOptions::ACCEPT_CONTENT => ['application/atom+xml', 'text/html']]);
|
||||
|
||||
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
|
||||
return;
|
||||
|
@ -922,7 +922,7 @@ class OStatus
|
|||
}
|
||||
|
||||
$stored = false;
|
||||
$curlResult = DI::httpRequest()->get($related, [HTTPRequestOptions::ACCEPT_CONTENT => ['application/atom+xml', 'text/html']]);
|
||||
$curlResult = DI::httpRequest()->get($related, [HTTPClientOptions::ACCEPT_CONTENT => ['application/atom+xml', 'text/html']]);
|
||||
|
||||
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
|
||||
return;
|
||||
|
|
|
@ -29,7 +29,7 @@ use Friendica\Model\APContact;
|
|||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\CurlResult;
|
||||
use Friendica\Network\HTTPRequestOptions;
|
||||
use Friendica\Network\HTTPClientOptions;
|
||||
use Friendica\Network\IHTTPResult;
|
||||
|
||||
/**
|
||||
|
@ -449,8 +449,8 @@ class HTTPSignature
|
|||
$header['Signature'] = 'keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) date host",signature="' . $signature . '"';
|
||||
}
|
||||
|
||||
$curl_opts = $opts;
|
||||
$curl_opts[HTTPRequestOptions::HEADERS] = $header;
|
||||
$curl_opts = $opts;
|
||||
$curl_opts[HTTPClientOptions::HEADERS] = $header;
|
||||
|
||||
if (!empty($opts['nobody'])) {
|
||||
$curlResult = DI::httpRequest()->head($request, $curl_opts);
|
||||
|
|
|
@ -30,7 +30,7 @@ use Friendica\Database\Database;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPRequestOptions;
|
||||
use Friendica\Network\HTTPClientOptions;
|
||||
|
||||
/**
|
||||
* Get information about a given URL
|
||||
|
@ -214,7 +214,7 @@ class ParseUrl
|
|||
return $siteinfo;
|
||||
}
|
||||
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPRequestOptions::CONTENT_LENGTH => 1000000]);
|
||||
$curlResult = DI::httpRequest()->get($url, [HTTPClientOptions::CONTENT_LENGTH => 1000000]);
|
||||
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
|
||||
return $siteinfo;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ use Friendica\Model\Contact;
|
|||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\HTTPRequestOptions;
|
||||
use Friendica\Network\HTTPClientOptions;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Protocol\Email;
|
||||
|
@ -153,7 +153,7 @@ class OnePoll
|
|||
}
|
||||
|
||||
$cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-');
|
||||
$curlResult = DI::httpRequest()->get($contact['poll'], [HTTPRequestOptions::COOKIEJAR => $cookiejar]);
|
||||
$curlResult = DI::httpRequest()->get($contact['poll'], [HTTPClientOptions::COOKIEJAR => $cookiejar]);
|
||||
unlink($cookiejar);
|
||||
|
||||
if ($curlResult->isTimeout()) {
|
||||
|
|
Loading…
Reference in a new issue