mirror of
https://github.com/friendica/friendica
synced 2024-11-18 00:23:47 +00:00
Merge pull request #14416 from annando/no-fetchfull
The redundant function "fetchfull" is removed
This commit is contained in:
commit
a54dcd2eb3
6 changed files with 25 additions and 43 deletions
|
@ -18,6 +18,7 @@ use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||||
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
|
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
|
@ -87,7 +88,7 @@ class OEmbed
|
||||||
// but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯
|
// but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯
|
||||||
$href = str_replace(['http://www.youtube.com/', 'http://player.vimeo.com/'],
|
$href = str_replace(['http://www.youtube.com/', 'http://player.vimeo.com/'],
|
||||||
['https://www.youtube.com/', 'https://player.vimeo.com/'], $href);
|
['https://www.youtube.com/', 'https://player.vimeo.com/'], $href);
|
||||||
$result = DI::httpClient()->fetchFull($href . '&maxwidth=' . $a->getThemeInfoValue('videowidth'), HttpClientAccept::DEFAULT, 0, '', HttpClientRequest::SITEINFO);
|
$result = DI::httpClient()->get($href . '&maxwidth=' . $a->getThemeInfoValue('videowidth'), HttpClientAccept::DEFAULT, [HttpClientOptions::REQUEST => HttpClientRequest::SITEINFO]);
|
||||||
if ($result->isSuccess()) {
|
if ($result->isSuccess()) {
|
||||||
$json_string = $result->getBodyString();
|
$json_string = $result->getBodyString();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -557,11 +557,11 @@ class Installer
|
||||||
$help = "";
|
$help = "";
|
||||||
$error_msg = "";
|
$error_msg = "";
|
||||||
if (function_exists('curl_init')) {
|
if (function_exists('curl_init')) {
|
||||||
$fetchResult = DI::httpClient()->fetchFull($baseurl . "/install/testrewrite");
|
$fetchResult = DI::httpClient()->get($baseurl . "/install/testrewrite");
|
||||||
|
|
||||||
$url = Strings::normaliseLink($baseurl . "/install/testrewrite");
|
$url = Strings::normaliseLink($baseurl . "/install/testrewrite");
|
||||||
if ($fetchResult->getReturnCode() != 204) {
|
if ($fetchResult->getReturnCode() != 204) {
|
||||||
$fetchResult = DI::httpClient()->fetchFull($url);
|
$fetchResult = DI::httpClient()->get($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fetchResult->getReturnCode() != 204) {
|
if ($fetchResult->getReturnCode() != 204) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ use Friendica\Model\PushSubscriber;
|
||||||
use Friendica\Module\Response;
|
use Friendica\Module\Response;
|
||||||
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
|
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||||
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
|
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
|
@ -141,7 +142,7 @@ class PubSubHubBub extends \Friendica\BaseModule
|
||||||
$hub_callback = rtrim($hub_callback, ' ?&#');
|
$hub_callback = rtrim($hub_callback, ' ?&#');
|
||||||
$separator = parse_url($hub_callback, PHP_URL_QUERY) === null ? '?' : '&';
|
$separator = parse_url($hub_callback, PHP_URL_QUERY) === null ? '?' : '&';
|
||||||
|
|
||||||
$fetchResult = $this->httpClient->fetchFull($hub_callback . $separator . $params, HttpClientAccept::DEFAULT, 0, '', HttpClientRequest::PUBSUB);
|
$fetchResult = $this->httpClient->get($hub_callback . $separator . $params, HttpClientAccept::DEFAULT, [HttpClientOptions::REQUEST => HttpClientRequest::PUBSUB]);
|
||||||
$body = $fetchResult->getBodyString();
|
$body = $fetchResult->getBodyString();
|
||||||
$returnCode = $fetchResult->getReturnCode();
|
$returnCode = $fetchResult->getReturnCode();
|
||||||
|
|
||||||
|
|
|
@ -31,22 +31,6 @@ interface ICanSendHttpRequests
|
||||||
*/
|
*/
|
||||||
public function fetch(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = '', string $request = ''): string;
|
public function fetch(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = '', string $request = ''): string;
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 string $accept_content supply Accept: header with 'accept_content' as the value
|
|
||||||
* @param int $timeout Timeout in seconds, default system config value or 60 seconds
|
|
||||||
* @param string $cookiejar Path to cookie jar file
|
|
||||||
* @param string $request Request Type
|
|
||||||
*
|
|
||||||
* @return ICanHandleHttpResponses With all relevant information, 'body' contains the actual fetched content.
|
|
||||||
*/
|
|
||||||
public function fetchFull(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = '', string $request = ''): ICanHandleHttpResponses;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a GET to a URL.
|
* Send a GET to a URL.
|
||||||
*
|
*
|
||||||
|
|
|
@ -271,25 +271,21 @@ class HttpClient implements ICanSendHttpRequests
|
||||||
*/
|
*/
|
||||||
public function fetch(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = '', string $request = ''): string
|
public function fetch(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = '', string $request = ''): string
|
||||||
{
|
{
|
||||||
$ret = $this->fetchFull($url, $accept_content, $timeout, $cookiejar, $request);
|
try {
|
||||||
|
$ret = $this->get(
|
||||||
return $ret->getBodyString();
|
$url,
|
||||||
}
|
$accept_content,
|
||||||
|
[
|
||||||
/**
|
HttpClientOptions::TIMEOUT => $timeout,
|
||||||
* {@inheritDoc}
|
HttpClientOptions::COOKIEJAR => $cookiejar,
|
||||||
*/
|
HttpClientOptions::REQUEST => $request,
|
||||||
public function fetchFull(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = '', string $request = ''): ICanHandleHttpResponses
|
]
|
||||||
{
|
);
|
||||||
return $this->get(
|
return $ret->getBodyString();
|
||||||
$url,
|
} catch (\Throwable $th) {
|
||||||
$accept_content,
|
$this->logger->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
|
||||||
[
|
return '';
|
||||||
HttpClientOptions::TIMEOUT => $timeout,
|
}
|
||||||
HttpClientOptions::COOKIEJAR => $cookiejar,
|
|
||||||
HttpClientOptions::REQUEST => $request,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getUserAgent(string $type = ''): string
|
private function getUserAgent(string $type = ''): string
|
||||||
|
|
|
@ -353,11 +353,11 @@ class InstallerTest extends MockedTest
|
||||||
// Mocking the CURL Request
|
// Mocking the CURL Request
|
||||||
$networkMock = Mockery::mock(ICanSendHttpRequests::class);
|
$networkMock = Mockery::mock(ICanSendHttpRequests::class);
|
||||||
$networkMock
|
$networkMock
|
||||||
->shouldReceive('fetchFull')
|
->shouldReceive('get')
|
||||||
->with('https://test/install/testrewrite')
|
->with('https://test/install/testrewrite')
|
||||||
->andReturn($IHTTPResult);
|
->andReturn($IHTTPResult);
|
||||||
$networkMock
|
$networkMock
|
||||||
->shouldReceive('fetchFull')
|
->shouldReceive('get')
|
||||||
->with('http://test/install/testrewrite')
|
->with('http://test/install/testrewrite')
|
||||||
->andReturn($IHTTPResult);
|
->andReturn($IHTTPResult);
|
||||||
|
|
||||||
|
@ -400,11 +400,11 @@ class InstallerTest extends MockedTest
|
||||||
// Mocking the CURL Request
|
// Mocking the CURL Request
|
||||||
$networkMock = Mockery::mock(ICanSendHttpRequests::class);
|
$networkMock = Mockery::mock(ICanSendHttpRequests::class);
|
||||||
$networkMock
|
$networkMock
|
||||||
->shouldReceive('fetchFull')
|
->shouldReceive('get')
|
||||||
->with('https://test/install/testrewrite')
|
->with('https://test/install/testrewrite')
|
||||||
->andReturn($IHTTPResultF);
|
->andReturn($IHTTPResultF);
|
||||||
$networkMock
|
$networkMock
|
||||||
->shouldReceive('fetchFull')
|
->shouldReceive('get')
|
||||||
->with('http://test/install/testrewrite')
|
->with('http://test/install/testrewrite')
|
||||||
->andReturn($IHTTPResultW);
|
->andReturn($IHTTPResultW);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue