1
0
mirror of https://github.com/whippyshou/mastodon synced 2024-11-24 23:26:31 +09:00

Fix #2955 - Send HEAD request ahead of GET when fetching URL previews (#2972)

This commit is contained in:
Eugen Rochko 2017-05-10 23:30:07 +02:00 committed by GitHub
parent c3ef5d5414
commit a231f915a0
2 changed files with 6 additions and 1 deletions

View File

@ -11,8 +11,12 @@ class FetchLinkCardService < BaseService
return if url.nil?
url = Addressable::URI.parse(url).normalize.to_s
url = Addressable::URI.parse(url).normalize.to_s
card = PreviewCard.where(status: status).first_or_initialize(status: status, url: url)
res = http_client.head(url)
return if res.code != 200 || res.mime_type != 'text/html'
attempt_opengraph(card, url) unless attempt_oembed(card, url)
end

View File

@ -2,6 +2,7 @@ require 'rails_helper'
RSpec.describe FetchLinkCardService do
before do
stub_request(:head, 'http://example.xn--fiqs8s/').to_return(status: 200, headers: { 'Content-Type' => 'text/html' })
stub_request(:get, 'http://example.xn--fiqs8s/').to_return(request_fixture('idn.txt'))
end