//
/**
- * @return Network\IHTTPRequest
+ * @return Network\IHTTPClient
*/
public static function httpRequest()
{
- return self::$dice->create(Network\IHTTPRequest::class);
+ return self::$dice->create(Network\IHTTPClient::class);
}
//
--- /dev/null
+<?php
+
+namespace Friendica\Factory;
+
+use Friendica\App;
+use Friendica\BaseFactory;
+use Friendica\Core\Config\IConfig;
+use Friendica\Network\HTTPClient;
+use Friendica\Network\IHTTPClient;
+use Friendica\Util\Profiler;
+use GuzzleHttp\Client;
+use GuzzleHttp\RequestOptions;
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\UriInterface;
+use Psr\Log\LoggerInterface;
+
+class HTTPClientFactory extends BaseFactory
+{
+ /** @var IConfig */
+ private $config;
+ /** @var Profiler */
+ private $profiler;
+ /** @var App\BaseURL */
+ private $baseUrl;
+
+ public function __construct(LoggerInterface $logger, IConfig $config, Profiler $profiler, App\BaseURL $baseUrl)
+ {
+ parent::__construct($logger);
+ $this->config = $config;
+ $this->profiler = $profiler;
+ $this->baseUrl = $baseUrl;
+ }
+
+ public function createClient(): IHTTPClient
+ {
+ $proxy = $this->config->get('system', 'proxy');
+
+ if (!empty($proxy)) {
+ $proxyuser = $this->config->get('system', 'proxyuser');
+
+ if (!empty($proxyuser)) {
+ $proxy = $proxyuser . '@' . $proxy;
+ }
+ }
+
+ $logger = $this->logger;
+
+ $onRedirect = function (
+ RequestInterface $request,
+ ResponseInterface $response,
+ UriInterface $uri
+ ) use ($logger) {
+ $logger->notice('Curl redirect.', ['url' => $request->getUri(), 'to' => $uri]);
+ };
+
+ $guzzle = new Client([
+ RequestOptions::ALLOW_REDIRECTS => [
+ 'max' => 8,
+ 'on_redirect' => $onRedirect,
+ 'track_redirect' => true,
+ 'strict' => true,
+ 'referer' => true,
+ ],
+ RequestOptions::HTTP_ERRORS => false,
+ // Without this setting it seems as if some webservers send compressed content
+ // This seems to confuse curl so that it shows this uncompressed.
+ /// @todo We could possibly set this value to "gzip" or something similar
+ RequestOptions::DECODE_CONTENT => '',
+ 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
+ // but you can override this
+ RequestOptions::VERIFY => (bool)$this->config->get('system', 'verifyssl'),
+ RequestOptions::PROXY => $proxy,
+ ]);
+
+ $userAgent = FRIENDICA_PLATFORM . " '" .
+ FRIENDICA_CODENAME . "' " .
+ FRIENDICA_VERSION . '-' .
+ DB_UPDATE_VERSION . '; ' .
+ $this->baseUrl->get();
+
+ return new HTTPClient($logger, $this->profiler, $this->config, $userAgent, $guzzle);
+ }
+}
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU APGL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Network;
+
+use DOMDocument;
+use DomXPath;
+use Friendica\Core\Config\IConfig;
+use Friendica\Core\System;
+use Friendica\Util\Network;
+use Friendica\Util\Profiler;
+use GuzzleHttp\Client;
+use GuzzleHttp\Cookie\FileCookieJar;
+use GuzzleHttp\Exception\RequestException;
+use GuzzleHttp\Exception\TransferException;
+use GuzzleHttp\RequestOptions;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Performs HTTP requests to a given URL
+ */
+class HTTPClient implements IHTTPClient
+{
+ /** @var LoggerInterface */
+ private $logger;
+ /** @var Profiler */
+ private $profiler;
+ /** @var IConfig */
+ private $config;
+ /** @var string */
+ private $userAgent;
+ /** @var Client */
+ private $client;
+
+ public function __construct(LoggerInterface $logger, Profiler $profiler, IConfig $config, string $userAgent, Client $client)
+ {
+ $this->logger = $logger;
+ $this->profiler = $profiler;
+ $this->config = $config;
+ $this->userAgent = $userAgent;
+ $this->client = $client;
+ }
+
+ protected function request(string $method, string $url, array $opts = [])
+ {
+ $this->profiler->startRecording('network');
+
+ if (Network::isLocalLink($url)) {
+ $this->logger->info('Local link', ['url' => $url, 'callstack' => System::callstack(20)]);
+ }
+
+ if (strlen($url) > 1000) {
+ $this->logger->debug('URL is longer than 1000 characters.', ['url' => $url, 'callstack' => System::callstack(20)]);
+ $this->profiler->stopRecording();
+ return CurlResult::createErrorCurl(substr($url, 0, 200));
+ }
+
+ $parts2 = [];
+ $parts = parse_url($url);
+ $path_parts = explode('/', $parts['path'] ?? '');
+ foreach ($path_parts as $part) {
+ if (strlen($part) <> mb_strlen($part)) {
+ $parts2[] = rawurlencode($part);
+ } else {
+ $parts2[] = $part;
+ }
+ }
+ $parts['path'] = implode('/', $parts2);
+ $url = Network::unparseURL($parts);
+
+ if (Network::isUrlBlocked($url)) {
+ $this->logger->info('Domain is blocked.', ['url' => $url]);
+ $this->profiler->stopRecording();
+ return CurlResult::createErrorCurl($url);
+ }
+
+ $conf = [];
+
+ if (!empty($opts['cookiejar'])) {
+ $jar = new FileCookieJar($opts['cookiejar']);
+ $conf[RequestOptions::COOKIES] = $jar;
+ }
+
+ if (!empty($opts['accept_content'])) {
+ array_push($curlOptions[CURLOPT_HTTPHEADER], 'Accept: ' . $opts['accept_content']);
+ }
+
+ if (!empty($opts['header'])) {
+ $curlOptions[CURLOPT_HTTPHEADER] = array_merge($opts['header'], $curlOptions[CURLOPT_HTTPHEADER]);
+ }
+
+ $curlOptions[CURLOPT_USERAGENT] = $this->userAgent;
+
+ if (!empty($opts['headers'])) {
+ $this->logger->notice('Wrong option \'headers\' used.');
+ $curlOptions[CURLOPT_HTTPHEADER] = array_merge($opts['headers'], $curlOptions[CURLOPT_HTTPHEADER]);
+ }
+
+ if (!empty($opts['timeout'])) {
+ $curlOptions[CURLOPT_TIMEOUT] = $opts['timeout'];
+ }
+
+ $onHeaders = function (ResponseInterface $response) use ($opts) {
+ if (!empty($opts['content_length']) &&
+ $response->getHeaderLine('Content-Length') > $opts['content_length']) {
+ throw new TransferException('The file is too big!');
+ }
+ };
+
+ try {
+ $response = $this->client->$method($url, [
+ 'on_headers' => $onHeaders,
+ 'curl' => $curlOptions,
+ ]);
+ return new GuzzleResponse($response, $url);
+ } catch (TransferException $exception) {
+ if ($exception instanceof RequestException &&
+ $exception->hasResponse()) {
+ return new GuzzleResponse($exception->getResponse(), $url, $exception->getCode(), '');
+ } else {
+ return new CurlResult($url, '', ['http_code' => $exception->getCode()], $exception->getCode(), '');
+ }
+ } finally {
+ $this->profiler->stopRecording();
+ }
+ }
+
+ /** {@inheritDoc}
+ *
+ * @throws HTTPException\InternalServerErrorException
+ */
+ public function head(string $url, array $opts = [])
+ {
+ return $this->request('head', $url, $opts);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get(string $url, array $opts = [])
+ {
+ return $this->request('get', $url, $opts);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param int $redirects The recursion counter for internal use - default 0
+ *
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ public function post(string $url, $params, array $headers = [], int $timeout = 0, &$redirects = 0)
+ {
+ $this->profiler->startRecording('network');
+
+ if (Network::isLocalLink($url)) {
+ $this->logger->info('Local link', ['url' => $url, 'callstack' => System::callstack(20)]);
+ }
+
+ if (Network::isUrlBlocked($url)) {
+ $this->logger->info('Domain is blocked.' . ['url' => $url]);
+ $this->profiler->stopRecording();
+ return CurlResult::createErrorCurl($url);
+ }
+
+ $ch = curl_init($url);
+
+ if (($redirects > 8) || (!$ch)) {
+ $this->profiler->stopRecording();
+ return CurlResult::createErrorCurl($url);
+ }
+
+ $this->logger->debug('Post_url: start.', ['url' => $url]);
+
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
+ curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
+
+ if ($this->config->get('system', 'ipv4_resolve', false)) {
+ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
+ }
+
+ @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
+
+ if (intval($timeout)) {
+ curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+ } else {
+ $curl_time = $this->config->get('system', 'curl_timeout', 60);
+ curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
+ }
+
+ if (!empty($headers)) {
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+ }
+
+ $check_cert = $this->config->get('system', 'verifyssl');
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
+
+ if ($check_cert) {
+ @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
+ }
+
+ $proxy = $this->config->get('system', 'proxy');
+
+ if (!empty($proxy)) {
+ curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
+ curl_setopt($ch, CURLOPT_PROXY, $proxy);
+ $proxyuser = $this->config->get('system', 'proxyuser');
+ if (!empty($proxyuser)) {
+ curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
+ }
+ }
+
+ // don't let curl abort the entire application
+ // if it throws any errors.
+
+ $s = @curl_exec($ch);
+
+ $curl_info = curl_getinfo($ch);
+
+ $curlResponse = new CurlResult($url, $s, $curl_info, curl_errno($ch), curl_error($ch));
+
+ if (!Network::isRedirectBlocked($url) && $curlResponse->isRedirectUrl()) {
+ $redirects++;
+ $this->logger->info('Post redirect.', ['url' => $url, 'to' => $curlResponse->getRedirectUrl()]);
+ curl_close($ch);
+ $this->profiler->stopRecording();
+ return $this->post($curlResponse->getRedirectUrl(), $params, $headers, $redirects, $timeout);
+ }
+
+ curl_close($ch);
+
+ $this->profiler->stopRecording();
+
+ // Very old versions of Lighttpd don't like the "Expect" header, so we remove it when needed
+ if ($curlResponse->getReturnCode() == 417) {
+ $redirects++;
+
+ if (empty($headers)) {
+ $headers = ['Expect:'];
+ } else {
+ if (!in_array('Expect:', $headers)) {
+ array_push($headers, 'Expect:');
+ }
+ }
+ $this->logger->info('Server responds with 417, applying workaround', ['url' => $url]);
+ return $this->post($url, $params, $headers, $redirects, $timeout);
+ }
+
+ $this->logger->debug('Post_url: End.', ['url' => $url]);
+
+ return $curlResponse;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function finalUrl(string $url, int $depth = 1, bool $fetchbody = false)
+ {
+ if (Network::isLocalLink($url)) {
+ $this->logger->info('Local link', ['url' => $url, 'callstack' => System::callstack(20)]);
+ }
+
+ if (Network::isUrlBlocked($url)) {
+ $this->logger->info('Domain is blocked.', ['url' => $url]);
+ return $url;
+ }
+
+ if (Network::isRedirectBlocked($url)) {
+ $this->logger->info('Domain should not be redirected.', ['url' => $url]);
+ return $url;
+ }
+
+ $url = Network::stripTrackingQueryParams($url);
+
+ if ($depth > 10) {
+ return $url;
+ }
+
+ $url = trim($url, "'");
+
+ $this->profiler->startRecording('network');
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HEADER, 1);
+ curl_setopt($ch, CURLOPT_NOBODY, 1);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
+
+ curl_exec($ch);
+ $curl_info = @curl_getinfo($ch);
+ $http_code = $curl_info['http_code'];
+ curl_close($ch);
+
+ $this->profiler->stopRecording();
+
+ if ($http_code == 0) {
+ return $url;
+ }
+
+ if (in_array($http_code, ['301', '302'])) {
+ if (!empty($curl_info['redirect_url'])) {
+ return $this->finalUrl($curl_info['redirect_url'], ++$depth, $fetchbody);
+ } elseif (!empty($curl_info['location'])) {
+ return $this->finalUrl($curl_info['location'], ++$depth, $fetchbody);
+ }
+ }
+
+ // Check for redirects in the meta elements of the body if there are no redirects in the header.
+ if (!$fetchbody) {
+ return $this->finalUrl($url, ++$depth, true);
+ }
+
+ // if the file is too large then exit
+ if ($curl_info["download_content_length"] > 1000000) {
+ return $url;
+ }
+
+ // if it isn't a HTML file then exit
+ if (!empty($curl_info["content_type"]) && !strstr(strtolower($curl_info["content_type"]), "html")) {
+ return $url;
+ }
+
+ $this->profiler->startRecording('network');
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_NOBODY, 0);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
+
+ $body = curl_exec($ch);
+ curl_close($ch);
+
+ $this->profiler->stopRecording();
+
+ if (trim($body) == "") {
+ return $url;
+ }
+
+ // Check for redirect in meta elements
+ $doc = new DOMDocument();
+ @$doc->loadHTML($body);
+
+ $xpath = new DomXPath($doc);
+
+ $list = $xpath->query("//meta[@content]");
+ foreach ($list as $node) {
+ $attr = [];
+ if ($node->attributes->length) {
+ foreach ($node->attributes as $attribute) {
+ $attr[$attribute->name] = $attribute->value;
+ }
+ }
+
+ if (@$attr["http-equiv"] == 'refresh') {
+ $path = $attr["content"];
+ $pathinfo = explode(";", $path);
+ foreach ($pathinfo as $value) {
+ if (substr(strtolower($value), 0, 4) == "url=") {
+ return $this->finalUrl(substr($value, 4), ++$depth);
+ }
+ }
+ }
+ }
+
+ return $url;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '')
+ {
+ $ret = $this->fetchFull($url, $timeout, $accept_content, $cookiejar);
+
+ return $ret->getBody();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '')
+ {
+ return $this->get(
+ $url,
+ [
+ 'timeout' => $timeout,
+ 'accept_content' => $accept_content,
+ 'cookiejar' => $cookiejar
+ ]
+ );
+ }
+}
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
- *
- * @license GNU APGL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Network;
-
-use DOMDocument;
-use DomXPath;
-use Friendica\App;
-use Friendica\Core\Config\IConfig;
-use Friendica\Core\System;
-use Friendica\Util\Network;
-use Friendica\Util\Profiler;
-use GuzzleHttp\Client;
-use GuzzleHttp\Exception\RequestException;
-use GuzzleHttp\Exception\TransferException;
-use Psr\Http\Message\RequestInterface;
-use Psr\Http\Message\ResponseInterface;
-use Psr\Http\Message\UriInterface;
-use Psr\Log\LoggerInterface;
-
-/**
- * Performs HTTP requests to a given URL
- */
-class HTTPRequest implements IHTTPRequest
-{
- /** @var LoggerInterface */
- private $logger;
- /** @var Profiler */
- private $profiler;
- /** @var IConfig */
- private $config;
- /** @var string */
- private $baseUrl;
-
- public function __construct(LoggerInterface $logger, Profiler $profiler, IConfig $config, App\BaseURL $baseUrl)
- {
- $this->logger = $logger;
- $this->profiler = $profiler;
- $this->config = $config;
- $this->baseUrl = $baseUrl->get();
- }
-
- /** {@inheritDoc}
- *
- * @throws HTTPException\InternalServerErrorException
- */
- public function head(string $url, array $opts = [])
- {
- $opts['nobody'] = true;
-
- return $this->get($url, $opts);
- }
-
- /**
- * {@inheritDoc}
- */
- public function get(string $url, array $opts = [])
- {
- $this->profiler->startRecording('network');
-
- if (Network::isLocalLink($url)) {
- $this->logger->info('Local link', ['url' => $url, 'callstack' => System::callstack(20)]);
- }
-
- if (strlen($url) > 1000) {
- $this->logger->debug('URL is longer than 1000 characters.', ['url' => $url, 'callstack' => System::callstack(20)]);
- $this->profiler->stopRecording();
- return CurlResult::createErrorCurl(substr($url, 0, 200));
- }
-
- $parts2 = [];
- $parts = parse_url($url);
- $path_parts = explode('/', $parts['path'] ?? '');
- foreach ($path_parts as $part) {
- if (strlen($part) <> mb_strlen($part)) {
- $parts2[] = rawurlencode($part);
- } else {
- $parts2[] = $part;
- }
- }
- $parts['path'] = implode('/', $parts2);
- $url = Network::unparseURL($parts);
-
- if (Network::isUrlBlocked($url)) {
- $this->logger->info('Domain is blocked.', ['url' => $url]);
- $this->profiler->stopRecording();
- return CurlResult::createErrorCurl($url);
- }
-
- $curlOptions = [];
-
- if (!empty($opts['cookiejar'])) {
- $curlOptions[CURLOPT_COOKIEJAR] = $opts["cookiejar"];
- $curlOptions[CURLOPT_COOKIEFILE] = $opts["cookiejar"];
- }
-
- // These settings aren't needed. We're following the location already.
- // $curlOptions[CURLOPT_FOLLOWLOCATION] =true;
- // $curlOptions[CURLOPT_MAXREDIRS] = 5;
-
- $curlOptions[CURLOPT_HTTPHEADER] = [];
-
- if (!empty($opts['accept_content'])) {
- array_push($curlOptions[CURLOPT_HTTPHEADER], 'Accept: ' . $opts['accept_content']);
- }
-
- if (!empty($opts['header'])) {
- $curlOptions[CURLOPT_HTTPHEADER] = array_merge($opts['header'], $curlOptions[CURLOPT_HTTPHEADER]);
- }
-
- $curlOptions[CURLOPT_RETURNTRANSFER] = true;
- $curlOptions[CURLOPT_USERAGENT] = $this->getUserAgent();
-
- $range = intval($this->config->get('system', 'curl_range_bytes', 0));
-
- if ($range > 0) {
- $curlOptions[CURLOPT_RANGE] = '0-' . $range;
- }
-
- // Without this setting it seems as if some webservers send compressed content
- // This seems to confuse curl so that it shows this uncompressed.
- /// @todo We could possibly set this value to "gzip" or something similar
- $curlOptions[CURLOPT_ENCODING] = '';
-
- if (!empty($opts['headers'])) {
- $this->logger->notice('Wrong option \'headers\' used.');
- $curlOptions[CURLOPT_HTTPHEADER] = array_merge($opts['headers'], $curlOptions[CURLOPT_HTTPHEADER]);
- }
-
- if (!empty($opts['nobody'])) {
- $curlOptions[CURLOPT_NOBODY] = $opts['nobody'];
- }
-
- $curlOptions[CURLOPT_CONNECTTIMEOUT] = 10;
-
- if (!empty($opts['timeout'])) {
- $curlOptions[CURLOPT_TIMEOUT] = $opts['timeout'];
- } else {
- $curl_time = $this->config->get('system', 'curl_timeout', 60);
- $curlOptions[CURLOPT_TIMEOUT] = intval($curl_time);
- }
-
- // by default we will allow self-signed certs
- // but you can override this
-
- $check_cert = $this->config->get('system', 'verifyssl');
- $curlOptions[CURLOPT_SSL_VERIFYPEER] = ($check_cert) ? true : false;
-
- if ($check_cert) {
- $curlOptions[CURLOPT_SSL_VERIFYHOST] = 2;
- }
-
- $proxy = $this->config->get('system', 'proxy');
-
- if (!empty($proxy)) {
- $curlOptions[CURLOPT_HTTPPROXYTUNNEL] = 1;
- $curlOptions[CURLOPT_PROXY] = $proxy;
- $proxyuser = $this->config->get('system', 'proxyuser');
-
- if (!empty($proxyuser)) {
- $curlOptions[CURLOPT_PROXYUSERPWD] = $proxyuser;
- }
- }
-
- if ($this->config->get('system', 'ipv4_resolve', false)) {
- $curlOptions[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
- }
-
- $logger = $this->logger;
-
- $onRedirect = function(
- RequestInterface $request,
- ResponseInterface $response,
- UriInterface $uri
- ) use ($logger) {
- $logger->notice('Curl redirect.', ['url' => $request->getUri(), 'to' => $uri]);
- };
-
- $onHeaders = function (ResponseInterface $response) use ($opts) {
- if (!empty($opts['content_length']) &&
- $response->getHeaderLine('Content-Length') > $opts['content_length']) {
- throw new TransferException('The file is too big!');
- }
- };
-
- $client = new Client([
- 'allow_redirect' => [
- 'max' => 8,
- 'on_redirect' => $onRedirect,
- 'track_redirect' => true,
- 'strict' => true,
- 'referer' => true,
- ],
- 'on_headers' => $onHeaders,
- 'curl' => $curlOptions
- ]);
-
- try {
- $response = $client->get($url);
- return new GuzzleResponse($response, $url);
- } catch (TransferException $exception) {
- if ($exception instanceof RequestException &&
- $exception->hasResponse()) {
- return new GuzzleResponse($exception->getResponse(), $url, $exception->getCode(), '');
- } else {
- return new CurlResult($url, '', ['http_code' => $exception->getCode()], $exception->getCode(), '');
- }
- } finally {
- $this->profiler->stopRecording();
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @param int $redirects The recursion counter for internal use - default 0
- *
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
- public function post(string $url, $params, array $headers = [], int $timeout = 0, &$redirects = 0)
- {
- $this->profiler->startRecording('network');
-
- if (Network::isLocalLink($url)) {
- $this->logger->info('Local link', ['url' => $url, 'callstack' => System::callstack(20)]);
- }
-
- if (Network::isUrlBlocked($url)) {
- $this->logger->info('Domain is blocked.' . ['url' => $url]);
- $this->profiler->stopRecording();
- return CurlResult::createErrorCurl($url);
- }
-
- $ch = curl_init($url);
-
- if (($redirects > 8) || (!$ch)) {
- $this->profiler->stopRecording();
- return CurlResult::createErrorCurl($url);
- }
-
- $this->logger->debug('Post_url: start.', ['url' => $url]);
-
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
- curl_setopt($ch, CURLOPT_USERAGENT, $this->getUserAgent());
-
- if ($this->config->get('system', 'ipv4_resolve', false)) {
- curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
- }
-
- @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
-
- if (intval($timeout)) {
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- } else {
- $curl_time = $this->config->get('system', 'curl_timeout', 60);
- curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
- }
-
- if (!empty($headers)) {
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- }
-
- $check_cert = $this->config->get('system', 'verifyssl');
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
-
- if ($check_cert) {
- @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- }
-
- $proxy = $this->config->get('system', 'proxy');
-
- if (!empty($proxy)) {
- curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
- curl_setopt($ch, CURLOPT_PROXY, $proxy);
- $proxyuser = $this->config->get('system', 'proxyuser');
- if (!empty($proxyuser)) {
- curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
- }
- }
-
- // don't let curl abort the entire application
- // if it throws any errors.
-
- $s = @curl_exec($ch);
-
- $curl_info = curl_getinfo($ch);
-
- $curlResponse = new CurlResult($url, $s, $curl_info, curl_errno($ch), curl_error($ch));
-
- if (!Network::isRedirectBlocked($url) && $curlResponse->isRedirectUrl()) {
- $redirects++;
- $this->logger->info('Post redirect.', ['url' => $url, 'to' => $curlResponse->getRedirectUrl()]);
- curl_close($ch);
- $this->profiler->stopRecording();
- return $this->post($curlResponse->getRedirectUrl(), $params, $headers, $redirects, $timeout);
- }
-
- curl_close($ch);
-
- $this->profiler->stopRecording();
-
- // Very old versions of Lighttpd don't like the "Expect" header, so we remove it when needed
- if ($curlResponse->getReturnCode() == 417) {
- $redirects++;
-
- if (empty($headers)) {
- $headers = ['Expect:'];
- } else {
- if (!in_array('Expect:', $headers)) {
- array_push($headers, 'Expect:');
- }
- }
- $this->logger->info('Server responds with 417, applying workaround', ['url' => $url]);
- return $this->post($url, $params, $headers, $redirects, $timeout);
- }
-
- $this->logger->debug('Post_url: End.', ['url' => $url]);
-
- return $curlResponse;
- }
-
- /**
- * {@inheritDoc}
- */
- public function finalUrl(string $url, int $depth = 1, bool $fetchbody = false)
- {
- if (Network::isLocalLink($url)) {
- $this->logger->info('Local link', ['url' => $url, 'callstack' => System::callstack(20)]);
- }
-
- if (Network::isUrlBlocked($url)) {
- $this->logger->info('Domain is blocked.', ['url' => $url]);
- return $url;
- }
-
- if (Network::isRedirectBlocked($url)) {
- $this->logger->info('Domain should not be redirected.', ['url' => $url]);
- return $url;
- }
-
- $url = Network::stripTrackingQueryParams($url);
-
- if ($depth > 10) {
- return $url;
- }
-
- $url = trim($url, "'");
-
- $this->profiler->startRecording('network');
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_NOBODY, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_USERAGENT, $this->getUserAgent());
-
- curl_exec($ch);
- $curl_info = @curl_getinfo($ch);
- $http_code = $curl_info['http_code'];
- curl_close($ch);
-
- $this->profiler->stopRecording();
-
- if ($http_code == 0) {
- return $url;
- }
-
- if (in_array($http_code, ['301', '302'])) {
- if (!empty($curl_info['redirect_url'])) {
- return $this->finalUrl($curl_info['redirect_url'], ++$depth, $fetchbody);
- } elseif (!empty($curl_info['location'])) {
- return $this->finalUrl($curl_info['location'], ++$depth, $fetchbody);
- }
- }
-
- // Check for redirects in the meta elements of the body if there are no redirects in the header.
- if (!$fetchbody) {
- return $this->finalUrl($url, ++$depth, true);
- }
-
- // if the file is too large then exit
- if ($curl_info["download_content_length"] > 1000000) {
- return $url;
- }
-
- // if it isn't a HTML file then exit
- if (!empty($curl_info["content_type"]) && !strstr(strtolower($curl_info["content_type"]), "html")) {
- return $url;
- }
-
- $this->profiler->startRecording('network');
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_NOBODY, 0);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_USERAGENT, $this->getUserAgent());
-
- $body = curl_exec($ch);
- curl_close($ch);
-
- $this->profiler->stopRecording();
-
- if (trim($body) == "") {
- return $url;
- }
-
- // Check for redirect in meta elements
- $doc = new DOMDocument();
- @$doc->loadHTML($body);
-
- $xpath = new DomXPath($doc);
-
- $list = $xpath->query("//meta[@content]");
- foreach ($list as $node) {
- $attr = [];
- if ($node->attributes->length) {
- foreach ($node->attributes as $attribute) {
- $attr[$attribute->name] = $attribute->value;
- }
- }
-
- if (@$attr["http-equiv"] == 'refresh') {
- $path = $attr["content"];
- $pathinfo = explode(";", $path);
- foreach ($pathinfo as $value) {
- if (substr(strtolower($value), 0, 4) == "url=") {
- return $this->finalUrl(substr($value, 4), ++$depth);
- }
- }
- }
- }
-
- return $url;
- }
-
- /**
- * {@inheritDoc}
- */
- public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '')
- {
- $ret = $this->fetchFull($url, $timeout, $accept_content, $cookiejar);
-
- return $ret->getBody();
- }
-
- /**
- * {@inheritDoc}
- */
- public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '')
- {
- return $this->get(
- $url,
- [
- 'timeout' => $timeout,
- 'accept_content' => $accept_content,
- 'cookiejar' => $cookiejar
- ]
- );
- }
-
- /**
- * {@inheritDoc}
- */
- public function getUserAgent()
- {
- return
- FRIENDICA_PLATFORM . " '" .
- FRIENDICA_CODENAME . "' " .
- FRIENDICA_VERSION . '-' .
- DB_UPDATE_VERSION . '; ' .
- $this->baseUrl;
- }
-}
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU APGL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Network;
+
+/**
+ * Interface for calling HTTP requests and returning their responses
+ */
+interface IHTTPClient
+{
+ /**
+ * Fetches the content of an URL
+ *
+ * Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt")
+ * to preserve cookies from one request to the next.
+ *
+ * @param string $url URL to fetch
+ * @param int $timeout Timeout in seconds, default system config value or 60 seconds
+ * @param string $accept_content supply Accept: header with 'accept_content' as the value
+ * @param string $cookiejar Path to cookie jar file
+ *
+ * @return string The fetched content
+ */
+ public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '');
+
+ /**
+ * Fetches the whole response of an URL.
+ *
+ * Inner workings and parameters are the same as @ref fetchUrl but returns an array with
+ * all the information collected during the fetch.
+ *
+ * @param string $url URL to fetch
+ * @param int $timeout Timeout in seconds, default system config value or 60 seconds
+ * @param string $accept_content supply Accept: header with 'accept_content' as the value
+ * @param string $cookiejar Path to cookie jar file
+ *
+ * @return IHTTPResult With all relevant information, 'body' contains the actual fetched content.
+ */
+ public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '');
+
+ /**
+ * Send a HEAD to an URL.
+ *
+ * @param string $url URL to fetch
+ * @param array $opts (optional parameters) assoziative array with:
+ * 'accept_content' => supply Accept: header with 'accept_content' as the value
+ * 'timeout' => int Timeout in seconds, default system config value or 60 seconds
+ * 'cookiejar' => path to cookie jar file
+ * 'header' => header array
+ *
+ * @return CurlResult
+ */
+ public function head(string $url, array $opts = []);
+
+ /**
+ * Send a GET to an URL.
+ *
+ * @param string $url URL to fetch
+ * @param array $opts (optional parameters) assoziative array with:
+ * 'accept_content' => supply Accept: header with 'accept_content' as the value
+ * 'timeout' => int Timeout in seconds, default system config value or 60 seconds
+ * 'cookiejar' => path to cookie jar file
+ * 'header' => header array
+ * 'content_length' => int maximum File content length
+ *
+ * @return IHTTPResult
+ */
+ public function get(string $url, array $opts = []);
+
+ /**
+ * Send POST request to an URL
+ *
+ * @param string $url URL to post
+ * @param mixed $params array of POST variables
+ * @param array $headers HTTP headers
+ * @param int $timeout The timeout in seconds, default system config value or 60 seconds
+ *
+ * @return IHTTPResult The content
+ */
+ public function post(string $url, $params, array $headers = [], int $timeout = 0);
+
+ /**
+ * Returns the original URL of the provided URL
+ *
+ * This function strips tracking query params and follows redirections, either
+ * through HTTP code or meta refresh tags. Stops after 10 redirections.
+ *
+ * @param string $url A user-submitted URL
+ * @param int $depth The current redirection recursion level (internal)
+ * @param bool $fetchbody Wether to fetch the body or not after the HEAD requests
+ *
+ * @return string A canonical URL
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @see ParseUrl::getSiteinfo
+ *
+ * @todo Remove the $fetchbody parameter that generates an extraneous HEAD request
+ */
+ public function finalUrl(string $url, int $depth = 1, bool $fetchbody = false);
+}
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
- *
- * @license GNU APGL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Network;
-
-/**
- * Interface for calling HTTP requests and returning their responses
- */
-interface IHTTPRequest
-{
- /**
- * Fetches the content of an URL
- *
- * Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt")
- * to preserve cookies from one request to the next.
- *
- * @param string $url URL to fetch
- * @param int $timeout Timeout in seconds, default system config value or 60 seconds
- * @param string $accept_content supply Accept: header with 'accept_content' as the value
- * @param string $cookiejar Path to cookie jar file
- *
- * @return string The fetched content
- */
- public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '');
-
- /**
- * Fetches the whole response of an URL.
- *
- * Inner workings and parameters are the same as @ref fetchUrl but returns an array with
- * all the information collected during the fetch.
- *
- * @param string $url URL to fetch
- * @param int $timeout Timeout in seconds, default system config value or 60 seconds
- * @param string $accept_content supply Accept: header with 'accept_content' as the value
- * @param string $cookiejar Path to cookie jar file
- *
- * @return IHTTPResult With all relevant information, 'body' contains the actual fetched content.
- */
- public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '');
-
- /**
- * Send a HEAD to an URL.
- *
- * @param string $url URL to fetch
- * @param array $opts (optional parameters) assoziative array with:
- * 'accept_content' => supply Accept: header with 'accept_content' as the value
- * 'timeout' => int Timeout in seconds, default system config value or 60 seconds
- * 'cookiejar' => path to cookie jar file
- * 'header' => header array
- *
- * @return CurlResult
- */
- public function head(string $url, array $opts = []);
-
- /**
- * Send a GET to an URL.
- *
- * @param string $url URL to fetch
- * @param array $opts (optional parameters) assoziative array with:
- * 'accept_content' => supply Accept: header with 'accept_content' as the value
- * 'timeout' => int Timeout in seconds, default system config value or 60 seconds
- * 'cookiejar' => path to cookie jar file
- * 'header' => header array
- * 'content_length' => int maximum File content length
- *
- * @return IHTTPResult
- */
- public function get(string $url, array $opts = []);
-
- /**
- * Send POST request to an URL
- *
- * @param string $url URL to post
- * @param mixed $params array of POST variables
- * @param array $headers HTTP headers
- * @param int $timeout The timeout in seconds, default system config value or 60 seconds
- *
- * @return IHTTPResult The content
- */
- public function post(string $url, $params, array $headers = [], int $timeout = 0);
-
- /**
- * Returns the original URL of the provided URL
- *
- * This function strips tracking query params and follows redirections, either
- * through HTTP code or meta refresh tags. Stops after 10 redirections.
- *
- * @param string $url A user-submitted URL
- * @param int $depth The current redirection recursion level (internal)
- * @param bool $fetchbody Wether to fetch the body or not after the HEAD requests
- *
- * @return string A canonical URL
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- * @see ParseUrl::getSiteinfo
- *
- * @todo Remove the $fetchbody parameter that generates an extraneous HEAD request
- */
- public function finalUrl(string $url, int $depth = 1, bool $fetchbody = false);
-
- /**
- * Returns the current UserAgent as a String
- *
- * @return string the UserAgent as a String
- */
- public function getUserAgent();
-}
['getBackend', [], Dice::CHAIN_CALL],
],
],
- Network\IHTTPRequest::class => [
- 'instanceOf' => Network\HTTPRequest::class,
+ Network\IHTTPClient::class => [
+ 'instanceOf' => Factory\HTTPClientFactory::class,
+ 'call' => [
+ ['createClient', [], Dice::CHAIN_CALL],
+ ],
],
Factory\Api\Mastodon\Error::class => [
'constructParams' => [
'constructParams' => [
[Dice::INSTANCE => Util\ReversedFileReader::class],
]
- ]
+ ],
];
--- /dev/null
+�PNG
+\1a
+���B\1eh[\f�]\ f\\1f��\1f|�;?�[����8�h �p&�&Xw^�v��ނ����<����W����oBk�%X<�W���M�z���g�\1f��������\ 3'OǦ�ȖʹK�\10 \1e��\1a\ f\15\18.x�U
+���\17���O?�؎d\aA\10�,��ú�����\f�u�\f\ 4P�*\1c8z�}\1fy�W��\e\13�ZfG��\ 4A h�`1pO)x��+�:1#\ 31\a���>��'�����K\a�=�E�\ 4Ah��� �|��B�\ 3\ 3�A \ 4�\13l�s�����o}����!\ 2�x�� �Q�\10\ 1 n�z�u���kud@fd@\ 3Ȍ\ 5� ���=v�����\1fi�U\12\ 4�#hc\f\v\ 1��w��ڰ\16)dd&f\ 4@f0�D�]x~��7���\7f�o�,�# �x� ,e�_���7\;�ߥ#M��L�Ā����X�#c��_�����?�qDF\ f\ 5a)�~��|���o�X��Ȭ��\19��00 \ 3�A$�
+��~��������\13��\92���\ 5 ?�S7"\ 31X�
+ 0�\1f` Ƃ\17E���͓w��/\7f�!�%N� ,\15:B��t��V\ fG�\10��� �\19٤�e���\10��\17v\1f}��}�_}�ɩZ��\13\17\ 4��v�b\ 6��.���Vk!\ 1#C<bh�+ `��X�[\f<f��_��\1d\1f��W_<(Q-AX:�]�\����rc_w�5\13\e\ 4����t*�,v"�\f]���O��\ f��˟������h�\1eX�DAX��]�\1c�n\q�-���\1a2�1\ 4�����
+!�1 �-\ 4
+\ 4��ܽ��o�z������\ 5��,, X��������Ԝ��.�!��\18 \ eOY#+�'���\ 1\ 1�ǿ����ݏ>��ݟI\10�\vF' \163 |����t\15٘�c�`l�ݖ�0�X�L\1a�\af���XTG'f>�W���'��p�x�=:Ȣ\14\ 4��$�B\ 4���\1c��M�J��\11�\18�0���'�\14�1q$ˤ=���%�
+�@?x��\e���\ f}i���*Hk-A�3�$X ����wߡ р2�L�6��T�$�T�S �R\1e\v�Af\fTd�G����?z��O�XX��W:M�\10 \1e�}�m�W\ 6��f�\1d\1e0���H\1c��lb;\v2���*\e\ 2���d�C��t��>��]�C��@c�?�g��\ 4\v �W����#҆\f�1ȆL\\ e�$��jd=���rv\16��x�a ����3��'���G_y��\f�M�`�3\15�\Љ�\ 5 �o�m�\1c��1h�\11C�L\12i�GI�\1d2��\16? >\ 1��<}��?}��\7fw�X%D��� �N\14,\ 6�.�\1fx�\1d�zH�� \ 5����I|op�\h��>�
+�����\1f$� �����\1e���}y���'��+K���a�\10��T��_���cS"1R�\14(D�\18��(!*P�� ��s��d)\ 2rÅ�<N\a\19\15�r#���MȀ|ߚ�ߺe��=�1 �������\18\ 1 ��J����W+u2L�
+t\7f�/��\ 2 �$E
+\11mc>\ 4�6\19\ 2 \10Ǒ&�d\a\ 4�>��_�*�[�\14�2�;�z���\1d\15\ 2�S�w���{�5�恠��p�U\10�M^,,\ 6@���o|�;O�,��l�{DM\1c�\ 2�D�\��\a
+���\10����<w��m��\1d�\ 4
+Az契�3bs �Z^����\7f�}A��� �<YX���R-4�||{��3"\102 #r\12Ao��\1a-�$О.d�iz- �a�̞\v�F�\15��\ e����ȶ��W�>���}go13.\ \ 5A�<ZX 0Y���}l���^���"�0)֡� ��\ 3�8\1a\15�\��'m>��@;�z�mj�\ 3\ 6 b ز��+�~fsߵC�v_EA�\1f�\13,\e}�����¿��BWA[��P+�\19e�t'�\ 11�.�=\\18'�[!S^\12�G�8[`x\ eW9I*�\18�)���Vu���^߽��o�\15\15�ܐ?��Y\ 2\f��\7f���|��^��@\11�Qd�\10!\ 1)�Y���\14��\16g�f!Ʃ\f� �<$b�X[�� "\ 6��^���=��������%��3��:\vBǑG�\ 2{?����\ 3\1f���H��٦�\11�!�#�\ 46���5(��J�)\ e�\16\18�JT�f�ݓ�w�<q^\17=\16$6\f\11\ 3�>������{��Ҫ\1e��\ 4�5�\15, �����>�'��ӗ\18Y�\15���2*elԼ刡s\15�\9d8c+)�AJ�s�\1fT�M{q��>�
+\ 44XT�%��DCEo���\ 2���'�\1e��=��I\12J\17���K�� X �\1f�x߿z$(x�W�T����,"���Z�\12�\a
+\ve��T�_���'�R!tiY���� �9�A!\11�"Ac-'W��=�5�\1d\14
+\16\19L\14��ZT33z^� /\ 3(BO!\ 3\13�g�� �>\ 20\ 1y\1e#����\15 ��\ 1!)\ 5J�灧Py蹧�y��\ f�G�\a��J��\v��{T��\ 2\14�9�Q,)\16�`�z�o<�����I\15�F��e9�!e�AL\1cC$7!�fP
+�\ 1�����V\ et�\ ev?t�HW�_=ҷq��\10�K� ec_\17��8��Z�ku�V7�:�j�^3�:�j\��j�T+�R��\��j�T�P��j̈́!�!��&
+\11\ 28�$ĸ��>\18�/�kvK�e\11#!"\13 9EC�G�\ 3���G�oR7\f\ 2�\ 3\f\ 2*\16�X�B\ 1
+\ 5*\16�T�b�J%*\15�T�R }\1f� \ 3�
+\ 1\14
+Hn,Fw1\11�J72c�\ 2F+�nn\14L���_��Jc|��Y!�r�\eZ\ 3M)T
+��
+\ 1 �E��W��aO�Z��/\1f��/��\ f��e��_����^���n�\14x>\15\ 2,\141�u\14�D��������\13�+���\1e����w_��u˯[7|��\ 2�,�3��9\fM�Ƨ���x4>��'�䤞\18��&��D4>��O�鲙��J�T�z�\f���\1c( D7�\ f"��ζ�V��+y\14�\ 4�ZF �3��\v\ e\1a0\1a\11�T�R KEohп�2o�
+\a\e�\166o\ e6n,\�1X��\eXF�s���Q1�ώ� X��D�\ e�G^���\1e\1e=�O\1c�ӧM�\80\10F@H˖a-�zġ�Z�\18\ 2k�[�\ 6��Ѱ�{������"��\ 1��\10i\13�� \15
+�U*�[�^\15l�X�r��yC�fM�r\14����-�]%,��/X\�M~����;L���:3���\1e\f
+\ f�Y�'\7f�.!�_� �x����\ 3�mO��\19�����\ 323\ 3�)֞bf\ 3��l@[5s��&�Ő�м0��\ 3`�Hs\14rd ���U��(\��p���k�\14���\1c����8ڬ�^~\17.!KB� ���\ f��\a���\ 5�@��l<�����\1a�\19 (6��\ 1\fS\�� \׳jY�\ e'\1e�\vC �B�\1f\1d ֯+]{M�u�\15����q��_��'�x�Y
+���_@���1\e`��54/6��J;
+�\ 6�\fN��~�t\12A�\fs�O�
+\ 55�\1flX_�fK�u�u���`�\1ao���E���R\10,\ 4d\ 6����?�?�y&6���x���>�I �k�\12��3ل5�\1d�5G��NI��1�8\f\ 1�J%\7f��\15�K7�X��ҵ�x#+Пs�!\ 4\11�\1c�\14\ 4\v����5�FS��\7f�~�\14\18���L\ 6\f3� P�<��#`�tj\ 2`��#�
+=��\15�Y���˵]�,Y��!���w��Lxp\17\ 4�M\f5�F�)���\ e ������2q<�SͶ�\11�F\eS��a\7fdE����{�=���\6k?Q|�\ 5K^� �\ fz�\7f���=bN\1d� 0I�s�
+0\ 2�&�Yˋ���VE�6K�]��ZK�zhj55��{��}o\7fk�V�nxIClj�^:a>D� To\7f�\ 3�9�\ f�1�)�}ÜN��h^ig^�Sԥ#�6{\v ��\10�g-�\1ai\ 3�l\fW� P���������\ f�����Β� �\19\11,��|eߛ\7f~�럁�2�>3\18W�\f�hV�u���\14-��/`X⾡�^3\�b1��e��s�oy0izg\1dm�(�lYR�P�\ f\ 3`td��7>k*Ӡ���\10�\1c�&
+!�8\fM\14qX�zdt\ 4a��Ȅ\1a���\11״�k�j�i�\1a�\19�40.�Txct��Jݽ\ f�i����}��ًܸg�XX ������u�۟�z�\ 2�u�\14;���\ 2@
+j\ 4t\ 5;�\10�C\1d\1f~�ߥ�zz�t�U#����=��v��\11�j�*J���9\f�?�* �Y�q[\ 6\ 6�4�e \11B\ 2N�ߜ��G���m�D�Y�\17f].\ f���F\7f�#��a�
+d�" �5\v\ 6\ 6(n������ߓ��\ 1?�{e\100��7\ 4Btb�4�C$D��\1d��:Xߐ\17k;\1a\ 6@3S^�k����^�V�J���`�\ 2�]P��\ e���S�$�3q�P�7�\e���v=\ 2"r��D\ 3 !0�\ 1B��;�\fF��R�y�\1d����v͢Sd�S\10��MR�\ 3]7ލ��'���ǜ���y�l�1$\ 6F&D��� �\ f\ 4�H�mf\17�5�Ev?#�A��_�e�=��\13.*"X�\fP��.6f��o��\eDB�[##X\ 3*\ e�'�����\11�v\19\ 4&$D�G\1cqf�����6�����o]$\1fG�`D��\ 2]3\ 1����\ 1��S�F/��<�qGD�T)n���\� \ 10"�FD\10\10m\v�v\7f�\v\ 6����Q58��3\11\16?"X� ̌�]7܍�/?�\ f� }��F����BDD D�^�ls\1f \11�\11\f\ 2�Ǥ]&�M+]\14���\12�~�ODX��`�Gb:\ 1@����\1f�\1a\ 3g;�[\ 1R\18�"2�ޢ5�0\1e0�:���\1a�f�J�\ e" D\1a�\ 6���p�0\ f"X��80�ūoF�8���5�\19\ 4۫\17�p!0\12���A\ 3\10{���\ 2k�\ 1"X#��S�P����+LJOM�jUI�b�"#��p\10�\v���ba�ۏr�\f\18 ""\1a�!������\e��!�t\aB�qN)0 \11rM�\1dk���Ę>u*�m\16��D���_Zl�\1d\ 1�_�������^$B? �C�G/@�\a�G�#�\ 3ߧ�W��A@���\a����\ 5\ f\ 3\1f\v
+����J\ 4E�E\ f)�j\ 5 �������=�>\11a�#��@�� �Ⱥ��~����\18� }\1f}\1f=?�,��\1a�ꔏ�G������v����a��\12A����\ 3 c�Fl��=�k�P�U�\7f\11 \c|A�8�Kx�x���{�/��Σz�\18$\ 3d������l�9 `�\ 3v�\10\f"`\ 4\ 4HhP3"*���P\ 3CR���O�\10\10�Q��OƗ@\10.\16��%:\14o�H�[���j#�� @�C�C��������5�|\1f��\18�\18x�{\10���
+<(\12��J
+��E��\17���r�3 B�W�\7f1<r4^\17\ 5\11��z����
+\e�c6�\ f�\ f������{�{��\18���\18\ 4\10K\15\ 6>\16|JCZ\1e\16 �
+
+�K�O��;\1a\ 4@�����\1f���'#,rD��\17�\v�ozO��0�^\12zG߇�j�\ f���O6�\15\ 4�$�#�����\ 5%\92�]
+K
+K>��\11�\ e�,��5�w_��\ 5� 1�\v *���咽�ʋ?\ 2`��I��K��Y\ e.�\ 10$\ 2F���� i7!\ fzP�\1c�tN��\ 6���\1f=V\7fm\7f�nm��EX���uA`@��M=�<��G�a\10��^��C�<t!���YA����\ 2������\ 2�t\a,zP"(**(P�[t6�H\1f?1����w�\ 4��\10�� 8\13�x�M�\ f�\a�%"T�MwpI\ f\10\ 4\14\ 4�{���}\ f� \ 3�\ 2\ f}\ f\ 2+[
+�\1e\16\15�\14�\14\14\15\16\15zɌa�|�#����dj����"&\:D�.$\f\�xM�[��\1a\1aa \f\ 2�D�\��w�\16�ZF�OI�V�c�������a)\ e��*�ձP�Py���o}w��Z�\ f�M\ 3Hڃp^�\ f\7f���>�Ń�=������\13���\ 4z
+��;�6�\e\19�~��s[\ f\ 6\ 5_y\14\ 4�d���K�?��W\1e�~�X�7�\fx*�f�D�\14\11����J���
+l%}��vxh��َ\e�\19}��sWa�Uū�tj�> �xժ��p��Ĵ���
+h \19\19<��W��_|��#?����\ fF\f\eV�w\ 5M5d���!\2D�.\1dv\ 2\1eop��zs4~�OO����\ 5���"L�Ԇx�%7��.�Lv*jBL"���1D�q���ܽ�g߃��{\\ f\10xÃ}_���\18�4h�K \15a�!��\13_}r�_<����\15}�+�u��C \1d֥\ 5\ 1\19��7�p��9�'��"�
+\1e]�
+֯\ 3'Vn\18�ƫV����\1c<\19\ 4\1e p<\a-�-���Z�\132\108��Wlx���/=�����w`|f���r�\vb\17��_�p�\10�j?\18\14��[((F'\ e��C\17zG@d�� qX�� tr�2N��l\18�&=XS�*�-�6&��u�?\1eq�^ݹs�{�M~ v�l\ 6D�\14m�<��ן7Ơ�81\ 3�\ 1����Ɋ\1a��S���t���G?�����8�\19V\ fvu\aҖr�"��^0q`����ek��q.O�K.����\�\12�餉�E��r���\16 �Y[�lYS˾i���0��������s�\1dvE���ryo���Ƕ\15\ 2��H�) ��Q�\18fl�4�\ 3\ 1A!��\19�\1d=���\ e|��\ 3�O����5�%�\1aka�ٵ8��{�� h���c\7f_��<�\ 1c8�\1c����"�B�4G\11G\11G\1at�\1c��&�8�`c�f���\1c\1a�i�\e�1��#Ә�u�\1a�q\14Q���\1f��x͖��\\v���ڟ?�ҾbwQ#E\ 4��F�
+ ��r�o\��Ϡ�<�����\ 3\1f���TY\15|M��4�&�Dq*�\v`��\eMœ�\11�\ 2�qJ�&\ 2B@\15?��t̀4����W,\7f���=�i�'���� \16VǑ\1d�\a �7\10l�\16�\1e?
+��I|��/��Ɍ\e&�"�\16ZH��i\ 4e\e� Q�\e�I_��\13���\f\10\ 3��u�74�u�͙�w �e��գ˾��\17</�\1aM̫8y+��6[+��\15�VS|�\1a� �H x\ 4\1eUB���Ͻt�ѭ'�O�\a����A|�\1c\1fW�8D�r z~��
+�6\1d3��-�ҷ^���J\11 2\ 2�-��D���bc��\\a��0|�H"�[\e\ e\ 56\1f"�f����n?���N<w�J\ 4kz�`���uI\11��\v��\ 2\ 3z�+
+\13o1�\16�\19�\v)\1dgt2�$�B�\17I\ 4�\ 2�\13e��=ӟ�6���J-�\15�^op�
+��\ 4\11��ѐ�A!X\7f�74\1a�\1f3�iT\1e&1,$$dW4���ڌ\ 6ȬISLm)5\ 1(D"T�\ 4������\v�$��\10T_z��z�o�-��\10 ��w���\7f�[/V+����A;cc\1c���\15�%�婱�CCZ��8Ws�i�4��C\ 4\1e�#��d�owM=�}ꩣ��yyIe2��1�%��\ 5F\ 4k1�\ 6�\v��\a�z�\18\1a\ 3�M�@.��b���\aL�=d\12��\10T<�F�ʙZH�\14OL\16+�\ 5�\em\14ܣ�\ f\1f��`�����u�\ 6���_"\ 4�i� ��\17C\1a��\1aGiܽ��j6��p{�t�-�ɔ+B�]\ 4\11(\ 4��:�z����\1f�1����f\1e���<����L����Xl�`-\ 6\18�<?X��\1fY���x�\14z
+g�`f0\f\11\ 3�P�w���Ûz߸�kC_ ¹"����j���+�<e�e t�\14Ell�\a\ 3:�{<$
+.
+қx�\1e\17۲�x�8nY�q����M�\ 5T�\18c굵\1f����{��\18����04�m?����X���W\ eN�ԧ*��S3����D\ 2�\ 3�\ 3�Qi<�F�2�,�\14s����+��ԭWil���Y�\19�\ 1�e=ޭ��\1e\��Ƶ]�\ e\16��"����ҥ~`w���G��l*;�\18hmt�V�R�r}����H�ֱr��\ 6"Ñ6���@�94\10\1a�d�!4�u�n��ۍ�\1a��6~�]���r�\���\1c;Uy���z]�rx�]GÈw\1e��sr�0C\ 4�\19\10����\ 1!x\1e*bT�!�d\ e1;D���\15e\ 2�*n�\1c�s�@ \ 6à\ 1\fcA]?T�ou�-�{n��8\Z�sĊ`-M�ݘ�\17*/�(\1a?
+.�!�-�:��t\ 1��L�~�Ư<\1a�];�\aIF��T��jxl������N��<�w��f<r�
+��ɐR�\ 4�\ 2O\ 1��P)��\10':8�L�I\ fta
+�\ 6"��OtI[\101G&��7筥�&\a��\7f���\13�\$NU�C�Uü{l�\ 3��Ȝ��'\ eNO�"\ 34V�\101 �� ���[�hz��� b`\ 6�����\15�\a�vݻ���B��T $�%,.�>IJ\15\1e?Ty����8
+F�өdJDgmY\17�\16�deˆ�b��9��Բ��v0�f�;�nkf�<S[�_>2��_m��iͮS���f�\1d\13ቪ� ́��X9::\13\1d��cը\12q\18\19\eJϤG�}��? �\f\ 6��X,���
+mx���\e��Λc�\9e�LdfB�\ e͉�>>\13\1d��\133щJtlF\1f���U�TM�#.�f&4\1c\19H&�ĸ�\18ACv~"^
+�u��\ e\ 5w�v�1R�iEaM�O-\ 2x�v�E��\ 5c*3�m?�l}ZO�!�a+=����\18�t�\ 6�b�j\12�49^�8�˰���4�&��s*�k9�\ ֯����\166o����R�̩������>6��τ�+�DE���Su3Uӓu3]7u+U\1ck�{j�#U�\f\ 67�(ݻ�t���U�
+\8{�j�9;�t94Su���S\1d�\ fC\ 4K�4�3c�\��\ f��z!<��T\fI�4\e�&b�`�\ 6����a��j�Kת�����n�Mw��\ 3l{�.�#�<��.5"XB>�Ǝ�v�T���>u��\ 6$0\f�6&��\1fL�*p\ 6���\fh\ 3lL�
+�\18�N�a�D�\ 6�uS��{ӻ���W�\ 3\1c\1c�l\11�\12r\ 1'5�\16}j��wkm�+�ɣ\1c�\ 1\11\fs\12�2�&�\ 2\e�TP[Q��.O�������\10*���%�\1d"XB�1&<�������N=}
+d�K��k��-�����\14\14�\19\10:���E\ 4KX\12����}�£���\14\ecs!]�R\13��t��ʁw�S�7�93�\vM�` ��YŃ�<\1d\1e�]��Jt�)O�a@����:�z��\1e��¦k�}�BkD��%����\1f�S߿#:�_��l�
+�ud���]�� \11;\7fR�����h��L�t��������\ 3�|
+"X� �\ 6\11,A\10r��5,Qr�\7f'���,�8�3.����_��!R"|�C\ 4�����?��.���lE�<EJ4���`]\14��.�U��Í�]���4Ψ\1d�����\10\ 1:\a�\12]�H�`�#�).�l�P��ٺ8��FQ@��� O���\Gk
+��s��\1aO��B�
+\ 1���\1c�� k��&}\13Dl��M��=�\1cG;æ�O�ʬ�k�\12a)
+����f�\11� \f"e�&\ai�g-\�Z\eM��Dd��2\1aF�\13 rO�R
+�,�D���L ���%!XM2�H��:�/[�j���\15\ 6 �L�3\v\16@��\ 5\v[ZU�.x��Y��zb\19q�\�h�c�uA\1a�☹3�\��\12fA�\1a����VU\12�r�Et\170�\14��ZM�\ e�\18M_���\ 5 Vw���dU)�D�D�\14Y�
+�N%�]b�%FwG~w\17�%!X��\19�\ e�X�6�\13�h���`�,�
+�짹\1c= ȊKf\ 1\1a���\18�^\ 3 ����CĖ��\10��L\12�\15 ��ٸ��6���\ 4��E\12����J t��������&�����Y\ 3֢�4��Z��zEDJ)E��BR�\ 1�3�
+�L!�<�\ e�-0y�),\ 5M��\194��\ 2u�nžmr\19�p�s���:9Nl�"�a��z��gl\15�J��+��G�5]c�\ f���$[��KBTJ)"2�\18"c�R\1a�\ 3P��^e��{.)�ZB�\ 5�\��Ί�\ 6�J��V��XT�1�X��U��x\11��cI��\ 5�;'9H�& ���\1f7{υ^�v\7f\15gK�\13��.m�tI\1c
+���Y{"4\16 �B�]�g�{�z�A ���0"2"h�\1c��c��ye��\18�J13��h\10IkC�̔��-\1d���&X�Ėf6i\10�9��F�\16"X�\ 1�\1f�̝��iUqh<�[�a�pc ���P�Κ�?c6������5x͉��]��C�S��
+R\ 5l�o��\ee�6�\ fi�'" �8J�q�zZg��\15��\14�\ 2�x�D��,�� �\v���f�jQ�3۞J6�{��6�\1a�Y��]H�YY�j:�E�R���$\16-�A��d�Tf2{B��7��\18�W�汰ZJ��\1d�o�)�>�w��\ 6�#d"�\1c�
+2��9�\e�L�deb�$\16S"7Y�
+g[OMO�\12#X�BA�N�v��e-%`�\v\a\e:7̲�\1a���}�>m�\aE�\16\e��b\1e�ԧ�N��[�#�D\v���[�\ 5�\-�C����Eι�Y��e���\1a/w�������˳��tEK\ 1��1���Z\18S��_�T� ��܊��W�\v��Hζ�f\1fd�+�hYB�\ 5s��g��摘Vv\13�>@��mJ;�f�ø�BR�ó�s�GH��g\18vrͥqM��I��L\��k�F�����܂��c\19[έ�lm\10�D�2��v�\ e\14�{�p\e�O�\12�\16B9LJZ
+,-��,�H�%�$��<z\17�����\��$Y\v�E�a����L\1a\ e���\1f)4�]ƿ�o�`�͕7���K���\v����N�O)���\ 6����i��v�����=�6h��������+p�e�J�f?�e�%�MMcZ\1e\a��T���\ 4\ 5���\ejXnR1�[�f?��Mk�?6�LV���$|�8 `�ex5��9�\15��
+"X� �\ 6\11,A\10r����\aMֱ%��I\a IEND�B`�
\ No newline at end of file
--- /dev/null
+<?php
+
+namespace Friendica\Test\src\Network;
+
+use Dice\Dice;
+use Friendica\App\BaseURL;
+use Friendica\Core\Config\IConfig;
+use Friendica\DI;
+use Friendica\Network\HTTPRequest;
+use Friendica\Network\IHTTPRequest;
+use Friendica\Test\MockedTest;
+use Friendica\Util\Images;
+use Friendica\Util\Profiler;
+use GuzzleHttp\Handler\MockHandler;
+use GuzzleHttp\Psr7\Response;
+use Psr\Log\NullLogger;
+
+require_once __DIR__ . '/../../../static/dbstructure.config.php';
+
+class HTTPRequestTest extends MockedTest
+{
+ public function testImageFetch()
+ {
+ $mock = new MockHandler([
+ new Response(200, [
+ 'Server' => 'tsa_b',
+ 'Content-Type' => 'image/png',
+ 'Cache-Control' => 'max-age=604800, must-revalidate',
+ 'Content-Length' => 24875,
+ ], file_get_contents(__DIR__ . '/../../datasets/curl/image.content'))
+ ]);
+
+ $config = \Mockery::mock(IConfig::class);
+ $config->shouldReceive('get')->with('system', 'curl_range_bytes', 0)->once()->andReturn(null);
+ $config->shouldReceive('get')->with('system', 'verifyssl')->once();
+ $config->shouldReceive('get')->with('system', 'proxy')->once();
+ $config->shouldReceive('get')->with('system', 'ipv4_resolve', false)->once()->andReturnFalse();
+ $config->shouldReceive('get')->with('system', 'blocklist', [])->once()->andReturn([]);
+
+ $baseUrl = \Mockery::mock(BaseURL::class);
+ $baseUrl->shouldReceive('get')->andReturn('http://friendica.local');
+
+ $profiler = \Mockery::mock(Profiler::class);
+ $profiler->shouldReceive('startRecording')->andReturnTrue();
+ $profiler->shouldReceive('stopRecording')->andReturnTrue();
+
+ $httpRequest = new HTTPRequest(new NullLogger(), $profiler, $config, $baseUrl);
+
+ self::assertInstanceOf(IHTTPRequest::class, $httpRequest);
+
+ $dice = \Mockery::mock(Dice::class);
+ $dice->shouldReceive('create')->with(IHTTPRequest::class)->andReturn($httpRequest)->once();
+ $dice->shouldReceive('create')->with(BaseURL::class)->andReturn($baseUrl);
+ $dice->shouldReceive('create')->with(IConfig::class)->andReturn($config)->once();
+
+ DI::init($dice);
+
+ print_r(Images::getInfoFromURL('https://pbs.twimg.com/profile_images/2365515285/9re7kx4xmc0eu9ppmado.png'));
+ }
+}