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

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]);

View file

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

View file

@ -424,16 +424,11 @@ class Probe
*/
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()) {
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 (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
return false;

View file

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