]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/ParseUrl.php
Merge pull request #11150 from annando/user-banner
[friendica.git] / src / Util / ParseUrl.php
index 83af765c5c8824e492a915091127914fae7486f0..2763f56abf52aefc8090779b7fca8090906478ab 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,6 +60,12 @@ 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 [];
                }
@@ -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;
                }