aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2021-02-12 05:45:38 +0100
committerGitHub <noreply@github.com>2021-02-12 05:45:38 +0100
commitf8972d45032dce3f026a57cc3bdcafe4c0ab89d9 (patch)
tree67914007d493e3ab615cd08bc2d849d189ea58e0
parentde0664de2cfafa419b2e7c34ee7fdb0cb51a8a2a (diff)
downloadmastodon-f8972d45032dce3f026a57cc3bdcafe4c0ab89d9.tar
mastodon-f8972d45032dce3f026a57cc3bdcafe4c0ab89d9.tar.gz
mastodon-f8972d45032dce3f026a57cc3bdcafe4c0ab89d9.tar.bz2
mastodon-f8972d45032dce3f026a57cc3bdcafe4c0ab89d9.zip
Fix YouTube embeds failing due to YouTube serving wrong OEmbed URLs (#15716)
-rw-r--r--app/services/fetch_oembed_service.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/services/fetch_oembed_service.rb b/app/services/fetch_oembed_service.rb
index 67e33875c..60be9b9dc 100644
--- a/app/services/fetch_oembed_service.rb
+++ b/app/services/fetch_oembed_service.rb
@@ -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