s3 0.3.15 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/s3/bucket.rb +2 -2
- data/lib/s3/connection.rb +13 -15
- data/lib/s3/object.rb +7 -18
- data/lib/s3/service.rb +2 -2
- data/lib/s3/version.rb +1 -1
- data/test/connection_test.rb +5 -5
- data/test/object_test.rb +1 -17
- data/test/test_helper.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55ade48988489016d6c76410ddb53c04d2b093a8
|
4
|
+
data.tar.gz: dd4cfb34b3e417c4687fe3aa3d85ddf0f5b72193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d437b2e4f424ea6e695d71bb1e0a4ff90549a4d444f528c37baa6dacddb362bf076e6098361956685441fb2da54983e828cdd85378b778e4dc9f0296d86568ea
|
7
|
+
data.tar.gz: 32f388c8b6a732a449c8b9b042892a88d7d7a438fd446ca259d76b78c56e6b82373f1d5778e894475d3e55545c2ff2d13edb7511a2e6104aa1edd66fd8e6efd8
|
data/Gemfile.lock
CHANGED
data/lib/s3/bucket.rb
CHANGED
@@ -200,9 +200,9 @@ module S3
|
|
200
200
|
@name = name
|
201
201
|
end
|
202
202
|
|
203
|
-
def bucket_request(method, options = {}
|
203
|
+
def bucket_request(method, options = {})
|
204
204
|
path = "#{path_prefix}#{options[:path]}"
|
205
|
-
service_request(method, options.merge(:host => host, :path => path)
|
205
|
+
service_request(method, options.merge(:host => host, :path => path))
|
206
206
|
end
|
207
207
|
|
208
208
|
def name_valid?(name)
|
data/lib/s3/connection.rb
CHANGED
@@ -53,7 +53,7 @@ module S3
|
|
53
53
|
#
|
54
54
|
# ==== Returns
|
55
55
|
# Net::HTTPResponse object -- response from the server
|
56
|
-
def request(method, options
|
56
|
+
def request(method, options)
|
57
57
|
host = options.fetch(:host, HOST)
|
58
58
|
path = options.fetch(:path)
|
59
59
|
body = options.fetch(:body, nil)
|
@@ -85,7 +85,7 @@ module S3
|
|
85
85
|
request.content_length = body.respond_to?(:lstat) ? body.stat.size : body.size
|
86
86
|
end
|
87
87
|
|
88
|
-
send_request(host, request
|
88
|
+
send_request(host, request)
|
89
89
|
end
|
90
90
|
|
91
91
|
# Helper function to parser parameters and create single string of
|
@@ -173,8 +173,8 @@ module S3
|
|
173
173
|
http
|
174
174
|
end
|
175
175
|
|
176
|
-
def send_request(host, request, skip_authorization = false
|
177
|
-
http(host).start do |http|
|
176
|
+
def send_request(host, request, skip_authorization = false)
|
177
|
+
response = http(host).start do |http|
|
178
178
|
host = http.address
|
179
179
|
|
180
180
|
request["Date"] ||= Time.now.httpdate
|
@@ -191,18 +191,16 @@ module S3
|
|
191
191
|
:secret_access_key => secret_access_key)
|
192
192
|
end
|
193
193
|
|
194
|
-
http.request(request)
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
result = handle_response(response)
|
202
|
-
yield result unless block.nil?
|
203
|
-
return result
|
204
|
-
end
|
194
|
+
http.request(request)
|
195
|
+
end
|
196
|
+
|
197
|
+
if response.code.to_i == 307
|
198
|
+
if response.body
|
199
|
+
doc = Document.new response.body
|
200
|
+
send_request(doc.elements["Error"].elements["Endpoint"].text, request, true)
|
205
201
|
end
|
202
|
+
else
|
203
|
+
handle_response(response)
|
206
204
|
end
|
207
205
|
end
|
208
206
|
|
data/lib/s3/object.rb
CHANGED
@@ -89,12 +89,6 @@ module S3
|
|
89
89
|
@content
|
90
90
|
end
|
91
91
|
|
92
|
-
# Streams the content of the object without caching it, providing
|
93
|
-
# successive chunks to the block
|
94
|
-
def stream(options = {}, &block)
|
95
|
-
get_object(options, &block)
|
96
|
-
end
|
97
|
-
|
98
92
|
# Saves the object, returns true if successfull.
|
99
93
|
def save
|
100
94
|
put_object
|
@@ -186,10 +180,9 @@ module S3
|
|
186
180
|
object
|
187
181
|
end
|
188
182
|
|
189
|
-
def get_object(options = {}
|
190
|
-
object_request(:get, options)
|
191
|
-
|
192
|
-
end
|
183
|
+
def get_object(options = {})
|
184
|
+
response = object_request(:get, options)
|
185
|
+
parse_headers(response)
|
193
186
|
end
|
194
187
|
|
195
188
|
def object_headers(options = {})
|
@@ -221,8 +214,8 @@ module S3
|
|
221
214
|
self.cache_control = options[:cache_control]
|
222
215
|
end
|
223
216
|
|
224
|
-
def object_request(method, options = {}
|
225
|
-
bucket_request(method, options.merge(:path => key)
|
217
|
+
def object_request(method, options = {})
|
218
|
+
bucket_request(method, options.merge(:path => key))
|
226
219
|
end
|
227
220
|
|
228
221
|
def last_modified=(last_modified)
|
@@ -252,7 +245,7 @@ module S3
|
|
252
245
|
headers
|
253
246
|
end
|
254
247
|
|
255
|
-
def parse_headers(response
|
248
|
+
def parse_headers(response)
|
256
249
|
@metadata = response.to_hash.select { |k, v| k.to_s.start_with?("x-amz-meta") }
|
257
250
|
self.etag = response["etag"] if response.key?("etag")
|
258
251
|
self.content_type = response["content-type"] if response.key?("content-type")
|
@@ -264,11 +257,7 @@ module S3
|
|
264
257
|
self.size = response["content-range"].sub(/[^\/]+\//, "").to_i
|
265
258
|
else
|
266
259
|
self.size = response["content-length"]
|
267
|
-
|
268
|
-
self.content = response.body
|
269
|
-
else
|
270
|
-
response.read_body(nil, &block)
|
271
|
-
end
|
260
|
+
self.content = response.body
|
272
261
|
end
|
273
262
|
end
|
274
263
|
end
|
data/lib/s3/service.rb
CHANGED
@@ -70,8 +70,8 @@ module S3
|
|
70
70
|
names.map { |name| Bucket.send(:new, self, name) }
|
71
71
|
end
|
72
72
|
|
73
|
-
def service_request(method, options = {}
|
74
|
-
connection.request(method, options.merge(:path => "/#{options[:path]}")
|
73
|
+
def service_request(method, options = {})
|
74
|
+
connection.request(method, options.merge(:path => "/#{options[:path]}"))
|
75
75
|
end
|
76
76
|
|
77
77
|
def connection
|
data/lib/s3/version.rb
CHANGED
data/test/connection_test.rb
CHANGED
@@ -12,8 +12,8 @@ class ConnectionTest < Test::Unit::TestCase
|
|
12
12
|
@response_error = Net::HTTPInternalServerError.new("1.1", "500", "Internal Server Error")
|
13
13
|
@response_temporary_redirect = Net::HTTPInternalServerError.new("1.1", "307", "Temporary Redirect")
|
14
14
|
@connection.stubs(:http).returns(@http_request)
|
15
|
-
|
16
|
-
@http_request.stubs(:
|
15
|
+
|
16
|
+
@http_request.stubs(:start).returns(@response_ok)
|
17
17
|
end
|
18
18
|
|
19
19
|
test "handle response not modify response when ok" do
|
@@ -36,7 +36,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
36
36
|
</Error>
|
37
37
|
EOFakeBody
|
38
38
|
|
39
|
-
@http_request.stubs(:
|
39
|
+
@http_request.stubs(:start).returns(@response_not_found)
|
40
40
|
@response_not_found.stubs(:body).returns(response_body)
|
41
41
|
|
42
42
|
assert_raise S3::Error::NoSuchBucket do
|
@@ -49,7 +49,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
49
49
|
end
|
50
50
|
|
51
51
|
test "handle response throws standard exception when error" do
|
52
|
-
@http_request.stubs(:
|
52
|
+
@http_request.stubs(:start).returns(@response_error)
|
53
53
|
@response_error.stubs(:body)
|
54
54
|
assert_raise S3::Error::ResponseError do
|
55
55
|
response = @connection.request(
|
@@ -174,7 +174,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
174
174
|
end
|
175
175
|
|
176
176
|
test "response.body is nil on TemporaryRedirect" do
|
177
|
-
@http_request.stubs(:
|
177
|
+
@http_request.stubs(:start).returns(@response_temporary_redirect)
|
178
178
|
@response_temporary_redirect.stubs(:body).returns(nil)
|
179
179
|
|
180
180
|
assert_nothing_raised do
|
data/test/object_test.rb
CHANGED
@@ -15,7 +15,6 @@ class ObjectTest < Test::Unit::TestCase
|
|
15
15
|
@object_mac.content = "test2"
|
16
16
|
|
17
17
|
@response_binary = Net::HTTPOK.new("1.1", "200", "OK")
|
18
|
-
@response_binary.stubs(:read_body).multiple_yields(*%w{t e s t})
|
19
18
|
@response_binary.stubs(:body).returns("test".respond_to?(:force_encoding) ? "test".force_encoding(Encoding::BINARY) : "test")
|
20
19
|
@response_binary["etag"] = ""
|
21
20
|
@response_binary["content-type"] = "image/png"
|
@@ -121,7 +120,7 @@ class ObjectTest < Test::Unit::TestCase
|
|
121
120
|
end
|
122
121
|
|
123
122
|
test "content and parse headers" do
|
124
|
-
@object_lena.expects(:object_request).with(:get, {}).
|
123
|
+
@object_lena.expects(:object_request).with(:get, {}).returns(@response_binary)
|
125
124
|
|
126
125
|
expected = /test/n
|
127
126
|
actual = @object_lena.content(true)
|
@@ -134,21 +133,6 @@ class ObjectTest < Test::Unit::TestCase
|
|
134
133
|
assert @object_lena.content(true)
|
135
134
|
end
|
136
135
|
|
137
|
-
test "streaming" do
|
138
|
-
@object_lena.expects(:object_request).with(:get, {}).yields(@response_binary)
|
139
|
-
|
140
|
-
expected = /test/n
|
141
|
-
io = StringIO.new
|
142
|
-
@object_lena.stream do |chunk|
|
143
|
-
io.write(chunk)
|
144
|
-
end
|
145
|
-
io.seek(0)
|
146
|
-
actual = io.read
|
147
|
-
assert_match expected, actual
|
148
|
-
assert_equal "image/png", @object_lena.content_type
|
149
|
-
assert_equal @object.instance_variable_defined?(:@content), false
|
150
|
-
end
|
151
|
-
|
152
136
|
test "retrieve" do
|
153
137
|
@object_lena.expects(:object_request).with(:head, {}).returns(@response_binary)
|
154
138
|
assert @object_lena.retrieve
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuba Kuźma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: proxies
|