A lot of Fixings

This commit is contained in:
Philipp 2021-08-20 20:05:41 +02:00
parent 06371d29a6
commit 65ca164487
No known key found for this signature in database
GPG key ID: 9A28B7D4FF5667BD
7 changed files with 16 additions and 25 deletions

View file

@ -1195,7 +1195,7 @@ class BBCode
if (is_null($text)) { if (is_null($text)) {
$curlResult = DI::httpRequest()->head($match[1], ['timeout' => DI::config()->get('system', 'xrd_timeout')]); $curlResult = DI::httpRequest()->head($match[1], ['timeout' => DI::config()->get('system', 'xrd_timeout')]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$mimetype = $curlResult->getHeader('Content-Type'); $mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
} else { } else {
$mimetype = ''; $mimetype = '';
} }
@ -1266,7 +1266,7 @@ class BBCode
$curlResult = DI::httpRequest()->head($match[1], ['timeout' => DI::config()->get('system', 'xrd_timeout')]); $curlResult = DI::httpRequest()->head($match[1], ['timeout' => DI::config()->get('system', 'xrd_timeout')]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$mimetype = $curlResult->getHeader('Content-Type'); $mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
} else { } else {
$mimetype = ''; $mimetype = '';
} }

View file

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

View file

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

View file

@ -145,4 +145,10 @@ class GuzzleResponse extends Response implements IHTTPResult, ResponseInterface
{ {
return $this->isTimeout; return $this->isTimeout;
} }
/// @todo - fix mismatching use of "getBody()" as string here and parent "getBody()" as streaminterface
public function getBody()
{
return parent::getBody()->getContents();
}
} }

View file

@ -72,7 +72,7 @@ class HTTPRequest implements IHTTPRequest
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function get(string $url, bool $binary = false, array $opts = []) public function get(string $url, array $opts = [])
{ {
$this->profiler->startRecording('network'); $this->profiler->startRecording('network');
@ -193,10 +193,6 @@ class HTTPRequest implements IHTTPRequest
$curlOptions[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; $curlOptions[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
} }
if ($binary) {
$curlOptions[CURLOPT_BINARYTRANSFER] = 1;
}
$logger = $this->logger; $logger = $this->logger;
$onRedirect = function( $onRedirect = function(
@ -223,7 +219,6 @@ class HTTPRequest implements IHTTPRequest
'referer' => true, 'referer' => true,
], ],
'on_headers' => $onHeaders, 'on_headers' => $onHeaders,
'sink' => tempnam(get_temppath(), 'guzzle'),
'curl' => $curlOptions 'curl' => $curlOptions
]); ]);

View file

@ -424,16 +424,11 @@ class Probe
*/ */
private static function getHideStatus($url) private static function getHideStatus($url)
{ {
$curlResult = DI::httpRequest()->get($url, false, ['content_length' => 1000000]); $curlResult = DI::httpRequest()->get($url, ['content_length' => 1000000]);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return false; return false;
} }
// If the file is too large then exit
if (($curlResult->getInfo()['download_content_length'] ?? 0) > 1000000) {
return false;
}
// If it isn't a HTML file then exit // If it isn't a HTML file then exit
if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) { if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
return false; return false;

View file

@ -63,7 +63,7 @@ class ParseUrl
return []; return [];
} }
$contenttype = $curlResult->getHeader('Content-Type'); $contenttype = $curlResult->getHeader('Content-Type')[0] ?? '';
if (empty($contenttype)) { if (empty($contenttype)) {
return []; return [];
} }
@ -213,19 +213,14 @@ class ParseUrl
return $siteinfo; return $siteinfo;
} }
$curlResult = DI::httpRequest()->get($url, false, ['content_length' => 1000000]); $curlResult = DI::httpRequest()->get($url, ['content_length' => 1000000]);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
return $siteinfo; return $siteinfo;
} }
$siteinfo['expires'] = DateTimeFormat::utc(self::DEFAULT_EXPIRATION_SUCCESS); $siteinfo['expires'] = DateTimeFormat::utc(self::DEFAULT_EXPIRATION_SUCCESS);
// If the file is too large then exit if ($cacheControlHeader = $curlResult->getHeader('Cache-Control')[0] ?? '') {
if (($curlResult->getInfo()['download_content_length'] ?? 0) > 1000000) {
return $siteinfo;
}
if ($cacheControlHeader = $curlResult->getHeader('Cache-Control')) {
if (preg_match('/max-age=([0-9]+)/i', $cacheControlHeader, $matches)) { if (preg_match('/max-age=([0-9]+)/i', $cacheControlHeader, $matches)) {
$maxAge = max(86400, (int)array_pop($matches)); $maxAge = max(86400, (int)array_pop($matches));
$siteinfo['expires'] = DateTimeFormat::utc("now + $maxAge seconds"); $siteinfo['expires'] = DateTimeFormat::utc("now + $maxAge seconds");