Permalink
Browse files

refs #11938, fix for: S3 Content-Type not set in Ruby 1.9.2

  • Loading branch information...
1 parent b9c0d76 commit 1dc181981da47e3ad80376a2333eefe5cfec7265 @konstantin-dzreev konstantin-dzreev committed Feb 21, 2012
@@ -126,6 +126,7 @@ def generate_request(method, path, params={}, body=nil, headers={}) # :nodoc:
path += "?" + params.to_a.collect{ |key,val| "#{AwsUtils::amz_escape(key)}=#{AwsUtils::amz_escape(val.to_s)}" }.join("&")
end
# Headers
+ headers = AwsUtils::fix_headers(headers)
headers['content-type'] ||= 'text/xml' if body
headers['date'] = Time.now.httpdate
# Auth
@@ -67,6 +67,16 @@ def self.fix_service_params(service_hash, signature)
service_hash
end
+ def self.fix_headers(headers)
+ result = {}
+ headers.each do |header, value|
+ next if !header.is_a?(String) || value.nil?
+ header = header.downcase
+ result[header] = value if result[header].right_blank?
+ end
+ result
+ end
+
# Signature Version 0
# A deprecated guy (should work till septemper 2009)
def self.sign_request_v0(aws_secret_access_key, service_hash)
@@ -206,6 +206,7 @@ def generate_request(method, path, params={}, body=nil, headers={}) # :nodoc:
path += "?" + params.to_a.collect{ |key,val| "#{AwsUtils::amz_escape(key)}=#{AwsUtils::amz_escape(val.to_s)}" }.join("&")
end
# Headers
+ headers = AwsUtils::fix_headers(headers)
headers['content-type'] ||= 'text/xml' if body
headers['date'] = Time.now.httpdate
# Auth
@@ -175,8 +175,8 @@ def generate_rest_request(method, headers) # :nodoc:
# calculate request data
server, path, path_to_sign = fetch_request_params(headers)
data = headers[:data]
- # remove unset(==optional) and symbolyc keys
- headers.each{ |key, value| headers.delete(key) if (value.nil? || key.is_a?(Symbol)) }
+ # make sure headers are downcased strings
+ headers = AwsUtils::fix_headers(headers)
#
headers['content-type'] ||= ''
headers['date'] = Time.now.httpdate
@@ -861,8 +861,8 @@ def generate_link(method, headers={}, expires=nil) #:nodoc:
expires ||= DEFAULT_EXPIRES_AFTER
expires = Time.now.utc + expires if expires.is_a?(Fixnum) && (expires < ONE_YEAR_IN_SECONDS)
expires = expires.to_i
- # remove unset(==optional) and symbolyc keys
- headers.each{ |key, value| headers.delete(key) if (value.nil? || key.is_a?(Symbol)) }
+ # make sure headers are downcased strings
+ headers = AwsUtils::fix_headers(headers)
#generate auth strings
auth_string = canonical_string(method, path_to_sign, headers, expires)
signature = CGI::escape(AwsUtils::sign( @aws_secret_access_key, auth_string))

0 comments on commit 1dc1819

Please sign in to comment.