Add `accept-language` header to Unfurling requests
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 17 Feb 2023 11:24:38 +0000 (12:24 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 17 Feb 2023 11:24:38 +0000 (12:24 +0100)
The default language is preferred, but any language is acceptable with a lower
priority.

see https://www.woltlab.com/community/thread/299002-imdb-english-embed-links-displaying-german-text/

wcfsetup/install/files/lib/system/message/unfurl/UnfurlResponse.class.php

index 2e8eb680ad767670c27e7932c2055aae83eacbd1..9aa30bfbc02111d110e9cffb72333a8ec129dae6 100644 (file)
@@ -13,6 +13,7 @@ use Psr\Http\Client\ClientExceptionInterface;
 use ValueError;
 use wcf\system\io\http\RedirectGuard;
 use wcf\system\io\HttpFactory;
+use wcf\system\language\LanguageFactory;
 use wcf\system\message\unfurl\exception\DownloadFailed;
 use wcf\system\message\unfurl\exception\ParsingFailed;
 use wcf\system\message\unfurl\exception\UrlInaccessible;
@@ -90,10 +91,13 @@ final class UnfurlResponse
         }
 
         try {
+            $defaultLanguage = LanguageFactory::getInstance()->getDefaultLanguage();
+
             $request = new Request('GET', $url, [
                 'accept' => 'text/html',
                 'range' => \sprintf('bytes=%d-%d', 0, self::MAX_SIZE - 1),
                 'accept-encoding' => 'gzip',
+                'accept-language' => "{$defaultLanguage->languageCode}, *; q=0.1"
             ]);
             $response = self::getHttpClient()->send($request);