]> cat aescling's git repositories - mastodon.git/commitdiff
Fix fetch of remote image with multiple Content-Type headers (#7749)
authorYamagishi Kazutoshi <ykzts@desire.sh>
Wed, 6 Jun 2018 18:50:07 +0000 (03:50 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Wed, 6 Jun 2018 18:50:07 +0000 (20:50 +0200)
app/models/concerns/remotable.rb

index 90c6894e0ad0063e86bf7a13c8b086789d87b609..c17f19a60050bb1a0916b4a9c041aade37692ca0 100644 (file)
@@ -24,13 +24,14 @@ module Remotable
           Request.new(:get, url).perform do |response|
             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)
 
             if extname.nil?
-              matches  = response.headers['content-disposition']&.match(/filename="([^"]*)"/)
-              filename = matches.nil? ? parsed_url.path.split('/').last : matches[1]
-              extname  = filename.nil? ? '' : File.extname(filename)
+              disposition = response.headers.get('content-disposition').last
+              matches     = disposition&.match(/filename="([^"]*)"/)
+              filename    = matches.nil? ? parsed_url.path.split('/').last : matches[1]
+              extname     = filename.nil? ? '' : File.extname(filename)
             end
 
             basename = SecureRandom.hex(8)