Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Fix YouTube embeds failing due to YouTube serving wrong OEmbed URLs (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored Feb 12, 2021
1 parent de0664d commit f8972d4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/services/fetch_oembed_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ def discover_endpoint!

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
Expand Down

0 comments on commit f8972d4

Please sign in to comment.