aliyun-sdk 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/aliyun/oss/bucket.rb +6 -8
- data/lib/aliyun/oss/download.rb +2 -1
- data/lib/aliyun/oss/http.rb +21 -2
- data/lib/aliyun/oss/protocol.rb +4 -0
- data/lib/aliyun/version.rb +1 -1
- data/tests/test_content_encoding.rb +59 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a480b0f35aeed00c9b07e617d3609caedbfd862
|
4
|
+
data.tar.gz: e7ae01442d09525274a84389da0ea3055e46164a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20b4634d8db8efd28f033013418846c130b669637db55406436e58112ef7bbd09c2f55b1bec979bd8eb498d1a2f071114f80b0a74ffb21713bcfa5358ad00643
|
7
|
+
data.tar.gz: 1a77e052686a50dfc1de71652d7da92c551f37065e9337446262fe8b19ca33c570d8764a4feea08111022e762e775bd95b923fbbaf0a55c882be435980ecc631
|
data/CHANGELOG.md
CHANGED
data/lib/aliyun/oss/bucket.rb
CHANGED
@@ -236,6 +236,8 @@ module Aliyun
|
|
236
236
|
# * :if_unmodified_since (Time) 指定如果object从这个时间后再无修改,则下载
|
237
237
|
# * :if_match_etag (String) 指定如果object的etag等于这个值,则下载
|
238
238
|
# * :if_unmatch_etag (String) 指定如果object的etag不等于这个值,则下载
|
239
|
+
# @option opts [Hash] :headers 指定请求的HTTP Header,不区分大小
|
240
|
+
# 写。这里指定的值会覆盖通过`:range`和`:condition`设置的值。
|
239
241
|
# @option opts [Hash] :rewrite 指定下载object时Server端返回的响应头部字段的值
|
240
242
|
# * :content_type (String) 指定返回的响应中Content-Type的值
|
241
243
|
# * :content_language (String) 指定返回的响应中Content-Language的值
|
@@ -472,10 +474,7 @@ module Aliyun
|
|
472
474
|
|
473
475
|
args[:content_type] ||= get_content_type(file)
|
474
476
|
args[:content_type] ||= get_content_type(key)
|
475
|
-
|
476
|
-
unless cpt_file = args[:cpt_file]
|
477
|
-
cpt_file = get_cpt_file(file)
|
478
|
-
end
|
477
|
+
cpt_file = args[:cpt_file] || get_cpt_file(file)
|
479
478
|
|
480
479
|
Multipart::Upload.new(
|
481
480
|
@protocol, options: args,
|
@@ -507,6 +506,8 @@ module Aliyun
|
|
507
506
|
# 则:cpt_file会被忽略。
|
508
507
|
# @option opts [Hash] :condition 指定下载object需要满足的条件,
|
509
508
|
# 同 {#get_object}
|
509
|
+
# @option opts [Hash] :headers 指定请求的HTTP Header,不区分大小
|
510
|
+
# 写。这里指定的值会覆盖通过`:condition`设置的值。
|
510
511
|
# @option opts [Hash] :rewrite 指定下载object时Server端返回的响
|
511
512
|
# 应头部字段的值,同 {#get_object}
|
512
513
|
# @yield [Float] 如果调用的时候传递了block,则会将下载进度交由
|
@@ -529,10 +530,7 @@ module Aliyun
|
|
529
530
|
|
530
531
|
args[:content_type] ||= get_content_type(file)
|
531
532
|
args[:content_type] ||= get_content_type(key)
|
532
|
-
|
533
|
-
unless cpt_file = args[:cpt_file]
|
534
|
-
cpt_file = get_cpt_file(file)
|
535
|
-
end
|
533
|
+
cpt_file = args[:cpt_file] || get_cpt_file(file)
|
536
534
|
|
537
535
|
Multipart::Download.new(
|
538
536
|
@protocol, options: args,
|
data/lib/aliyun/oss/download.rb
CHANGED
@@ -179,7 +179,8 @@ module Aliyun
|
|
179
179
|
part_file = get_part_file(p)
|
180
180
|
File.open(part_file, 'w') do |w|
|
181
181
|
@protocol.get_object(
|
182
|
-
bucket, object,
|
182
|
+
bucket, object,
|
183
|
+
@options.merge(range: p[:range])) { |chunk| w.write(chunk) }
|
183
184
|
end
|
184
185
|
|
185
186
|
sync_update_part(p.merge(done: true, md5: get_file_md5(part_file)))
|
data/lib/aliyun/oss/http.rb
CHANGED
@@ -32,6 +32,7 @@ module Aliyun
|
|
32
32
|
class HTTP
|
33
33
|
|
34
34
|
DEFAULT_CONTENT_TYPE = 'application/octet-stream'
|
35
|
+
DEFAULT_ACCEPT_ENCODING = 'identity'
|
35
36
|
STS_HEADER = 'x-oss-security-token'
|
36
37
|
OPEN_TIMEOUT = 10
|
37
38
|
READ_TIMEOUT = 120
|
@@ -156,8 +157,25 @@ module Aliyun
|
|
156
157
|
r.read_body
|
157
158
|
else
|
158
159
|
# streaming read body on success
|
159
|
-
|
160
|
-
|
160
|
+
encoding = r['content-encoding']
|
161
|
+
if encoding == 'gzip'
|
162
|
+
stream = StreamWriter.new { |s| r.read_body { |chunk| s << chunk } }
|
163
|
+
reader = Zlib::GzipReader.new(stream)
|
164
|
+
yield reader.read(16 * 1024) until reader.eof?
|
165
|
+
elsif encoding == 'deflate'
|
166
|
+
begin
|
167
|
+
stream = Zlib::Inflate.new
|
168
|
+
r.read_body { |chunk| stream << chunk }
|
169
|
+
stream.finish { |chunk| yield chunk }
|
170
|
+
rescue Zlib::DataError
|
171
|
+
# No luck with Zlib decompression. Let's try with raw deflate,
|
172
|
+
# like some broken web servers do.
|
173
|
+
stream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
|
174
|
+
r.read_body { |chunk| stream << chunk }
|
175
|
+
stream.finish { |chunk| yield chunk }
|
176
|
+
end
|
177
|
+
else
|
178
|
+
r.read_body { |chunk| yield chunk }
|
161
179
|
end
|
162
180
|
end
|
163
181
|
end
|
@@ -210,6 +228,7 @@ module Aliyun
|
|
210
228
|
headers['user-agent'] = get_user_agent
|
211
229
|
headers['date'] = Time.now.httpdate
|
212
230
|
headers['content-type'] ||= DEFAULT_CONTENT_TYPE
|
231
|
+
headers['accept-encoding'] ||= DEFAULT_ACCEPT_ENCODING
|
213
232
|
headers[STS_HEADER] = @config.sts_token if @config.sts_token
|
214
233
|
|
215
234
|
if body = http_options[:body]
|
data/lib/aliyun/oss/protocol.rb
CHANGED
@@ -718,6 +718,9 @@ module Aliyun
|
|
718
718
|
# specified
|
719
719
|
# * :if_unmatch_etag (String) get the object if its etag
|
720
720
|
# doesn't match specified
|
721
|
+
# @option opts [Hash] :headers custom HTTP headers, case
|
722
|
+
# insensitive. Headers specified here will overwrite `:condition`
|
723
|
+
# and `:range`
|
721
724
|
# @option opts [Hash] :rewrite response headers to rewrite
|
722
725
|
# * :content_type (String) the Content-Type header
|
723
726
|
# * :content_language (String) the Content-Language header
|
@@ -739,6 +742,7 @@ module Aliyun
|
|
739
742
|
headers = {}
|
740
743
|
headers['range'] = get_bytes_range(range) if range
|
741
744
|
headers.merge!(get_conditions(conditions)) if conditions
|
745
|
+
headers.merge!(to_lower_case(opts[:headers])) if opts.key?(:headers)
|
742
746
|
|
743
747
|
sub_res = {}
|
744
748
|
if rewrites
|
data/lib/aliyun/version.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'yaml'
|
3
|
+
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
|
4
|
+
require 'aliyun/oss'
|
5
|
+
require 'zlib'
|
6
|
+
|
7
|
+
class TestContentEncoding < Minitest::Test
|
8
|
+
def setup
|
9
|
+
Aliyun::Common::Logging.set_log_level(Logger::DEBUG)
|
10
|
+
conf_file = '~/.oss.yml'
|
11
|
+
conf = YAML.load(File.read(File.expand_path(conf_file)))
|
12
|
+
client = Aliyun::OSS::Client.new(
|
13
|
+
:endpoint => conf['endpoint'],
|
14
|
+
:cname => conf['cname'],
|
15
|
+
:access_key_id => conf['access_key_id'],
|
16
|
+
:access_key_secret => conf['access_key_secret'])
|
17
|
+
@bucket = client.get_bucket(conf['bucket'])
|
18
|
+
|
19
|
+
@prefix = "tests/content_encoding/"
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_key(k)
|
23
|
+
"#{@prefix}#{k}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_gzip_encoding
|
27
|
+
key = get_key('gzip')
|
28
|
+
File.open('/tmp/x', 'w') do |f|
|
29
|
+
1000.times { f.write 'hello world' * 1024 }
|
30
|
+
end
|
31
|
+
|
32
|
+
@bucket.put_object(
|
33
|
+
key, file: '/tmp/x', content_type: 'text/plain')
|
34
|
+
|
35
|
+
@bucket.get_object(
|
36
|
+
key, file: '/tmp/y', headers: {'accept-encoding': 'gzip'})
|
37
|
+
|
38
|
+
assert File.exist?('/tmp/y')
|
39
|
+
diff = `diff /tmp/x /tmp/y`
|
40
|
+
assert diff.empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_deflate_encoding
|
44
|
+
key = get_key('deflate')
|
45
|
+
File.open('/tmp/x', 'w') do |f|
|
46
|
+
1000.times { f.write 'hello world' * 1024 }
|
47
|
+
end
|
48
|
+
|
49
|
+
@bucket.put_object(
|
50
|
+
key, file: '/tmp/x', content_type: 'text/plain')
|
51
|
+
|
52
|
+
@bucket.get_object(
|
53
|
+
key, file: '/tmp/y', headers: {'accept-encoding': 'deflate'})
|
54
|
+
|
55
|
+
assert File.exist?('/tmp/y')
|
56
|
+
diff = `diff /tmp/x /tmp/y`
|
57
|
+
assert diff.empty?
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyun-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tianlong Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- spec/aliyun/oss/util_spec.rb
|
180
180
|
- spec/aliyun/sts/client_spec.rb
|
181
181
|
- spec/aliyun/sts/util_spec.rb
|
182
|
+
- tests/test_content_encoding.rb
|
182
183
|
- tests/test_content_type.rb
|
183
184
|
- tests/test_custom_headers.rb
|
184
185
|
- tests/test_encoding.rb
|
@@ -224,6 +225,7 @@ test_files:
|
|
224
225
|
- spec/aliyun/oss/util_spec.rb
|
225
226
|
- spec/aliyun/sts/client_spec.rb
|
226
227
|
- spec/aliyun/sts/util_spec.rb
|
228
|
+
- tests/test_content_encoding.rb
|
227
229
|
- tests/test_content_type.rb
|
228
230
|
- tests/test_custom_headers.rb
|
229
231
|
- tests/test_encoding.rb
|