mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Onebox can match engines based on the content_type (#13876)
* FEATURE: Onebox can match engines based on the content_type `FinalDestination` now returns the `content_type` of a resolved URL. `Oneboxer` passes this value to `Onebox` itself. Onebox engines can now specify a `matches_content_type` regex of content_types that the engine can handle, regardless of the URL. `ImageOnebox` will match URLs with a content type of `image/png`, `jpg`, `gif`, `bmp`, `tif`, etc. This will allow images that exist at a URL without a file type extension to be correctly rendered, assuming a valid `content_type` is returned.
This commit is contained in:
@@ -21,7 +21,13 @@ module Onebox
|
||||
return if @uri.nil?
|
||||
return if @uri.port && !Onebox.options.allowed_ports.include?(@uri.port)
|
||||
return if @uri.scheme && !Onebox.options.allowed_schemes.include?(@uri.scheme)
|
||||
ordered_engines.find { |engine| engine === @uri && has_allowed_iframe_origins?(engine) }
|
||||
|
||||
ordered_engines.find do |engine|
|
||||
(
|
||||
engine.respond_to?(:handles_content_type?) && engine.handles_content_type?(@options[:content_type]) ||
|
||||
engine === @uri
|
||||
) && has_allowed_iframe_origins?(engine)
|
||||
end
|
||||
end
|
||||
|
||||
def has_allowed_iframe_origins?(engine)
|
||||
|
||||
Reference in New Issue
Block a user