@private
@return [bucket] S3 bucket name
@private
@return [String] S3 object key
# File lib/aws/s3/request.rb, line 186 def query_parameters %w(response-content-type response-content-language response-expires response-cache-control response-content-disposition response-content-encoding) end
# File lib/aws/s3/request.rb, line 180 def sub_resources %w(acl location logging notification partNumber policy requestPayment torrent uploadId uploads versionId versioning versions delete lifecycle) end
CanonicalizedAmzHeaders
See the developer guide for more information on how this element is generated.
# File lib/aws/s3/request.rb, line 151 def canonicalized_headers x_amz = headers.select{|name, value| name.to_s =~ %r^x-amz-/ } x_amz = x_amz.collect{|name, value| [name.downcase, value] } x_amz = x_amz.sort_by{|name, value| name } x_amz = x_amz.collect{|name, value| "#{name}:#{value}" }.join("\n") x_amz == '' ? nil : x_amz end
From the S3 developer guide
CanonicalizedResource = [ "/" + Bucket ] + <HTTP-Request-URI, from the protocol name up to the querystring> + [ sub-resource, if present. e.g. "?acl", "?location", "?logging", or "?torrent"];
# File lib/aws/s3/request.rb, line 121 def canonicalized_resource parts = [] # virtual hosted-style requests require the hostname to appear # in the canonicalized resource prefixed by a forward slash. if Client.dns_compatible_bucket_name?(bucket) and !path_style? parts << "/#{bucket}" end # all requests require the portion of the un-decoded uri up to # but not including the query string parts << path # lastly any sub resource querystring params need to be appened # in lexigraphical ordered joined by '&' and prefixed by '?' params = (sub_resource_params + query_parameters_for_signature) unless params.empty? parts << '?' parts << params.sort.collect{|p| p.to_s }.join('&') end parts.join end
# File lib/aws/s3/request.rb, line 56 def host path_style? ? @host : "#{bucket}.#{@host}" end
# File lib/aws/s3/request.rb, line 34 def metadata= metadata Array(metadata).each do |name, value| headers["x-amz-meta-#{name}"] = value end end
# File lib/aws/s3/request.rb, line 60 def path_style? if force_path_style true else Client.path_style_bucket_name?(bucket) end end
# File lib/aws/s3/request.rb, line 163 def query_parameters_for_signature params.select { |p| self.class.query_parameters.include?(p.name) } end
# File lib/aws/s3/request.rb, line 48 def server_side_encryption= sse if sse.is_a?(Symbol) headers['x-amz-server-side-encryption'] = sse.to_s.upcase elsif sse headers['x-amz-server-side-encryption'] = sse end end
# File lib/aws/s3/request.rb, line 103 def signing_string_date # if a date is provided via x-amz-date then we should omit the # Date header from the signing string (should appear as a blank line) if headers.detect{|k,v| k.to_s =~ %r^x-amz-date$/ } '' else headers['date'] ||= Time.now.rfc822 end end
# File lib/aws/s3/request.rb, line 40 def storage_class= storage_class if storage_class.kind_of?(Symbol) headers["x-amz-storage-class"] = storage_class.to_s.upcase elsif storage_class headers["x-amz-storage-class"] = storage_class end end
From the S3 developer guide:
StringToSign =
HTTP-Verb + "\n" + content-md5 + "\n" + content-type + "\n" + date + "\n" + CanonicalizedAmzHeaders + CanonicalizedResource;
# File lib/aws/s3/request.rb, line 93 def string_to_sign [ http_method, headers.values_at('content-md5', 'content-type').join("\n"), signing_string_date, canonicalized_headers, canonicalized_resource, ].flatten.compact.join("\n") end
# File lib/aws/s3/request.rb, line 159 def sub_resource_params params.select{|p| self.class.sub_resources.include?(p.name) } end
# File lib/aws/s3/request.rb, line 68 def uri parts = [] parts << bucket if bucket and path_style? parts << escape_path(key) if key path = '/' + parts.join('/') querystring = url_encoded_params uri = '' uri << path uri << "?#{querystring}" if querystring uri end