Merge pull request #10619 from nupplaphil/task/guzzlehttp

PSR-7 Part 1: Use Guzzle PSR-7 library for HTTPRequest->get()
This commit is contained in:
Hypolite Petovan 2021-08-22 18:11:30 -04:00 committed by GitHub
commit 2108be7e07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 461 additions and 201 deletions

View file

@ -32,7 +32,7 @@ use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\Register;
use Friendica\Network\CurlResult;
use Friendica\Network\IHTTPResult;
use Friendica\Protocol\Relay;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
@ -171,7 +171,7 @@ class GServer
if (($now - $contact_time) < (60 * 60 * 24)) {
return DateTimeFormat::utc('now +1 day');
}
// If the last contact was less than a week before then try again in a week
if (($now - $contact_time) < (60 * 60 * 24 * 7)) {
return DateTimeFormat::utc('now +1 week');
@ -671,18 +671,19 @@ class GServer
/**
* Detect server type by using the nodeinfo data
*
* @param string $url address of the server
* @param CurlResult $curlResult
* @param string $url address of the server
* @param IHTTPResult $httpResult
*
* @return array Server data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function fetchNodeinfo(string $url, CurlResult $curlResult)
private static function fetchNodeinfo(string $url, IHTTPResult $httpResult)
{
if (!$curlResult->isSuccess()) {
if (!$httpResult->isSuccess()) {
return [];
}
$nodeinfo = json_decode($curlResult->getBody(), true);
$nodeinfo = json_decode($httpResult->getBody(), true);
if (!is_array($nodeinfo) || empty($nodeinfo['links'])) {
return [];
@ -1748,8 +1749,8 @@ class GServer
*
* @param int $gsid Server id
* @param int $protocol Protocol id
* @return void
* @throws Exception
* @return void
* @throws Exception
*/
public static function setProtocol(int $gsid, int $protocol)
{
@ -1808,8 +1809,8 @@ class GServer
* Fetch the protocol of the given server
*
* @param int $gsid Server id
* @return int
* @throws Exception
* @return int
* @throws Exception
*/
public static function getProtocol(int $gsid)
{

View file

@ -495,6 +495,7 @@ class Photo
$type = $ret->getContentType();
} else {
$img_str = '';
$type = '';
}
if ($quit_on_error && ($img_str == "")) {

View file

@ -90,7 +90,7 @@ class Link
$curlResult = DI::httpRequest()->head($url, ['timeout' => $timeout]);
if ($curlResult->isSuccess()) {
if (empty($media['mimetype'])) {
return $curlResult->getHeader('Content-Type');
return $curlResult->getHeader('Content-Type')[0] ?? '';
}
}
return '';

View file

@ -170,10 +170,10 @@ class Media
$curlResult = DI::httpRequest()->head($media['url'], ['timeout' => $timeout]);
if ($curlResult->isSuccess()) {
if (empty($media['mimetype'])) {
$media['mimetype'] = $curlResult->getHeader('Content-Type');
$media['mimetype'] = $curlResult->getHeader('Content-Type')[0] ?? '';
}
if (empty($media['size'])) {
$media['size'] = (int)$curlResult->getHeader('Content-Length');
$media['size'] = (int)($curlResult->getHeader('Content-Length')[0] ?? 0);
}
} else {
Logger::notice('Could not fetch head', ['media' => $media]);