mirror of
https://github.com/friendica/friendica
synced 2025-04-26 10:30:11 +00:00
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:
commit
2108be7e07
21 changed files with 461 additions and 201 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -495,6 +495,7 @@ class Photo
|
|||
$type = $ret->getContentType();
|
||||
} else {
|
||||
$img_str = '';
|
||||
$type = '';
|
||||
}
|
||||
|
||||
if ($quit_on_error && ($img_str == "")) {
|
||||
|
|
|
@ -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 '';
|
||||
|
|
|
@ -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]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue