Permalink
Browse files

Merge remote-tracking branch 'internal/public_right_aws' into develop…

…ment
  • Loading branch information...
2 parents f21f6b7 + beb1a0e commit af0c8ed87aa901432b0672089156c31853a9c770 @konstantin-dzreev konstantin-dzreev committed Feb 21, 2012
View
@@ -333,4 +333,9 @@ the source key.
- SignatureDoesNotMatch on file download via get_link()
- S3#bucket should not fail for non admin creds
- couple doc typos
-
+
+=== 3.0.2
+ Release Notes:
+ - Fixed:
+ - S3 Content-Type not set in Ruby 1.9.2
+ - error in rds_interface describe_db_snapshots in Ruby 1.9.2
@@ -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
@@ -43,9 +43,10 @@ def self.sign(aws_secret_access_key, auth_string)
Base64.encode64(OpenSSL::HMAC.digest(@@digest1, aws_secret_access_key, auth_string)).strip
end
- # Escape a string accordingly Amazon rulles
+ # Escape a string accordingly Amazon rules
# http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/index.html?REST_RESTAuth.html
def self.amz_escape(param)
+ param = param.flatten.join('') if param.is_a?(Array) # ruby 1.9.x Array#to_s fix
param.to_s.gsub(/([^a-zA-Z0-9._~-]+)/n) do
'%' + $1.unpack('H2' * $1.size).join('%').upcase
end
@@ -66,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)
View
@@ -2,7 +2,7 @@ module RightAws #:nodoc:
module VERSION #:nodoc:
MAJOR = 3 unless defined?(MAJOR)
MINOR = 0 unless defined?(MINOR)
- TINY = 1 unless defined?(TINY)
+ TINY = 2 unless defined?(TINY)
STRING = [MAJOR, MINOR, TINY].join('.') unless defined?(STRING)
end
@@ -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
@@ -866,8 +866,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 af0c8ed

Please sign in to comment.