]> cat aescling's git repositories - mastodon.git/commitdiff
Fix YouTube embeds failing due to YouTube serving wrong OEmbed URLs (#15716)
authorEugen Rochko <eugen@zeonfederated.com>
Fri, 12 Feb 2021 04:45:38 +0000 (05:45 +0100)
committerGitHub <noreply@github.com>
Fri, 12 Feb 2021 04:45:38 +0000 (05:45 +0100)
app/services/fetch_oembed_service.rb

index 67e33875c68fda51523447995ac5a9e89fb24f27..60be9b9dc09e584c0da24b60ce1922901e1d4c08 100644 (file)
@@ -38,7 +38,17 @@ class FetchOEmbedService
 
     return if @endpoint_url.blank?
 
-    @endpoint_url = (Addressable::URI.parse(@url) + @endpoint_url).to_s
+    @endpoint_url = begin
+      base_url = Addressable::URI.parse(@url)
+
+      # If the OEmbed endpoint is given as http but the URL we opened
+      # was served over https, we can assume OEmbed will be available
+      # through https as well
+
+      (base_url + @endpoint_url).tap do |absolute_url|
+        absolute_url.scheme = base_url.scheme if base_url.scheme == 'https'
+      end.to_s
+    end
 
     cache_endpoint!
   rescue Addressable::URI::InvalidURIError