Fix YouTube embeds failing due to YouTube serving wrong OEmbed URLs (#15716)
This commit is contained in:
		
							parent
							
								
									a042276ae4
								
							
						
					
					
						commit
						0baa928e56
					
				
					 1 changed files with 11 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue