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

@ -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");