Create HTTPClientFactory and introduce ImageTest
This commit is contained in:
+2
-2
@@ -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);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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],
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
�PNG
|
||||
|
||||
���Bh[�]\��|�;?�[����8�h �p&�&Xw^�v��ނ����<����W����oBk�%X<�W���M�z���g���������'OǦ�ȖʹK� ��.x�U
|
||||
������O?�؎dA�,��ú������u�P�*8z�}y�W���ZfG��A h�`1pO)x��+�:1#1���>��'�����K�=�E�Ah��� �|��B��A �l�s�����o}����!�x�� �Q� n�z�u���kud@fd@Ȍ� ���=v�����i�U�#hc��w��ڰ)dd&f@f0�D�]x~��7����o�,�# �x� ,e�_���7\;�ߥ#M��L�Ā����X�#c��_�����?�qDFa)�~��|���o�X��Ȭ����00 �A$�
|
||||
��~������������� ?�S7"1X�
|
||||
0�` ƂE���͓w��/�!�%N� ,:B��t��VG���� �٤�e�����v}��}�_}�ɩZ����v�b��.���Vk!#C<bh�+ `��X�[<f��_����W_<(Q-AX:�]�\����rc_w�5����t*�,v"�]���O����˟������h�X�DAX��]��n\q�-���2�1�����
|
||||
!�1 �-
|
||||
��ܽ��o�z��������,, X��������Ԝ��.�!�� OY#+�'����ǿ����ݏ>��ݟI�F' 3 |����t٘�c�`l�ݖ�0�X�L�f���XTG'f>�W���'��p�x�=:Ȣ��$�B�����M�J����0���'��1q$ˤ=���%�
|
||||
�@?x�����}i���*Hk-A�3�$X ����wߡ р2�L�6��T�$�T�S �R�AfTd�G����?z��O�XX��W:M� �}�m�W��f�0���H��lb;2���*���d�C��t��>��]�C��@c�?�g�� �W����#҆�1ȆL\�$��jd=���rv��x�a ����3��'���G_y���M�`�3�\Љ� �o�m���1h�C�Li�GI�2��? >��<}��?}��w�X%D��� �N,�.�x��zH�� ����I|op�\h��>�
|
||||
�����$� ��������}y���'��+K���a���T��_���cS"1R�(D���(!*P�� ��s��d)rÅ�<N�r#���MȀ|ߚ�ߺe��=�1 ������� ��J����W+u2L�
|
||||
t�/�� �$E
|
||||
mc>�6 Ǒ&�d�>��_�*�[��2�;�z����S�w���{�5�恠��p�U�M^,,@���o|�;O�,��l�{DM��D�\��
|
||||
�������<w��m���
|
||||
Az契�3bs �Z^�����}A��� �<YX���R-4�||{��3"2 #rAo��-�$О.d�iz- �a�̞�F�������ȶ��W�>���}go13.\ A�<ZX 0Y���}l���^���"�0)֡� ���8�\��'m>��@;�z�mj� b ز��+�~fsߵC�v_EA��,}�����¿��BWA[��P+�e�t'�1�.�=\'�[!S^�G�8[`xW9I*��)���Vu���^߽��o��ܐ?��Y�����|��^��@�Qd�!)�Y�����g�f!Ʃ� �<$b�X[�� "��^���=��������%��3��:BǑG�{?�������H��٦��!�#�6���5(��J�)��JT�f�ݓ�w�<q^=$6�>������{��Ҫ���5�, �����>�'��ӗY����2*elԼ刡s�8c+)�AJ�s�T�M{q��>�
|
||||
4XT�%��DCEo������'���=��IJ���K�� X ��x߿z$(x�W�T����,"���Z��
|
||||
e��T�_���'�R!tiY���� �9�A!�"Ac-'W��=�5�
|
||||
L��ZT33z^� /(BO!�g�� �>0y#���� ��!)J�灧Py蹧�y���G���J����{T���9�Q,)�`�z�o<�����I�F��e9�!e�ALC$7!�fP
|
||||
������Vt�v?t�HW�_=ҷq���K� ec_��8��Z�ku�V7�:�j�^3�:�j\��j�T+�R��\��j�T�P��j̈́!�!��&
|
||||
8�$ĸ��>�/�kvK�e#!" 9EC�G����G�oR7�*�X�B
|
||||
*�T�b�J%*�T�R }� �
|
||||
|
||||
Hn,Fw1�J72c�F+�nnL���_��Jc|��Y!�r�ZM)T
|
||||
��
|
||||
�E��W��aO�Z��/��/����e��_����^���n�x>,1�u�D���������+�������w_��u˯[7|���,�3��9M�Ƨ���x4>��'�䤞��&��D4>��O�鲙��J�T�z����( D7�"��ζ�V��+y��ZF �3��0�T�R KEohп�2o�
|
||||
�6o6n,\�1X��XF�s���Q1�ώ� X��D��G^���=�O�ӧM�F@H˖a-�zġ�Z�k�[���Ѱ�{������"����i��
|
||||
�U*�[�^l�X�r��yC�fM�r����-�]%,��/X\�M~����;L���:3���
|
||||
�Y�'�.!�_� �x�����mO�������23�)֞bf��l@[5s��&�Ő�м0��`�Hsrd ���U��(\��p���k��������8ڬ�^~.!KB� ���������@��l<������ (6��S\�� \׳jY�'�C �B� ֯+]{M�u�����q��_��'�x�Y
|
||||
���_@���1`��54/6��J;
|
||||
��N��~�tA�s�O�
|
||||
5�lX_�fK�u�u���`�o���E���R,d����?�?�y&6���x���>�I �k���3ل5��5G��NI��1�8�J%���K7�X��ҵ�x#+Пs�!������5�FS���~����L3� P�<��#`�tj`��#�
|
||||
=���Y���˵]�,Y��!���w��Lxp�M5�F�)��� ������2q<�SͶ��FS��adE����{�=���\6k?Q|�K^� �z����=bN� 0I�s�
|
||||
0�&�Yˋ���VE�6K�]��ZK�zhj55��{��}ok�V�nxIClj�^:a>D� To��9��1�)�}ÜN��h^ig^�Sԥ#�6{ ���g-�i�lW� P��������������Β� �,��|eߛ~�럁�2�>3W��hV�u���-��/`X⾡�^3\�b1��e��s�oy0izgm�(�lYR�P�`td��7>k*Ӡ�����&
|
||||
!�8MqX�zdta��Ȅ���״�k�j�i���40.�Txct��Jݽ�i����}��ًܸg�XX ������u�۟�z��u�;���@
|
||||
jt;��C~�ߥ�zz�t�U#����=��v���j�*J���9�?�* �Y�q[�4�e BN�ߜ��G���m�D�Y�f].���F�#��a�
|
||||
d�" �5(n������ߓ��?�{e0��7Btb�4�C$D����:Xߐk;@3S^�k����^�V�J���`��]P�����S�$�3q�P�7����v="r��D !0�B��;�F��R�y�����v͢Sd�S��MR�]7ލ��'���ǜ���y�l�1$F&D��� ��H�mf�5�Ev?#�A��_�e�=��.*"X�P��.6f��o��DB�[##X*�'������v&$D�Gqf�����6�����o]$G�`D��]3������S�F/��<�qGD�T)n���\� 0"�FDm�v�����Q58��3?"X� ̌�]7܍�/?�� }��F����BDD D�^�ls ��Ǥ]&�M+]����~�ODX��`�Gb:@�����g;�[R�"2�ޢ5�00�:����f�J�" D����p�0"X��80�ūoF�8���5�۫�p!0���A{���k�"X#��S�P����+LJOM�jUI�b�"#��p����ba�ۏr� ""�!��������!�tB�qN)0 rM�k���Ę>u*�m��D���_Zl��_�������^$B? �C�G/@��G�#�ߧ�W��A@�������
|
||||
����JE�E)�j �������=�>a�#��@�� �Ⱥ��~����� }}=?�,���ꔏ�G������v����a��A���� c�Fl��=�k�P�U� \c|A�8�Kx�x���{�/��Σz�$d������l�9 `�v�"`HhP3"*���PCR���O��Q��OƗ@.��%:o�H�[���j#�� @�C�C��������5�|���x�{���
|
||||
<(��J
|
||||
��E�����r�3 B�W�1<r4^��z����
|
||||
�c6��������{�{�����K>|JCZ �
|
||||
|
||||
�K�O��;@��������'#,rD����ozO��0�^zG߇�j����O6��$�#�����%�]
|
||||
K
|
||||
K>����,��5�w_��� 1� *���咽�ʋ?`��I��K��Y.�0$F���� i7!zP��tN�����=Vm�nm��EX���uA`@��M=�<��G�a��^��C�<t!���YA�����������t,zP"(**(P�[t6�H?1����w����� 8�x�M���%"T�MwpI�{���}� �}+[
|
||||
���zɌa�|�#����dj����"&\:D�.$\�xM�[��a �D�\��w��ZF�OI�V�c�������a)��*�ձP�Py���o}w��Z��MHڃp^����>�Ń�=���������z
|
||||
��;�6��~��s[_y�d���K�?��W�~�X�7�x*�f�D�����J���
|
||||
l%}��vxh��َ�}��sWa�Uū�tj�> �xժ��p��Ĵ���
|
||||
h <��W��_|��#?����FV�wM5d���!\2D�.vop��zs4~�OO�������"L�Ԇx�%7��.�Lv*jBL"���1D�q���ܽ�g߃��{\xÃ}_����4h�K a�!��_}r�_<����}�+�u��C ֥��7�p��9�'��"�
|
||||
]�
|
||||
֯'Vn�ƫV����< p<-�-���Z�28��Wlx���/=�����w`|f���r�b��_�p��j?��[((F'��CzG@d�� qX�� tr�2N��l�&=XS�*�-�6&��u�?q�^ݹs�{�M~ v�lD�m�<��ן7Ơ�81�����Ɋ��S���t���G?�����8�VvuҖr�"��^0q`����ek��q.O�K.����\��餉�E��r��� �Y[�lYS˾i���0��������s�vE���ryo���Ƕ��H�) ��Q�fl�4�A!���=���|���O����5�%�ka�ٵ8��{�� h���c_��<�c8�����"�B�4GGGt���&�8�`c�f����i��1��#Ә�u��qQ�����x͖��\���ڟ?�ҾbwQ#E��F�
|
||||
��r�o\��Ϡ�<��������TY|M��4�&�Dq*�`��Mœ���qJ�&B@?��t̀4����W,���=�i�'���� VǑ� �7l��?
|
||||
��I|��/��Ɍ&�"�ZH��ie� Q��I_�������u�74�u�͙�w �e��գ˾��</�M̫8y+��6[+���VS|�� �H xUB���Ͻt�ѭ'�O�����A|�W�8D�r z~��
|
||||
�63��-�ҷ^���J 2�-��D���bc��\��0|�H"�[6"�f����n?���N<w�Jkz�`���uI����z�+
|
||||
o1���)gt2�$�B�I��e��=ӟ�6���J-��^op�
|
||||
����ѐ�A!X�74�3�iT&1,$$dW4���ڌȬISLm)5(D"T��������$��T_z��z�o�-�� ��w����[/V+����A;cc����%�婱�CCZ��8Ws�i�4��C�#��d�owM=�}ꩣ��yyIe2��1�%��Fk1�����z��M�@.��b���L�=d��T<�F�ʙZH�OL+��mܣ���`�����u����_"�i� ��C��Giܽ��j6��p{�t�-�ɔ+B�](��:�z�����1����f���<����L����Xl�`-�<?X��Y���x�z
|
||||
g�`f0�P�w���Ûz߸�kC_ ¹"����j���+�<e�e t�Ell�:�{<$
|
||||
.
|
||||
қx�۲�x�8nY�q����M�T�c굵����{������04�m?����X���WN�ԧ*��S3����D���Qi<�F�2�,�s����+��ԭWil���Y���e=ޭ��\��Ƶ]���"����ҥ~`w���G��l*;�hmt�V�R�r}����H�ֱr��"Ñ6���@�94�d�!4�u�n��ۍ���6~�]���r�\���;Uy���z]�rx�]GÈw��sr�0C�����!x*bT�!�d1;D���e�*n��s�@ àcA]?T�ou�-�{n��8\Z�sĊ`-M�ݘ�*/�(?
|
||||
.�!�-�:��t��L�~�Ư<�];�IF��T��jxl������N��<�w��f<r�
|
||||
��ɐR��O��P)��':8�L�Ita
|
||||
�"��OtI[1G&��7筥�&������\$NU�C�Uü{l���Ȝ��'NO�"4V�1 �� ���[�hz��� b`�������vݻ���B��T $�%,.�>IJ?Ty����8
|
||||
F�өdJDgmY��deˆ�b��9��Բ��v0�f�;�nkf�<S[�_>2��_m��iͮS���f�ቪ� ́��X9::��cըqJϤG�}��? ���X,���
|
||||
mx�����Λc��LdfB�͉�>>��3щJtlF���U�TM�#.�f&4H&�ĸ�ACv~"^
|
||||
�u��w�v�1R�iEaM�O-x�v�E��c*3�m?�l}ZO�!�a+=�����t��b�j�49^�8�˰���4�&��s*�k9�\ ֯����6o����R�̩������>6��τ�+�DE���Su3Uӓu3]7u+Uk�{j�#U�7�(ݻ�t���U�
|
||||
\8{�j�9;�t94Su���S�CK�4�3c�\����z!<��TI�4�&b�`�����a��j�Kת�����n�Mw��l{�.�#�<��.5"XB>�Ǝ�v�T���>u��$0�6&��L�*p���hlL�
|
||||
��N�a�D��uS��{ӻ���W��l�r'5�}j��wkm�+�ɣ�s�2�&��TP[Q��.O�������*���%�"XB�1&<�������N=}
|
||||
d�K��k��-������:���EKX����}�£���cs!]�R��t��ʁw�S�7�93�M�` ��YŃ�<�]��Jt�)O�a@����:�z����¦k�}�BkD��%�����S߿#:�_��l�
|
||||
�ud���]�� ;R�����h��L�t���������|
|
||||
"X� �,Ar��5,Qr�'���,�8�3.����_��!R"|�C�����?��.���lE�<EJ4���`]��.�U��Í�]���4Ψ�����:�]�H�`�#�).�l�P��ٺ8��FQ@��� O���\Gk
|
||||
��s��O��B�
|
||||
����� k��&}Dl��M��=�G;æ�O�ʬ�k�a)
|
||||
����f�� "e�&i�g-\�ZM��Dd��2F� rO�R
|
||||
�,�D���L ���%!XM2�H��:�/[�j��� �L�3@��[ZU�.x��Y��zbq�\�h�c�uA�☹3�\��fA�����VU�r�Et0���ZM��M_��� Vw���dU)�D�D�Y�
|
||||
�N%�]b�%FwG~w�%!X����X�6��h���`�,�
|
||||
�짹= ȊKf����^ ����CĖ����L� ��ٸ��6�����E����J t��������&�����Y֢�4��Z��zEDJ)E��BR��3�
|
||||
�L!�<��-0y�),M��4��u�nžmr�p�s���:9Nl�"�a��z��gl�J��+��G�5]c����$[��KBTJ)"2�"c�R�P��^e��{.)�ZB��\��Ί��J��V��XT�1�X��U��x��cI���;'9H�& ���7{υ^�vgK���.m�tI
|
||||
���Y{"4 �B�]�g�{�z�A ���0"2"h���c��ye���J13��hIkC�̔��-���&X�Ėf6i�9��F�"X���̝��iUqh<�[�a�pc ���P�Κ�?c6������5x͉��]��C�S��
|
||||
Rl�o��e�6�i�'" �8J�q�zZg������x�D��,�� ����f�jQ�3۞J6�{��6��Y��]H�YY�j:�E�R���$-�A��d�Tf2{B��7���W�汰ZJ���o�)�>�w���#d"��
|
||||
2��9��L�deb�$S"7Y�
|
||||
g[OMO�#X�BA�N�v��e-%`�:7̲����}�>m�E���b�ԧ�N��[�#�D���[��\-�C����Eι�Y��e���/w�������˳��tEK��1���ZS��_�T� ��܊��W���Hζ�fd�+�hYB�s��g��摘Vv�>@��mJ;�f�ø�BR�ó�s�GH��gvrͥqM��I��L\��k�F�����܂��c[έ�lm�D�2��v��{�p�O��B9LJZ
|
||||
,-��,�H�%�$��<z�����\��$Y�E�a����L���)4�]ƿ�o�`�͕7���K�������N�O)�������i��v�����=�6h��������+p�e�J�f?�e�%�MMcZ��T������jXnR1�[�f?��Mk�?6�LV���$|�8 `�ex5��9���
|
||||
"X� �,Ar����Mֱ%��I IEND�B`�
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user