]> 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 d65ec0bb5542cd56de2e7ba365d27d902ac94dae..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;
                }
 
@@ -455,7 +462,7 @@ class ParseUrl
                                                $siteinfo['language'] = trim($meta_tag['content']);
                                                break;
                                        case 'og:type':
-                                               $siteinfo['type'] = trim($meta_tag['content']);
+                                               $siteinfo['pagetype'] = trim($meta_tag['content']);
                                                break;
                                        case 'twitter:description':
                                                $siteinfo['text'] = trim($meta_tag['content']);