mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08: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:
@ -42,6 +42,13 @@ describe FinalDestination do
|
||||
}
|
||||
end
|
||||
|
||||
let(:image_response) do
|
||||
{
|
||||
status: 200,
|
||||
headers: { "Content-Type" => "image/jpeg" }
|
||||
}
|
||||
end
|
||||
|
||||
def redirect_response(from, dest)
|
||||
stub_request(:head, from).to_return(
|
||||
status: 302,
|
||||
@ -317,6 +324,19 @@ describe FinalDestination do
|
||||
expect(final.resolve.to_s).to eq("#{upstream_url}#L154-L205")
|
||||
expect(final.status).to eq(:resolved)
|
||||
end
|
||||
|
||||
context "content_type" do
|
||||
before do
|
||||
stub_request(:head, "https://eviltrout.com/this/is/an/image").to_return(image_response)
|
||||
end
|
||||
|
||||
it "returns a content_type" do
|
||||
final = FinalDestination.new("https://eviltrout.com/this/is/an/image", opts)
|
||||
expect(final.resolve.to_s).to eq("https://eviltrout.com/this/is/an/image")
|
||||
expect(final.content_type).to eq("image/jpeg")
|
||||
expect(final.status).to eq(:resolved)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.get' do
|
||||
|
Reference in New Issue
Block a user