Create HTTPClientFactory and introduce ImageTest

This commit is contained in:
Philipp
2021-08-23 00:14:18 +02:00
parent 73e8db24f9
commit 52c7948526
7 changed files with 278 additions and 134 deletions
+2 -2
View File
@@ -407,11 +407,11 @@ abstract class DI
//
/**
* @return Network\IHTTPRequest
* @return Network\IHTTPClient
*/
public static function httpRequest()
{
return self::$dice->create(Network\IHTTPRequest::class);
return self::$dice->create(Network\IHTTPClient::class);
}
//
+87
View File
@@ -0,0 +1,87 @@
<?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);
}
}
@@ -23,23 +23,22 @@ 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\Cookie\FileCookieJar;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
use Psr\Http\Message\RequestInterface;
use GuzzleHttp\RequestOptions;
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
class HTTPClient implements IHTTPClient
{
/** @var LoggerInterface */
private $logger;
@@ -48,31 +47,20 @@ class HTTPRequest implements IHTTPRequest
/** @var IConfig */
private $config;
/** @var string */
private $baseUrl;
private $userAgent;
/** @var Client */
private $client;
public function __construct(LoggerInterface $logger, Profiler $profiler, IConfig $config, App\BaseURL $baseUrl)
public function __construct(LoggerInterface $logger, Profiler $profiler, IConfig $config, string $userAgent, Client $client)
{
$this->logger = $logger;
$this->profiler = $profiler;
$this->config = $config;
$this->baseUrl = $baseUrl->get();
$this->logger = $logger;
$this->profiler = $profiler;
$this->config = $config;
$this->userAgent = $userAgent;
$this->client = $client;
}
/** {@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 = [])
protected function request(string $method, string $url, array $opts = [])
{
$this->profiler->startRecording('network');
@@ -105,19 +93,13 @@ class HTTPRequest implements IHTTPRequest
return CurlResult::createErrorCurl($url);
}
$curlOptions = [];
$conf = [];
if (!empty($opts['cookiejar'])) {
$curlOptions[CURLOPT_COOKIEJAR] = $opts["cookiejar"];
$curlOptions[CURLOPT_COOKIEFILE] = $opts["cookiejar"];
$jar = new FileCookieJar($opts['cookiejar']);
$conf[RequestOptions::COOKIES] = $jar;
}
// 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']);
}
@@ -126,74 +108,17 @@ class HTTPRequest implements IHTTPRequest
$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] = '';
$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['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']) {
@@ -201,20 +126,11 @@ class HTTPRequest implements IHTTPRequest
}
};
$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);
$response = $this->client->$method($url, [
'on_headers' => $onHeaders,
'curl' => $curlOptions,
]);
return new GuzzleResponse($response, $url);
} catch (TransferException $exception) {
if ($exception instanceof RequestException &&
@@ -228,6 +144,23 @@ class HTTPRequest implements IHTTPRequest
}
}
/** {@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}
*
@@ -262,7 +195,7 @@ class HTTPRequest implements IHTTPRequest
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());
curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
if ($this->config->get('system', 'ipv4_resolve', false)) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
@@ -376,7 +309,7 @@ class HTTPRequest implements IHTTPRequest
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_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
curl_exec($ch);
$curl_info = @curl_getinfo($ch);
@@ -421,7 +354,7 @@ class HTTPRequest implements IHTTPRequest
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_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
$body = curl_exec($ch);
curl_close($ch);
@@ -485,17 +418,4 @@ class HTTPRequest implements IHTTPRequest
]
);
}
/**
* {@inheritDoc}
*/
public function getUserAgent()
{
return
FRIENDICA_PLATFORM . " '" .
FRIENDICA_CODENAME . "' " .
FRIENDICA_VERSION . '-' .
DB_UPDATE_VERSION . '; ' .
$this->baseUrl;
}
}
@@ -24,7 +24,7 @@ namespace Friendica\Network;
/**
* Interface for calling HTTP requests and returning their responses
*/
interface IHTTPRequest
interface IHTTPClient
{
/**
* Fetches the content of an URL
@@ -114,11 +114,4 @@ interface IHTTPRequest
* @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();
}
+6 -3
View File
@@ -220,8 +220,11 @@ return [
['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' => [
@@ -232,5 +235,5 @@ return [
'constructParams' => [
[Dice::INSTANCE => Util\ReversedFileReader::class],
]
]
],
];
+81
View File
@@ -0,0 +1,81 @@
PNG

Bh[ ]\|;?[8h p&&Xw^vނ<WoBk%X<WMzg'OǦȖʹK .xU
O?؎dA,ú u P*8z}yWZfGA h`1pO)x+:1#1>'K=EAh |BA lso}!x Q nzukud@fd@Ȍ =viU#hc wڰ)dd&f@f0D]x~7o,# x ,e_7\;ߥ#MLĀX#c_?qDFa)~|oXȬ00 A$
~’ ?S7"1X
0` ƂE͓w/!%N ,:BtVG ٤ev}}_}ɩZvb.Vk!#C<bh+ `X[ <f_W_<(Q-AX:]\rc_w5t*,v" ]O˟hXDAX]n\q-21
!1 -
ܽoz,, XԜ.! OY#+'ǿݏ>ݟI F' 3 |t٘c`lݖ0XLfXTG'f>W'px=:Ȣ$BMJ0'1q$ˤ=%
@?x}i*Hk-A3$X р2L6T$TS R Af TdG?zOXXW:M }Wf0Hlb; 2*dCt>]C@c?g W 1ȆL\$jd=rvxa 3'G_y M`3 om1hCLiGI2? ><}?}wX%D N,.xzH I|op\h>
$ }y'+KaT_cS"1R(D(!*P sd)<Nr#MȀ|ߚߺe=1  JW+u2L
t/ $E
mc>6 Ǒ&d>_*[2;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azglJ+G5]c$[KBTJ)"2"cRP^e{.)ZB\ΊJVXT1XUxcI;'9H& 7{υ^vgK.mtI
Y{"4 B]g{zA 0"2"hcyeJ13hIkC̔-&XĖf6i9F"X̝iUqh<[apc PΚ?c65x͉]CS
Rloe6i'" 8JqzZgxD, fjQ3۞J6{6Y]HYYj:ER$-AdTf2{B7W汰ZJo)>w#d"
29Ldeb$S"7Y
g[OMO#XBANve-%` :7̲}>mEbԧN[#D [\-CEιYe/w˳tEK1ZS_T ܊W fd+hYBsg摘Vv>@mJ;føBRósGHgvrͥqMIL\kF܂clmD2v{pOB9LJZ
,-,H%$<z\$Y EaL؜)4]ƿo`͕7K NO)iv=6h+peJf?e%MMcZTjXnR1[f?Mk?6LV$|8 `ex59
"X ,ArMֱ%I IENDB`
+60
View File
@@ -0,0 +1,60 @@
<?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'));
}
}