Class: AWS::S3::Request
Instance Attribute Summary collapse
#access_key_id, #headers, #http_method, #params, #proxy_uri, #read_timeout, #region, #service_ruby_name
Class Method Summary
collapse
Instance Method Summary
collapse
#escape, #escape_path
#add_param, #get_param, #initialize, #param_value_for, #port, #port=, #ssl_ca_file, #ssl_ca_file=, #ssl_ca_path, #ssl_ca_path=, #ssl_verify_peer=, #ssl_verify_peer?, #uri, #url_encoded_params, #use_ssl=, #use_ssl?
Instance Attribute Details
#body_stream ⇒ Object
32
33
34
|
# File 'lib/aws/s3/request.rb', line 32
def body_stream
@body_stream
end
|
26
27
28
|
# File 'lib/aws/s3/request.rb', line 26
def bucket
@bucket
end
|
#key ⇒ String
29
30
31
|
# File 'lib/aws/s3/request.rb', line 29
def key
@key
end
|
Class Method Details
.query_parameters ⇒ Object
191
192
193
194
195
|
# File 'lib/aws/s3/request.rb', line 191
def query_parameters
%w(response-content-type response-content-language
response-expires response-cache-control
response-content-disposition response-content-encoding)
end
|
.sub_resources ⇒ Object
185
186
187
188
189
|
# File 'lib/aws/s3/request.rb', line 185
def sub_resources
%w(acl location logging notification partNumber policy
requestPayment torrent uploadId uploads versionId
versioning versions delete lifecycle)
end
|
Instance Method Details
#add_authorization!(signer) ⇒ Object
174
175
176
177
178
179
180
181
|
# File 'lib/aws/s3/request.rb', line 174
def add_authorization!(signer)
if signer.respond_to?(:session_token) and
token = signer.session_token
["x-amz-security-token"] = token
end
signature = URI.escape(signer.sign(string_to_sign, 'sha1'))
["authorization"] = "AWS #{signer.access_key_id}:#{signature}"
end
|
#body ⇒ String?
Returns The http request body.
78
79
80
81
82
83
84
85
86
|
# File 'lib/aws/s3/request.rb', line 78
def body
if @body_stream
string = @body_stream.read
@body_stream.rewind
string
else
nil
end
end
|
#body=(body) ⇒ Object
73
74
75
|
# File 'lib/aws/s3/request.rb', line 73
def body= body
@body_stream = StringIO.new(body)
end
|
#canned_acl=(acl) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/aws/s3/request.rb', line 40
def canned_acl= acl
if acl.kind_of?(Symbol)
["x-amz-acl"] = acl.to_s.gsub("_", "-")
elsif acl
["x-amz-acl"] = acl
end
end
|
CanonicalizedAmzHeaders
See the developer guide for more information on how this element is generated.
158
159
160
161
162
163
164
|
# File 'lib/aws/s3/request.rb', line 158
def
x_amz = .select{|name, value| name.to_s =~ /^x-amz-/i }
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
|
#canonicalized_resource ⇒ Object
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"];
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/aws/s3/request.rb', line 125
def canonicalized_resource
parts = []
if
Client.dns_compatible_bucket_name?(bucket) and
!Client.path_style_bucket_name?(bucket)
then
parts << "/#{bucket}"
end
parts << path
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
|
34
35
36
37
38
|
# File 'lib/aws/s3/request.rb', line 34
def metadata= metadata
Array(metadata).each do |name, value|
["x-amz-meta-#{name}"] = value
end
end
|
#path ⇒ Object
60
61
62
63
64
65
|
# File 'lib/aws/s3/request.rb', line 60
def path
parts = []
parts << bucket if bucket and Client.path_style_bucket_name?(bucket)
parts << escape_path(key) if key
"/#{parts.join('/')}"
end
|
#query_parameters_for_signature ⇒ Object
170
171
172
|
# File 'lib/aws/s3/request.rb', line 170
def query_parameters_for_signature
params.select { |p| self.class.query_parameters.include?(p.name) }
end
|
#querystring ⇒ Object
67
68
69
|
# File 'lib/aws/s3/request.rb', line 67
def querystring
url_encoded_params
end
|
#signing_string_date ⇒ Object
107
108
109
110
111
112
113
114
115
|
# File 'lib/aws/s3/request.rb', line 107
def signing_string_date
if .detect{|k,v| k.to_s =~ /^x-amz-date$/i }
''
else
['date'] ||= Time.now.rfc822
end
end
|
#storage_class=(storage_class) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/aws/s3/request.rb', line 48
def storage_class= storage_class
if storage_class.kind_of?(Symbol)
["x-amz-storage-class"] = storage_class.to_s.upcase
elsif storage_class
["x-amz-storage-class"] = storage_class
end
end
|
#string_to_sign ⇒ Object
From the S3 developer guide:
StringToSign =
HTTP-Verb + "\n" +
content-md5 + "\n" +
content-type + "\n" +
date + "\n" +
CanonicalizedAmzHeaders + CanonicalizedResource;
97
98
99
100
101
102
103
104
105
|
# File 'lib/aws/s3/request.rb', line 97
def string_to_sign
[
http_method,
.values_at('content-md5', 'content-type').join("\n"),
signing_string_date,
,
canonicalized_resource,
].flatten.compact.join("\n")
end
|
#sub_resource_params ⇒ Object
166
167
168
|
# File 'lib/aws/s3/request.rb', line 166
def sub_resource_params
params.select{|p| self.class.sub_resources.include?(p.name) }
end
|