diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-10 23:30:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-10 23:30:07 +0200 |
commit | a231f915a0734d1089ca76dbd7f4593ef63e8764 (patch) | |
tree | 7e60f17290231fad1cd254cfd2d9e06699c4685e /app | |
parent | c3ef5d5414ac1fee5471d7063616a4b72a408e11 (diff) |
Fix #2955 - Send HEAD request ahead of GET when fetching URL previews (#2972)
Diffstat (limited to 'app')
-rw-r--r-- | app/services/fetch_link_card_service.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb index 524b66626..27d7c2a70 100644 --- a/app/services/fetch_link_card_service.rb +++ b/app/services/fetch_link_card_service.rb @@ -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 |