From 4853a2badaef7916c90e2fc546c9d7551ce8a706 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Thu, 1 Aug 2024 11:14:24 +0200 Subject: [PATCH] Add Accept-Language header when fetching preview card (#31232) --- app/services/fetch_link_card_service.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb index adabb1096..49b820557 100644 --- a/app/services/fetch_link_card_service.rb +++ b/app/services/fetch_link_card_service.rb @@ -45,7 +45,13 @@ class FetchLinkCardService < BaseService def html return @html if defined?(@html) - @html = Request.new(:get, @url).add_headers('Accept' => 'text/html', 'User-Agent' => "#{Mastodon::Version.user_agent} Bot").perform do |res| + headers = { + 'Accept' => 'text/html', + 'Accept-Language' => "#{I18n.default_locale}, *;q=0.5", + 'User-Agent' => "#{Mastodon::Version.user_agent} Bot", + } + + @html = Request.new(:get, @url).add_headers(headers).perform do |res| next unless res.code == 200 && res.mime_type == 'text/html' # We follow redirects, and ideally we want to save the preview card for