FIX: Request html when fetching inline onebox data (#24674)

We do expect to receive html
This commit is contained in:
Jarek Radosz 2023-12-04 02:36:42 +01:00 committed by GitHub
parent eada155dcd
commit 74011232e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 9 deletions

View File

@ -86,6 +86,7 @@ class FinalDestination
end end
) )
@stop_at_blocked_pages = @opts[:stop_at_blocked_pages] @stop_at_blocked_pages = @opts[:stop_at_blocked_pages]
@extra_headers = @opts[:headers]
end end
def self.connection_timeout def self.connection_timeout
@ -120,6 +121,7 @@ class FinalDestination
"Host" => @uri.hostname + (@include_port_in_host_header ? ":#{@uri.port}" : ""), "Host" => @uri.hostname + (@include_port_in_host_header ? ":#{@uri.port}" : ""),
} }
result.merge!(@extra_headers) if @extra_headers
result["Cookie"] = @cookie if @cookie result["Cookie"] = @cookie if @cookie
result result

View File

@ -78,6 +78,9 @@ module RetrieveTitle
stop_at_blocked_pages: true, stop_at_blocked_pages: true,
max_redirects: max_redirects, max_redirects: max_redirects,
initial_https_redirect_ignore_limit: initial_https_redirect_ignore_limit, initial_https_redirect_ignore_limit: initial_https_redirect_ignore_limit,
headers: {
Accept: "text/html,*/*",
},
) )
current = nil current = nil

View File

@ -1,18 +1,13 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe TopicLink do RSpec.describe TopicLink do
it { is_expected.to validate_presence_of :url } let(:test_uri) { URI.parse(Discourse.base_url) }
def test_uri
URI.parse(Discourse.base_url)
end
fab!(:topic) { Fabricate(:topic, title: "unique topic name") } fab!(:topic) { Fabricate(:topic, title: "unique topic name") }
fab!(:user) { topic.user } fab!(:user) { topic.user }
fab!(:post) fab!(:post)
it { is_expected.to validate_presence_of :url }
it "can't link to the same topic" do it "can't link to the same topic" do
ftl = TopicLink.new(url: "/t/#{topic.id}", topic_id: topic.id, link_topic_id: topic.id) ftl = TopicLink.new(url: "/t/#{topic.id}", topic_id: topic.id, link_topic_id: topic.id)
expect(ftl.valid?).to eq(false) expect(ftl.valid?).to eq(false)
@ -25,7 +20,7 @@ RSpec.describe TopicLink do
# prepare a title for one of the links # prepare a title for one of the links
stub_request(:get, non_png).with( stub_request(:get, non_png).with(
headers: { headers: {
"Accept" => "*/*", "Accept" => "text/html,*/*",
"Accept-Encoding" => "gzip", "Accept-Encoding" => "gzip",
"Host" => "b.com", "Host" => "b.com",
}, },
@ -273,6 +268,7 @@ RSpec.describe TopicLink do
let(:post) do let(:post) do
Fabricate(:post, topic: topic, user: user, raw: "<a href='/faq'>faq link here</a>") Fabricate(:post, topic: topic, user: user, raw: "<a href='/faq'>faq link here</a>")
end end
before { TopicLink.extract_from(post) } before { TopicLink.extract_from(post) }
it "does not extract a link" do it "does not extract a link" do