]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/ParseUrl.php
Hash the URL before using it as cache key in Util\Images::getInfoFromURLCached
[friendica.git] / src / Util / ParseUrl.php
index 83af765c5c8824e492a915091127914fae7486f0..24be55cab931ced253b360a51070f93852dcb0d0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -60,13 +60,19 @@ class ParseUrl
        public static function getContentType(string $url)
        {
                $curlResult = DI::httpClient()->head($url);
+
+               // Workaround for systems that can't handle a HEAD request
+               if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
+                       $curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000]);
+               }
+
                if (!$curlResult->isSuccess()) {
                        return [];
                }
 
                $contenttype =  $curlResult->getHeader('Content-Type')[0] ?? '';
                if (empty($contenttype)) {
-                       return [];
+                       return ['application', 'octet-stream'];
                }
 
                return explode('/', current(explode(';', $contenttype)));
@@ -216,6 +222,7 @@ class ParseUrl
 
                $curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000]);
                if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
+                       Logger::info('Empty body or error when fetching', ['url' => $url, 'success' => $curlResult->isSuccess(), 'code' => $curlResult->getReturnCode()]);
                        return $siteinfo;
                }