From 409d909d0f52395eae4bebf7960c368efed3865f Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 23 Oct 2021 12:50:31 +0200 Subject: [PATCH] Restructure HTTPClient for new paradigm --- src/Content/Text/BBCode.php | 6 +- src/Core/Search.php | 4 +- src/DI.php | 4 +- src/Model/GServer.php | 22 +++--- src/Model/Post/Link.php | 4 +- src/Model/Post/Media.php | 4 +- src/Module/Magic.php | 4 +- .../Capability/ICanHandleHttpResponses.php} | 9 +-- .../Capability/ICanRequestPerHttp.php} | 30 ++++---- .../Client/HttpClientCan.php} | 61 ++++++++-------- .../Client/HttpClientOptions.php} | 4 +- .../HTTPClient/Factory/HttpClient.php} | 28 ++++---- .../{ => HTTPClient/Response}/CurlResult.php | 71 ++++++++++--------- .../Response}/GuzzleResponse.php | 34 +++++---- src/Network/Probe.php | 9 +-- src/Protocol/OStatus.php | 6 +- src/Util/HTTPSignature.php | 10 +-- src/Util/ParseUrl.php | 4 +- src/Worker/OnePoll.php | 4 +- static/dependencies.config.php | 4 +- tests/DiceHttpMockHandlerTrait.php | 8 +-- tests/src/Core/InstallerTest.php | 18 ++--- .../Storage/Repository/StorageManagerTest.php | 6 +- .../Client}/HTTPClientTest.php | 2 +- .../Response}/CurlResultTest.php | 52 +++++++------- 25 files changed, 210 insertions(+), 198 deletions(-) rename src/Network/{IHTTPResult.php => HTTPClient/Capability/ICanHandleHttpResponses.php} (90%) rename src/Network/{IHTTPClient.php => HTTPClient/Capability/ICanRequestPerHttp.php} (85%) rename src/Network/{HTTPClient.php => HTTPClient/Client/HttpClientCan.php} (76%) rename src/Network/{HTTPClientOptions.php => HTTPClient/Client/HttpClientOptions.php} (93%) rename src/{Factory/HTTPClientFactory.php => Network/HTTPClient/Factory/HttpClient.php} (83%) rename src/Network/{ => HTTPClient/Response}/CurlResult.php (79%) rename src/Network/{ => HTTPClient/Response}/GuzzleResponse.php (81%) rename tests/src/Network/{ => HTTPClient/Client}/HTTPClientTest.php (92%) rename tests/src/Network/{ => HTTPClient/Response}/CurlResultTest.php (70%) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index da95c3d67..ecaf34527 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -39,7 +39,7 @@ use Friendica\Model\Event; use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Model\Tag; -use Friendica\Network\HTTPClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Object\Image; use Friendica\Protocol\Activity; use Friendica\Util\Images; @@ -1201,7 +1201,7 @@ class BBCode $text = DI::cache()->get($cache_key); if (is_null($text)) { - $curlResult = DI::httpClient()->head($match[1], [HTTPClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); + $curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); if ($curlResult->isSuccess()) { $mimetype = $curlResult->getHeader('Content-Type')[0] ?? ''; } else { @@ -1272,7 +1272,7 @@ class BBCode return $text; } - $curlResult = DI::httpClient()->head($match[1], [HTTPClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); + $curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); if ($curlResult->isSuccess()) { $mimetype = $curlResult->getHeader('Content-Type')[0] ?? ''; } else { diff --git a/src/Core/Search.php b/src/Core/Search.php index ff4abdfac..82c0ea3d3 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -24,7 +24,7 @@ namespace Friendica\Core; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Network\HTTPException; -use Friendica\Network\HTTPClientOptions; +use Friendica\Network\HTTPClient\Client\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::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), [HTTPClientOptions::ACCEPT_CONTENT => ['application/json']]); + $curlResult = DI::httpClient()->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'])) { diff --git a/src/DI.php b/src/DI.php index 8ee700440..ecc65bbc9 100644 --- a/src/DI.php +++ b/src/DI.php @@ -415,11 +415,11 @@ abstract class DI // /** - * @return Network\IHTTPClient + * @return Network\HTTPClient\Capability\ICanRequestPerHttp */ public static function httpClient() { - return self::$dice->create(Network\IHTTPClient::class); + return self::$dice->create(Network\HTTPClient\Capability\ICanRequestPerHttp::class); } // diff --git a/src/Model/GServer.php b/src/Model/GServer.php index 7c5a2b98a..c56e7701e 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -32,8 +32,8 @@ use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module\Register; -use Friendica\Network\HTTPClientOptions; -use Friendica\Network\IHTTPResult; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; use Friendica\Protocol\Relay; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -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::httpClient()->get($url . '/.well-known/nodeinfo', [HTTPClientOptions::TIMEOUT => $xrd_timeout]); + $curlResult = DI::httpClient()->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::httpClient()->get($url, [HTTPClientOptions::TIMEOUT => $xrd_timeout]); + $curlResult = DI::httpClient()->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::httpClient()->get($baseurl, [HTTPClientOptions::TIMEOUT => $xrd_timeout]); + $curlResult = DI::httpClient()->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::httpClient()->get($url, [HTTPClientOptions::TIMEOUT => $xrd_timeout]); + $curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout]); if ($curlResult->isSuccess()) { $urldata = self::analyseRootHeader($curlResult, $serverdata); $urldata = self::analyseRootBody($curlResult, $urldata, $url); @@ -672,13 +672,13 @@ class GServer /** * Detect server type by using the nodeinfo data * - * @param string $url address of the server - * @param IHTTPResult $httpResult + * @param string $url address of the server + * @param ICanHandleHttpResponses $httpResult * * @return array Server data * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - private static function fetchNodeinfo(string $url, IHTTPResult $httpResult) + private static function fetchNodeinfo(string $url, ICanHandleHttpResponses $httpResult) { if (!$httpResult->isSuccess()) { return []; @@ -959,7 +959,7 @@ class GServer private static function validHostMeta(string $url) { $xrd_timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = DI::httpClient()->get($url . '/.well-known/host-meta', [HTTPClientOptions::TIMEOUT => $xrd_timeout]); + $curlResult = DI::httpClient()->get($url . '/.well-known/host-meta', [HttpClientOptions::TIMEOUT => $xrd_timeout]); if (!$curlResult->isSuccess()) { return false; } @@ -1725,7 +1725,7 @@ class GServer if (!empty($accesstoken)) { $api = 'https://instances.social/api/1.0/instances/list?count=0'; - $curlResult = DI::httpClient()->get($api, [HTTPClientOptions::HEADERS => ['Authorization' => ['Bearer ' . $accesstoken]]]); + $curlResult = DI::httpClient()->get($api, [HttpClientOptions::HEADERS => ['Authorization' => ['Bearer ' . $accesstoken]]]); if ($curlResult->isSuccess()) { $servers = json_decode($curlResult->getBody(), true); diff --git a/src/Model/Post/Link.php b/src/Model/Post/Link.php index dcda036ec..50ed12a36 100644 --- a/src/Model/Post/Link.php +++ b/src/Model/Post/Link.php @@ -26,7 +26,7 @@ use Friendica\Core\System; use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Network\HTTPClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Util\Proxy; /** @@ -100,7 +100,7 @@ class Link { $timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = DI::httpClient()->head($url, [HTTPClientOptions::TIMEOUT => $timeout]); + $curlResult = DI::httpClient()->head($url, [HttpClientOptions::TIMEOUT => $timeout]); if ($curlResult->isSuccess()) { if (empty($media['mimetype'])) { return $curlResult->getHeader('Content-Type')[0] ?? ''; diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index b42ba89cf..6fe996d76 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -30,7 +30,7 @@ use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Photo; use Friendica\Model\Post; -use Friendica\Network\HTTPClientOptions; +use Friendica\Network\HTTPClient\Client\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::httpClient()->head($media['url'], [HTTPClientOptions::TIMEOUT => $timeout]); + $curlResult = DI::httpClient()->head($media['url'], [HttpClientOptions::TIMEOUT => $timeout]); if ($curlResult->isSuccess()) { if (empty($media['mimetype'])) { $media['mimetype'] = $curlResult->getHeader('Content-Type')[0] ?? ''; diff --git a/src/Module/Magic.php b/src/Module/Magic.php index d508835b0..c51c05844 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -28,7 +28,7 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\User; -use Friendica\Network\HTTPClientOptions; +use Friendica\Network\HTTPClient\Client\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::httpClient()->get($basepath . '/owa', [HTTPClientOptions::HEADERS => $header]); + $curlResult = DI::httpClient()->get($basepath . '/owa', [HttpClientOptions::HEADERS => $header]); if ($curlResult->isSuccess()) { $j = json_decode($curlResult->getBody(), true); diff --git a/src/Network/IHTTPResult.php b/src/Network/HTTPClient/Capability/ICanHandleHttpResponses.php similarity index 90% rename from src/Network/IHTTPResult.php rename to src/Network/HTTPClient/Capability/ICanHandleHttpResponses.php index 38a117628..b0ad0a968 100644 --- a/src/Network/IHTTPResult.php +++ b/src/Network/HTTPClient/Capability/ICanHandleHttpResponses.php @@ -1,13 +1,13 @@ path to cookie jar file * 'header' => header array * - * @return CurlResult + * @return ICanHandleHttpResponses */ - public function head(string $url, array $opts = []); + public function head(string $url, array $opts = []): ICanHandleHttpResponses; /** * Send a GET to an URL. @@ -83,9 +83,9 @@ interface IHTTPClient * 'header' => header array * 'content_length' => int maximum File content length * - * @return IHTTPResult + * @return ICanHandleHttpResponses */ - public function get(string $url, array $opts = []); + public function get(string $url, array $opts = []): ICanHandleHttpResponses; /** * Sends a HTTP request to a given url @@ -101,9 +101,9 @@ interface IHTTPClient * 'content_length' => int maximum File content length * 'auth' => array authentication settings * - * @return IHTTPResult + * @return ICanHandleHttpResponses */ - public function request(string $method, string $url, array $opts = []); + public function request(string $method, string $url, array $opts = []): ICanHandleHttpResponses; /** * Send POST request to an URL @@ -113,9 +113,9 @@ interface IHTTPClient * @param array $headers HTTP headers * @param int $timeout The timeout in seconds, default system config value or 60 seconds * - * @return IHTTPResult The content + * @return ICanHandleHttpResponses The content */ - public function post(string $url, $params, array $headers = [], int $timeout = 0); + public function post(string $url, $params, array $headers = [], int $timeout = 0): ICanHandleHttpResponses; /** * Returns the original URL of the provided URL @@ -129,5 +129,5 @@ interface IHTTPClient * * @throws TransferException In case there's an error during the resolving */ - public function finalUrl(string $url); + public function finalUrl(string $url): string; } diff --git a/src/Network/HTTPClient.php b/src/Network/HTTPClient/Client/HttpClientCan.php similarity index 76% rename from src/Network/HTTPClient.php rename to src/Network/HTTPClient/Client/HttpClientCan.php index 004af57f9..ea07a5c83 100644 --- a/src/Network/HTTPClient.php +++ b/src/Network/HTTPClient/Client/HttpClientCan.php @@ -19,9 +19,14 @@ * */ -namespace Friendica\Network; +namespace Friendica\Network\HTTPClient\Client; use Friendica\Core\System; +use Friendica\Network\HTTPClient\Response\CurlResult; +use Friendica\Network\HTTPClient\Response\GuzzleResponse; +use Friendica\Network\HTTPClient\Capability\ICanRequestPerHttp; +use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; +use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\Network; use Friendica\Util\Profiler; use GuzzleHttp\Client; @@ -37,7 +42,7 @@ use Psr\Log\LoggerInterface; /** * Performs HTTP requests to a given URL */ -class HTTPClient implements IHTTPClient +class HttpClientCan implements ICanRequestPerHttp { /** @var LoggerInterface */ private $logger; @@ -59,7 +64,7 @@ class HTTPClient implements IHTTPClient /** * {@inheritDoc} */ - public function request(string $method, string $url, array $opts = []): IHTTPResult + public function request(string $method, string $url, array $opts = []): ICanHandleHttpResponses { $this->profiler->startRecording('network'); $this->logger->debug('Request start.', ['url' => $url, 'method' => $method]); @@ -95,43 +100,43 @@ class HTTPClient implements IHTTPClient $conf = []; - if (!empty($opts[HTTPClientOptions::COOKIEJAR])) { - $jar = new FileCookieJar($opts[HTTPClientOptions::COOKIEJAR]); + if (!empty($opts[HttpClientOptions::COOKIEJAR])) { + $jar = new FileCookieJar($opts[HttpClientOptions::COOKIEJAR]); $conf[RequestOptions::COOKIES] = $jar; } $headers = []; - if (!empty($opts[HTTPClientOptions::ACCEPT_CONTENT])) { - $headers['Accept'] = $opts[HTTPClientOptions::ACCEPT_CONTENT]; + if (!empty($opts[HttpClientOptions::ACCEPT_CONTENT])) { + $headers['Accept'] = $opts[HttpClientOptions::ACCEPT_CONTENT]; } - if (!empty($opts[HTTPClientOptions::LEGACY_HEADER])) { + if (!empty($opts[HttpClientOptions::LEGACY_HEADER])) { $this->logger->notice('Wrong option \'headers\' used.'); - $headers = array_merge($opts[HTTPClientOptions::LEGACY_HEADER], $headers); + $headers = array_merge($opts[HttpClientOptions::LEGACY_HEADER], $headers); } - if (!empty($opts[HTTPClientOptions::HEADERS])) { - $headers = array_merge($opts[HTTPClientOptions::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[HTTPClientOptions::TIMEOUT])) { - $conf[RequestOptions::TIMEOUT] = $opts[HTTPClientOptions::TIMEOUT]; + if (!empty($opts[HttpClientOptions::TIMEOUT])) { + $conf[RequestOptions::TIMEOUT] = $opts[HttpClientOptions::TIMEOUT]; } - if (!empty($opts[HTTPClientOptions::BODY])) { - $conf[RequestOptions::BODY] = $opts[HTTPClientOptions::BODY]; + if (!empty($opts[HttpClientOptions::BODY])) { + $conf[RequestOptions::BODY] = $opts[HttpClientOptions::BODY]; } - if (!empty($opts[HTTPClientOptions::AUTH])) { - $conf[RequestOptions::AUTH] = $opts[HTTPClientOptions::AUTH]; + if (!empty($opts[HttpClientOptions::AUTH])) { + $conf[RequestOptions::AUTH] = $opts[HttpClientOptions::AUTH]; } $conf[RequestOptions::ON_HEADERS] = function (ResponseInterface $response) use ($opts) { - if (!empty($opts[HTTPClientOptions::CONTENT_LENGTH]) && - (int)$response->getHeaderLine('Content-Length') > $opts[HTTPClientOptions::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!'); } }; @@ -159,7 +164,7 @@ class HTTPClient implements IHTTPClient /** {@inheritDoc} */ - public function head(string $url, array $opts = []): IHTTPResult + public function head(string $url, array $opts = []): ICanHandleHttpResponses { return $this->request('head', $url, $opts); } @@ -167,7 +172,7 @@ class HTTPClient implements IHTTPClient /** * {@inheritDoc} */ - public function get(string $url, array $opts = []): IHTTPResult + public function get(string $url, array $opts = []): ICanHandleHttpResponses { return $this->request('get', $url, $opts); } @@ -175,18 +180,18 @@ class HTTPClient implements IHTTPClient /** * {@inheritDoc} */ - public function post(string $url, $params, array $headers = [], int $timeout = 0): IHTTPResult + public function post(string $url, $params, array $headers = [], int $timeout = 0): ICanHandleHttpResponses { $opts = []; - $opts[HTTPClientOptions::BODY] = $params; + $opts[HttpClientOptions::BODY] = $params; if (!empty($headers)) { - $opts[HTTPClientOptions::HEADERS] = $headers; + $opts[HttpClientOptions::HEADERS] = $headers; } if (!empty($timeout)) { - $opts[HTTPClientOptions::TIMEOUT] = $timeout; + $opts[HttpClientOptions::TIMEOUT] = $timeout; } return $this->request('post', $url, $opts); @@ -195,7 +200,7 @@ class HTTPClient implements IHTTPClient /** * {@inheritDoc} */ - public function finalUrl(string $url) + public function finalUrl(string $url): string { $this->profiler->startRecording('network'); @@ -229,7 +234,7 @@ class HTTPClient implements IHTTPClient /** * {@inheritDoc} */ - public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '') + public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = ''): string { $ret = $this->fetchFull($url, $timeout, $accept_content, $cookiejar); @@ -239,7 +244,7 @@ class HTTPClient implements IHTTPClient /** * {@inheritDoc} */ - public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '') + public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = ''): ICanHandleHttpResponses { return $this->get( $url, diff --git a/src/Network/HTTPClientOptions.php b/src/Network/HTTPClient/Client/HttpClientOptions.php similarity index 93% rename from src/Network/HTTPClientOptions.php rename to src/Network/HTTPClient/Client/HttpClientOptions.php index f9438fb47..fa684c763 100644 --- a/src/Network/HTTPClientOptions.php +++ b/src/Network/HTTPClient/Client/HttpClientOptions.php @@ -1,13 +1,13 @@ config->get('system', 'proxy'); if (!empty($proxy)) { - $proxyuser = $this->config->get('system', 'proxyuser'); + $proxyUser = $this->config->get('system', 'proxyuser'); - if (!empty($proxyuser)) { - $proxy = $proxyuser . '@' . $proxy; + if (!empty($proxyUser)) { + $proxy = $proxyUser . '@' . $proxy; } } @@ -72,7 +72,7 @@ class HTTPClientFactory extends BaseFactory DB_UPDATE_VERSION . '; ' . $this->baseUrl->get(); - $guzzle = new Client([ + $guzzle = new GuzzleHttp\Client([ RequestOptions::ALLOW_REDIRECTS => [ 'max' => 8, 'on_redirect' => $onRedirect, @@ -88,7 +88,7 @@ class HTTPClientFactory extends BaseFactory RequestOptions::FORCE_IP_RESOLVE => ($this->config->get('system', 'ipv4_resolve') ? 'v4' : null), RequestOptions::CONNECT_TIMEOUT => 10, RequestOptions::TIMEOUT => $this->config->get('system', 'curl_timeout', 60), - // by default we will allow self-signed certs + // by default, we will allow self-signed certs, // but it can be overridden RequestOptions::VERIFY => (bool)$this->config->get('system', 'verifyssl'), RequestOptions::PROXY => $proxy, @@ -108,6 +108,6 @@ class HTTPClientFactory extends BaseFactory // Some websites test the browser for cookie support, so this enhances results. $resolver->setCookieJar(get_temppath() .'/resolver-cookie-' . Strings::getRandomName(10)); - return new HTTPClient($logger, $this->profiler, $guzzle, $resolver); + return new Client\HttpClientCan($logger, $this->profiler, $guzzle, $resolver); } } diff --git a/src/Network/CurlResult.php b/src/Network/HTTPClient/Response/CurlResult.php similarity index 79% rename from src/Network/CurlResult.php rename to src/Network/HTTPClient/Response/CurlResult.php index 8b3b12876..adff9b8dc 100644 --- a/src/Network/CurlResult.php +++ b/src/Network/HTTPClient/Response/CurlResult.php @@ -19,17 +19,17 @@ * */ -namespace Friendica\Network; +namespace Friendica\Network\HTTPClient\Response; use Friendica\Core\Logger; -use Friendica\Core\System; +use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\Network; /** * A content class for Curl call results */ -class CurlResult implements IHTTPResult +class CurlResult implements ICanHandleHttpResponses { /** * @var int HTTP return code or 0 if timeout or failure @@ -101,35 +101,36 @@ class CurlResult implements IHTTPResult * * @param string $url optional URL * - * @return IHTTPResult a CURL with error response + * @return ICanHandleHttpResponses a CURL with error response * @throws InternalServerErrorException */ - public static function createErrorCurl($url = '') + public static function createErrorCurl(string $url = '') { return new CurlResult($url, '', ['http_code' => 0]); } /** * Curl constructor. - * @param string $url the URL which was called - * @param string $result the result of the curl execution - * @param array $info an additional info array - * @param int $errorNumber the error number or 0 (zero) if no error - * @param string $error the error message or '' (the empty string) if no + * + * @param string $url the URL which was called + * @param string $result the result of the curl execution + * @param array $info an additional info array + * @param int $errorNumber the error number or 0 (zero) if no error + * @param string $error the error message or '' (the empty string) if no * * @throws InternalServerErrorException when HTTP code of the CURL response is missing */ - public function __construct($url, $result, $info, $errorNumber = 0, $error = '') + public function __construct(string $url, string $result, array $info, int $errorNumber = 0, string $error = '') { if (!array_key_exists('http_code', $info)) { throw new InternalServerErrorException('CURL response doesn\'t contains a response HTTP code'); } - $this->returnCode = $info['http_code']; - $this->url = $url; - $this->info = $info; + $this->returnCode = $info['http_code']; + $this->url = $url; + $this->info = $info; $this->errorNumber = $errorNumber; - $this->error = $error; + $this->error = $error; Logger::debug('construct', ['url' => $url, 'returncode' => $this->returnCode, 'result' => $result]); @@ -145,15 +146,15 @@ class CurlResult implements IHTTPResult // allow for HTTP/2.x without fixing code $header = ''; - $base = $result; + $base = $result; while (preg_match('/^HTTP\/.+? \d+/', $base)) { $chunk = substr($base, 0, strpos($base, "\r\n\r\n") + 4); $header .= $chunk; $base = substr($base, strlen($chunk)); } - $this->body = substr($result, strlen($header)); - $this->header = $header; + $this->body = substr($result, strlen($header)); + $this->header = $header; $this->header_fields = []; // Is filled on demand } @@ -185,7 +186,7 @@ class CurlResult implements IHTTPResult $this->redirectUrl = $this->info['url']; } - if ($this->returnCode == 301 || $this->returnCode == 302 || $this->returnCode == 303 || $this->returnCode== 307) { + if ($this->returnCode == 301 || $this->returnCode == 302 || $this->returnCode == 303 || $this->returnCode == 307) { $redirect_parts = parse_url($this->info['redirect_url'] ?? ''); if (empty($redirect_parts)) { $redirect_parts = []; @@ -229,19 +230,19 @@ class CurlResult implements IHTTPResult } /** {@inheritDoc} */ - public function getReturnCode() + public function getReturnCode(): string { return $this->returnCode; } /** {@inheritDoc} */ - public function getContentType() + public function getContentType(): string { return $this->contentType; } /** {@inheritDoc} */ - public function getHeader($header) + public function getHeader(string $header): array { if (empty($header)) { return []; @@ -259,13 +260,13 @@ class CurlResult implements IHTTPResult } /** {@inheritDoc} */ - public function getHeaders() + public function getHeaders(): array { return $this->getHeaderArray(); } /** {@inheritDoc} */ - public function inHeader(string $field) + public function inHeader(string $field): bool { $field = strtolower(trim($field)); @@ -275,7 +276,7 @@ class CurlResult implements IHTTPResult } /** {@inheritDoc} */ - public function getHeaderArray() + public function getHeaderArray(): array { if (!empty($this->header_fields)) { return $this->header_fields; @@ -285,9 +286,9 @@ class CurlResult implements IHTTPResult $lines = explode("\n", trim($this->header)); foreach ($lines as $line) { - $parts = explode(':', $line); + $parts = explode(':', $line); $headerfield = strtolower(trim(array_shift($parts))); - $headerdata = trim(implode(':', $parts)); + $headerdata = trim(implode(':', $parts)); if (empty($this->header_fields[$headerfield])) { $this->header_fields[$headerfield] = [$headerdata]; } elseif (!in_array($headerdata, $this->header_fields[$headerfield])) { @@ -299,49 +300,49 @@ class CurlResult implements IHTTPResult } /** {@inheritDoc} */ - public function isSuccess() + public function isSuccess(): bool { return $this->isSuccess; } /** {@inheritDoc} */ - public function getUrl() + public function getUrl(): string { return $this->url; } /** {@inheritDoc} */ - public function getRedirectUrl() + public function getRedirectUrl(): string { return $this->redirectUrl; } /** {@inheritDoc} */ - public function getBody() + public function getBody(): string { return $this->body; } /** {@inheritDoc} */ - public function isRedirectUrl() + public function isRedirectUrl(): bool { return $this->isRedirectUrl; } /** {@inheritDoc} */ - public function getErrorNumber() + public function getErrorNumber(): int { return $this->errorNumber; } /** {@inheritDoc} */ - public function getError() + public function getError(): string { return $this->error; } /** {@inheritDoc} */ - public function isTimeout() + public function isTimeout(): bool { return $this->isTimeout; } diff --git a/src/Network/GuzzleResponse.php b/src/Network/HTTPClient/Response/GuzzleResponse.php similarity index 81% rename from src/Network/GuzzleResponse.php rename to src/Network/HTTPClient/Response/GuzzleResponse.php index d5afb4ca6..aa92309e5 100644 --- a/src/Network/GuzzleResponse.php +++ b/src/Network/HTTPClient/Response/GuzzleResponse.php @@ -19,10 +19,10 @@ * */ -namespace Friendica\Network; +namespace Friendica\Network\HTTPClient\Response; use Friendica\Core\Logger; -use Friendica\Core\System; +use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; use Friendica\Network\HTTPException\NotImplementedException; use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; @@ -30,7 +30,7 @@ use Psr\Http\Message\ResponseInterface; /** * A content wrapper class for Guzzle call results */ -class GuzzleResponse extends Response implements IHTTPResult, ResponseInterface +class GuzzleResponse extends Response implements ICanHandleHttpResponses, ResponseInterface { /** @var string The URL */ private $url; @@ -79,68 +79,72 @@ class GuzzleResponse extends Response implements IHTTPResult, ResponseInterface } /** {@inheritDoc} */ - public function getReturnCode() + public function getReturnCode(): string { return $this->getStatusCode(); } /** {@inheritDoc} */ - public function getContentType() + public function getContentType(): string { $contentTypes = $this->getHeader('Content-Type') ?? []; + return array_pop($contentTypes) ?? ''; } /** {@inheritDoc} */ - public function inHeader(string $field) + public function inHeader(string $field): bool { return $this->hasHeader($field); } /** {@inheritDoc} */ - public function getHeaderArray() + public function getHeaderArray(): array { return $this->getHeaders(); } /** {@inheritDoc} */ - public function isSuccess() + public function isSuccess(): bool { return $this->isSuccess; } /** {@inheritDoc} */ - public function getUrl() + public function getUrl(): string { return $this->url; } /** {@inheritDoc} */ - public function getRedirectUrl() + public function getRedirectUrl(): string { return $this->url; } - /** {@inheritDoc} */ - public function isRedirectUrl() + /** {@inheritDoc} + * + * @throws NotImplementedException + */ + public function isRedirectUrl(): bool { throw new NotImplementedException(); } /** {@inheritDoc} */ - public function getErrorNumber() + public function getErrorNumber(): int { return $this->errorNumber; } /** {@inheritDoc} */ - public function getError() + public function getError(): string { return $this->error; } /** {@inheritDoc} */ - public function isTimeout() + public function isTimeout(): bool { return $this->isTimeout; } diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 23c115eab..64855b83a 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -34,6 +34,7 @@ use Friendica\Model\Contact; use Friendica\Model\GServer; use Friendica\Model\Profile; use Friendica\Model\User; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Protocol\ActivityNamespace; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Email; @@ -170,7 +171,7 @@ class Probe Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url, 'callstack' => System::callstack(20)]); $xrd = null; - $curlResult = DI::httpClient()->get($ssl_url, [HTTPClientOptions::TIMEOUT => $xrd_timeout, HTTPClientOptions::ACCEPT_CONTENT => ['application/xrd+xml']]); + $curlResult = DI::httpClient()->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 +188,7 @@ class Probe } if (!is_object($xrd) && !empty($url)) { - $curlResult = DI::httpClient()->get($url, [HTTPClientOptions::TIMEOUT => $xrd_timeout, HTTPClientOptions::ACCEPT_CONTENT => ['application/xrd+xml']]); + $curlResult = DI::httpClient()->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]); @@ -429,7 +430,7 @@ class Probe */ private static function getHideStatus($url) { - $curlResult = DI::httpClient()->get($url, [HTTPClientOptions::CONTENT_LENGTH => 1000000]); + $curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000]); if (!$curlResult->isSuccess()) { return false; } @@ -950,7 +951,7 @@ class Probe { $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()) { self::$istimeout = true; return []; diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 46f68086b..ca8a76b6b 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -38,7 +38,7 @@ use Friendica\Model\ItemURI; use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Model\User; -use Friendica\Network\HTTPClientOptions; +use Friendica\Network\HTTPClient\Client\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::httpClient()->get($conversation, [HTTPClientOptions::ACCEPT_CONTENT => ['application/atom+xml', 'text/html']]); + $curlResult = DI::httpClient()->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::httpClient()->get($related, [HTTPClientOptions::ACCEPT_CONTENT => ['application/atom+xml', 'text/html']]); + $curlResult = DI::httpClient()->get($related, [HttpClientOptions::ACCEPT_CONTENT => ['application/atom+xml', 'text/html']]); if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { return; diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index f11dbcceb..36919b5b6 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -28,9 +28,9 @@ use Friendica\DI; use Friendica\Model\APContact; use Friendica\Model\Contact; use Friendica\Model\User; -use Friendica\Network\CurlResult; -use Friendica\Network\HTTPClientOptions; -use Friendica\Network\IHTTPResult; +use Friendica\Network\HTTPClient\Response\CurlResult; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; /** * Implements HTTP Signatures per draft-cavage-http-signatures-07. @@ -414,7 +414,7 @@ class HTTPSignature * 'nobody' => only return the header * 'cookiejar' => path to cookie jar file * - * @return IHTTPResult CurlResult + * @return \Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses CurlResult * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ public static function fetchRaw($request, $uid = 0, $opts = ['accept_content' => ['application/activity+json', 'application/ld+json']]) @@ -450,7 +450,7 @@ class HTTPSignature } $curl_opts = $opts; - $curl_opts[HTTPClientOptions::HEADERS] = $header; + $curl_opts[HttpClientOptions::HEADERS] = $header; if (!empty($opts['nobody'])) { $curlResult = DI::httpClient()->head($request, $curl_opts); diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 589164952..6c3c4a025 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -30,7 +30,7 @@ use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Network\HTTPException; -use Friendica\Network\HTTPClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; /** * Get information about a given URL @@ -214,7 +214,7 @@ class ParseUrl return $siteinfo; } - $curlResult = DI::httpClient()->get($url, [HTTPClientOptions::CONTENT_LENGTH => 1000000]); + $curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000]); if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { return $siteinfo; } diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 99d5054ca..6d05e6cdc 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -29,7 +29,7 @@ use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\User; -use Friendica\Network\HTTPClientOptions; +use Friendica\Network\HTTPClient\Client\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::httpClient()->get($contact['poll'], [HTTPClientOptions::COOKIEJAR => $cookiejar]); + $curlResult = DI::httpClient()->get($contact['poll'], [HttpClientOptions::COOKIEJAR => $cookiejar]); unlink($cookiejar); if ($curlResult->isTimeout()) { diff --git a/static/dependencies.config.php b/static/dependencies.config.php index 042949e60..dad374d8d 100644 --- a/static/dependencies.config.php +++ b/static/dependencies.config.php @@ -224,8 +224,8 @@ return [ ['getBackend', [], Dice::CHAIN_CALL], ], ], - Network\IHTTPClient::class => [ - 'instanceOf' => Factory\HTTPClientFactory::class, + Network\HTTPClient\Capability\ICanRequestPerHttp::class => [ + 'instanceOf' => Network\HTTPClient\Factory\HttpClient::class, 'call' => [ ['createClient', [], Dice::CHAIN_CALL], ], diff --git a/tests/DiceHttpMockHandlerTrait.php b/tests/DiceHttpMockHandlerTrait.php index 969b76b5b..7f77d7e4f 100644 --- a/tests/DiceHttpMockHandlerTrait.php +++ b/tests/DiceHttpMockHandlerTrait.php @@ -23,8 +23,8 @@ namespace Friendica\Test; use Dice\Dice; use Friendica\DI; -use Friendica\Factory\HTTPClientFactory; -use Friendica\Network\IHTTPClient; +use Friendica\Network\HTTPClient\Factory\HttpClient; +use Friendica\Network\HTTPClient\Capability\ICanRequestPerHttp; use GuzzleHttp\HandlerStack; /** @@ -49,8 +49,8 @@ trait DiceHttpMockHandlerTrait $dice = DI::getDice(); // addRule() clones the current instance and returns a new one, so no concurrency problems :-) - $newDice = $dice->addRule(IHTTPClient::class, [ - 'instanceOf' => HTTPClientFactory::class, + $newDice = $dice->addRule(ICanRequestPerHttp::class, [ + 'instanceOf' => HttpClient::class, 'call' => [ ['createClient', [$this->httpRequestHandler], Dice::CHAIN_CALL], ], diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index 4742d41d8..8db5a7d5c 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -25,8 +25,8 @@ namespace Friendica\Core; use Dice\Dice; use Friendica\Core\Config\ValueObject\Cache; use Friendica\DI; -use Friendica\Network\IHTTPResult; -use Friendica\Network\IHTTPClient; +use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; +use Friendica\Network\HTTPClient\Capability\ICanRequestPerHttp; use Friendica\Test\MockedTest; use Friendica\Test\Util\VFSTrait; use Mockery; @@ -319,7 +319,7 @@ class InstallerTest extends MockedTest $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; }); // Mocking the CURL Response - $IHTTPResult = Mockery::mock(IHTTPResult::class); + $IHTTPResult = Mockery::mock(ICanHandleHttpResponses::class); $IHTTPResult ->shouldReceive('getReturnCode') ->andReturn('404'); @@ -331,7 +331,7 @@ class InstallerTest extends MockedTest ->andReturn('test Error'); // Mocking the CURL Request - $networkMock = Mockery::mock(IHTTPClient::class); + $networkMock = Mockery::mock(ICanRequestPerHttp::class); $networkMock ->shouldReceive('fetchFull') ->with('https://test/install/testrewrite') @@ -342,7 +342,7 @@ class InstallerTest extends MockedTest ->andReturn($IHTTPResult); $this->dice->shouldReceive('create') - ->with(IHTTPClient::class) + ->with(ICanRequestPerHttp::class) ->andReturn($networkMock); DI::init($this->dice); @@ -366,19 +366,19 @@ class InstallerTest extends MockedTest $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; }); // Mocking the failed CURL Response - $IHTTPResultF = Mockery::mock(IHTTPResult::class); + $IHTTPResultF = Mockery::mock(ICanHandleHttpResponses::class); $IHTTPResultF ->shouldReceive('getReturnCode') ->andReturn('404'); // Mocking the working CURL Response - $IHTTPResultW = Mockery::mock(IHTTPResult::class); + $IHTTPResultW = Mockery::mock(ICanHandleHttpResponses::class); $IHTTPResultW ->shouldReceive('getReturnCode') ->andReturn('204'); // Mocking the CURL Request - $networkMock = Mockery::mock(IHTTPClient::class); + $networkMock = Mockery::mock(ICanRequestPerHttp::class); $networkMock ->shouldReceive('fetchFull') ->with('https://test/install/testrewrite') @@ -389,7 +389,7 @@ class InstallerTest extends MockedTest ->andReturn($IHTTPResultW); $this->dice->shouldReceive('create') - ->with(IHTTPClient::class) + ->with(ICanRequestPerHttp::class) ->andReturn($networkMock); DI::init($this->dice); diff --git a/tests/src/Core/Storage/Repository/StorageManagerTest.php b/tests/src/Core/Storage/Repository/StorageManagerTest.php index 0ba28af82..c090c2696 100644 --- a/tests/src/Core/Storage/Repository/StorageManagerTest.php +++ b/tests/src/Core/Storage/Repository/StorageManagerTest.php @@ -40,7 +40,7 @@ use Friendica\DI; use Friendica\Core\Config\Factory\Config; use Friendica\Core\Config\Repository; use Friendica\Core\Storage\Type; -use Friendica\Network\HTTPClient; +use Friendica\Network\HTTPClient\Client\HttpClientCan; use Friendica\Test\DatabaseTest; use Friendica\Test\Util\Database\StaticDatabase; use Friendica\Test\Util\VFSTrait; @@ -61,7 +61,7 @@ class StorageManagerTest extends DatabaseTest private $logger; /** @var L10n */ private $l10n; - /** @var HTTPClient */ + /** @var HttpClientCan */ private $httpRequest; protected function setUp(): void @@ -93,7 +93,7 @@ class StorageManagerTest extends DatabaseTest $this->l10n = \Mockery::mock(L10n::class); - $this->httpRequest = \Mockery::mock(HTTPClient::class); + $this->httpRequest = \Mockery::mock(HttpClientCan::class); } protected function tearDown(): void diff --git a/tests/src/Network/HTTPClientTest.php b/tests/src/Network/HTTPClient/Client/HTTPClientTest.php similarity index 92% rename from tests/src/Network/HTTPClientTest.php rename to tests/src/Network/HTTPClient/Client/HTTPClientTest.php index 0e3f74c09..0e2c0b3e3 100644 --- a/tests/src/Network/HTTPClientTest.php +++ b/tests/src/Network/HTTPClient/Client/HTTPClientTest.php @@ -1,6 +1,6 @@ makePartial(); - $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php'); + $dice = $dice->addRules(include __DIR__ . '/../../../../../static/dependencies.config.php'); $logger = new NullLogger(); $dice->shouldReceive('create') @@ -52,12 +52,12 @@ class CurlResultTest extends TestCase */ public function testNormal() { - $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head'); - $headerArray = include(__DIR__ . '/../../datasets/curl/about.head.php'); - $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body'); + $header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head'); + $headerArray = include(__DIR__ . '/../../../../datasets/curl/about.head.php'); + $body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body'); - $curlResult = new CurlResult('https://test.local', $header . $body, [ + $curlResult = new \Friendica\Network\HTTPClient\Response\CurlResult('https://test.local', $header . $body, [ 'http_code' => 200, 'content_type' => 'text/html; charset=utf-8', 'url' => 'https://test.local' @@ -80,12 +80,12 @@ class CurlResultTest extends TestCase */ public function testRedirect() { - $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head'); - $headerArray = include(__DIR__ . '/../../datasets/curl/about.head.php'); - $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body'); + $header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head'); + $headerArray = include(__DIR__ . '/../../../../datasets/curl/about.head.php'); + $body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body'); - $curlResult = new CurlResult('https://test.local/test/it', $header . $body, [ + $curlResult = new \Friendica\Network\HTTPClient\Response\CurlResult('https://test.local/test/it', $header . $body, [ 'http_code' => 301, 'content_type' => 'text/html; charset=utf-8', 'url' => 'https://test.local/test/it', @@ -107,12 +107,12 @@ class CurlResultTest extends TestCase */ public function testTimeout() { - $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head'); - $headerArray = include(__DIR__ . '/../../datasets/curl/about.head.php'); - $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body'); + $header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head'); + $headerArray = include(__DIR__ . '/../../../../datasets/curl/about.head.php'); + $body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body'); - $curlResult = new CurlResult('https://test.local/test/it', $header . $body, [ + $curlResult = new \Friendica\Network\HTTPClient\Response\CurlResult('https://test.local/test/it', $header . $body, [ 'http_code' => 500, 'content_type' => 'text/html; charset=utf-8', 'url' => 'https://test.local/test/it', @@ -136,9 +136,9 @@ class CurlResultTest extends TestCase */ public function testRedirectHeader() { - $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.redirect'); - $headerArray = include(__DIR__ . '/../../datasets/curl/about.redirect.php'); - $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body'); + $header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.redirect'); + $headerArray = include(__DIR__ . '/../../../../datasets/curl/about.redirect.php'); + $body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body'); $curlResult = new CurlResult('https://test.local/test/it?key=value', $header . $body, [ @@ -162,10 +162,10 @@ class CurlResultTest extends TestCase */ public function testInHeader() { - $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head'); - $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body'); + $header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head'); + $body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body'); - $curlResult = new CurlResult('https://test.local', $header . $body, [ + $curlResult = new \Friendica\Network\HTTPClient\Response\CurlResult('https://test.local', $header . $body, [ 'http_code' => 200, 'content_type' => 'text/html; charset=utf-8', 'url' => 'https://test.local' @@ -179,10 +179,10 @@ class CurlResultTest extends TestCase */ public function testGetHeaderArray() { - $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head'); - $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body'); + $header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head'); + $body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body'); - $curlResult = new CurlResult('https://test.local', $header . $body, [ + $curlResult = new \Friendica\Network\HTTPClient\Response\CurlResult('https://test.local', $header . $body, [ 'http_code' => 200, 'content_type' => 'text/html; charset=utf-8', 'url' => 'https://test.local' @@ -199,8 +199,8 @@ class CurlResultTest extends TestCase */ public function testGetHeaderWithParam() { - $header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head'); - $body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body'); + $header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head'); + $body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body'); $curlResult = new CurlResult('https://test.local', $header . $body, [ 'http_code' => 200,