FIX: follow redirects for inline/mini onebox (#13512)
This commit is contained in:
parent
a2b744ae25
commit
0adeddde61
|
@ -57,12 +57,13 @@ module RetrieveTitle
|
|||
encoding = nil
|
||||
|
||||
fd.get do |_response, chunk, uri|
|
||||
|
||||
unless Net::HTTPRedirection === _response
|
||||
if current
|
||||
current << chunk
|
||||
else
|
||||
current = chunk
|
||||
end
|
||||
|
||||
if !encoding && content_type = _response['content-type']&.strip&.downcase
|
||||
if content_type =~ /charset="?([a-z0-9_-]+)"?/
|
||||
encoding = Regexp.last_match(1)
|
||||
|
@ -76,6 +77,7 @@ module RetrieveTitle
|
|||
title = extract_title(current, encoding)
|
||||
throw :done if title || max_size < current.length
|
||||
end
|
||||
end
|
||||
title
|
||||
end
|
||||
end
|
||||
|
|
|
@ -89,5 +89,16 @@ describe RetrieveTitle do
|
|||
IPSocket.stubs(:getaddress).returns('100.2.3.4')
|
||||
expect(RetrieveTitle.crawl("https://brelksdjflaskfj.com/amazing")).to eq("japanese こんにちは website")
|
||||
end
|
||||
|
||||
it "can follow redirect" do
|
||||
stub_request(:get, "http://foobar.com/amazing").
|
||||
to_return(status: 301, body: "", headers: { "location" => "https://wikipedia.com/amazing" })
|
||||
|
||||
stub_request(:get, "https://wikipedia.com/amazing").
|
||||
to_return(status: 200, body: "<html><title>very amazing</title>", headers: {})
|
||||
|
||||
IPSocket.stubs(:getaddress).returns('100.2.3.4')
|
||||
expect(RetrieveTitle.crawl("http://foobar.com/amazing")).to eq("very amazing")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue