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:
jbrw
2021-07-30 13:36:30 -04:00
committed by GitHub
parent f0d048b42a
commit 2f28ba318c
9 changed files with 65 additions and 3 deletions

View File

@ -50,6 +50,18 @@ describe Onebox::Engine do
end
end
describe "handles_content_type?" do
class OneboxEngineImages
include Onebox::Engine
@@matcher_content_type = /^image\/png$/
end
it "returns true if argument matches the matcher" do
result = OneboxEngineImages.handles_content_type?('image/png')
expect(result).to eq(true)
end
end
class AlwaysHttpsEngineExample < OneboxEngineExample
always_https
end