mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
Fix fetch of remote image with multiple Content-Type headers (#7749)
This commit is contained in:
parent
c75493755f
commit
683707839f
@ -24,13 +24,14 @@ module Remotable
|
|||||||
Request.new(:get, url).perform do |response|
|
Request.new(:get, url).perform do |response|
|
||||||
next if response.code != 200
|
next if response.code != 200
|
||||||
|
|
||||||
content_type = parse_content_type(response.headers['content-type'])
|
content_type = parse_content_type(response.headers.get('content-type').last)
|
||||||
extname = detect_extname_from_content_type(content_type)
|
extname = detect_extname_from_content_type(content_type)
|
||||||
|
|
||||||
if extname.nil?
|
if extname.nil?
|
||||||
matches = response.headers['content-disposition']&.match(/filename="([^"]*)"/)
|
disposition = response.headers.get('content-disposition').last
|
||||||
filename = matches.nil? ? parsed_url.path.split('/').last : matches[1]
|
matches = disposition&.match(/filename="([^"]*)"/)
|
||||||
extname = filename.nil? ? '' : File.extname(filename)
|
filename = matches.nil? ? parsed_url.path.split('/').last : matches[1]
|
||||||
|
extname = filename.nil? ? '' : File.extname(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
basename = SecureRandom.hex(8)
|
basename = SecureRandom.hex(8)
|
||||||
|
Loading…
Reference in New Issue
Block a user