diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5568daa..41a0446 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,17 @@
## CHANGE LOG
+### v6.1.0
+
+- Qiniu::Storage所有上传接口返回第三个值raw_headers,类型为Hash,包含已解析的HTTP响应报文中的所有Header信息。
+
+该返回值主要用于调试。当遇到难以理解或解释的错误时,请将其中的X-Log和X-Reqid两项信息[通过邮件反馈](mailto:support@qiniu.com?subject=Ruby-SDK-Bug-Report)给我们。
+
+- 更新Qiniu::Storage所有上传接口的测试用例,打印HTTP响应Header信息。
+
+- 删除过时的Qiniu::Storage#put_file方法和相关测试用例。
+
+该方法调用的API已过时并逐步废弃,建议用户尽快迁移到Qiniu::Storage#upload_with_token_2方法上。
+
### v6.0.1
- 重新划分命名空间,存储相关归入Qiniu::Storage,数据处理相关归入Qiniu::Fop,杂项相关归入Qiniu::Misc。
diff --git a/Gemfile.lock b/Gemfile.lock
index dddcc76..e546604 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- qiniu (6.0.1)
+ qiniu (6.1.0)
json (~> 1.7)
mime-types (~> 1.19)
rest-client (~> 1.6)
@@ -12,7 +12,7 @@ GEM
specs:
diff-lcs (1.1.3)
fakeweb (1.3.0)
- json (1.7.7)
+ json (1.8.1)
mime-types (1.23)
rake (10.0.3)
rest-client (1.6.7)
diff --git a/README.md b/README.md
index d6cb1b3..ec00b0d 100755
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@
在您 Ruby 应用程序的 `Gemfile` 文件中,添加如下一行代码:
- gem 'qiniu', '~> 6.0.0'
+ gem 'qiniu', '~> 6.1.0'
然后,在应用程序所在的目录下,可以运行 `bundle` 安装依赖包:
diff --git a/lib/qiniu.rb b/lib/qiniu.rb
index 49c3658..337b78a 100755
--- a/lib/qiniu.rb
+++ b/lib/qiniu.rb
@@ -54,16 +54,6 @@ module Qiniu
code == StatusOK
end
- def put_file opts = {}
- code, data = Storage.put_file(opts[:file],
- opts[:bucket],
- opts[:key],
- opts[:mime_type],
- opts[:note],
- opts[:enable_crc32_check])
- code == StatusOK
- end
-
def upload_file opts = {}
uncontained_opts = [:uptoken, :file, :bucket, :key] - opts.keys
raise MissingArgsError, uncontained_opts unless uncontained_opts.empty?
diff --git a/lib/qiniu/auth.rb b/lib/qiniu/auth.rb
index 867e4a3..1d3075c 100755
--- a/lib/qiniu/auth.rb
+++ b/lib/qiniu/auth.rb
@@ -10,16 +10,16 @@ module Qiniu
include Utils
def call_with_signature(url, data, retry_times = 0, options = {})
- code, data = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data, options[:mime])})
- [code, data]
- end
+ code, data, raw_headers = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data, options[:mime])})
+ [code, data, raw_headers]
+ end # call_with_signature
def request(url, data = nil, options = {})
- code, data = Auth.call_with_signature(url, data, 0, options)
- [code, data]
- end
+ code, data, raw_headers = Auth.call_with_signature(url, data, 0, options)
+ [code, data, raw_headers]
+ end # request
- end
+ end # class << self
end # module Auth
end # module Qiniu
diff --git a/lib/qiniu/config.rb b/lib/qiniu/config.rb
index 53216c3..7f230e4 100755
--- a/lib/qiniu/config.rb
+++ b/lib/qiniu/config.rb
@@ -20,7 +20,6 @@ module Qiniu
:content_type => 'application/x-www-form-urlencoded',
:auth_url => "https://acc.qbox.me/oauth2/token",
:rs_host => "http://rs.qiniu.com",
- :io_host => "http://iovip.qbox.me",
:up_host => "http://up.qiniu.com",
:pub_host => "http://pu.qbox.me:10200",
:eu_host => "http://eu.qbox.me",
diff --git a/lib/qiniu/upload.rb b/lib/qiniu/upload.rb
index 73f9d98..faede91 100755
--- a/lib/qiniu/upload.rb
+++ b/lib/qiniu/upload.rb
@@ -5,27 +5,6 @@ module Qiniu
class << self
include Utils
- def put_file(local_file,
- bucket,
- key = nil,
- mime_type = nil,
- custom_meta = nil,
- enable_crc32_check = false)
- action_params = _generate_action_params(
- local_file,
- bucket,
- key,
- mime_type,
- custom_meta,
- enable_crc32_check
- )
-
- url = Config.settings[:io_host] + action_params
- options = {:content_type => 'application/octet-stream'}
-
- Auth.request url, ::IO.read(local_file), options
- end # put_file
-
def upload_with_token(uptoken,
local_file,
bucket,
diff --git a/lib/qiniu/utils.rb b/lib/qiniu/utils.rb
index ba7a4d8..3dd3005 100755
--- a/lib/qiniu/utils.rb
+++ b/lib/qiniu/utils.rb
@@ -74,10 +74,11 @@ module Qiniu
else
data = {}
body = response.respond_to?(:body) ? response.body : {}
+ raw_headers = response.respond_to?(:raw_headers) ? response.raw_headers : {}
data = safe_json_parse(body) unless body.empty?
end
- [code, data]
- end
+ [code, data, raw_headers]
+ end # send_request_with
def http_request url, data = nil, options = {}
retry_times = 0
@@ -99,9 +100,10 @@ module Qiniu
res = e.response
code = res.code.to_i if res.respond_to? :code
body = res.respond_to?(:body) ? res.body : ""
+ raw_headers = res.respond_to?(:raw_headers) ? res.raw_headers : {}
data = safe_json_parse(body) unless body.empty?
end
- [code, data]
+ [code, data, raw_headers]
end
end
diff --git a/lib/qiniu/version.rb b/lib/qiniu/version.rb
index 8d779d8..fa24356 100755
--- a/lib/qiniu/version.rb
+++ b/lib/qiniu/version.rb
@@ -3,8 +3,8 @@
module Qiniu
module Version
MAJOR = 6
- MINOR = 0
- PATCH = 1
+ MINOR = 1
+ PATCH = 0
# Returns a version string by joining MAJOR, MINOR, and PATCH with '.'
#
# Example
diff --git a/spec/qiniu/management_spec.rb b/spec/qiniu/management_spec.rb
index 34ab775..7023cc0 100755
--- a/spec/qiniu/management_spec.rb
+++ b/spec/qiniu/management_spec.rb
@@ -29,9 +29,16 @@ module Qiniu
end
### 准备数据
- context ".put_file" do
+ context ".upload_with_token_2" do
it "should works" do
- code, data = Storage.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true)
+ upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"}
+ uptoken = Qiniu.generate_upload_token(upopts)
+
+ code, data, raw_headers = Qiniu::Storage.upload_with_token_2(
+ uptoken,
+ __FILE__,
+ @key
+ )
code.should == 200
puts data.inspect
end
diff --git a/spec/qiniu/qiniu_spec.rb b/spec/qiniu/qiniu_spec.rb
index 86a014e..1136432 100755
--- a/spec/qiniu/qiniu_spec.rb
+++ b/spec/qiniu/qiniu_spec.rb
@@ -37,17 +37,6 @@ module Qiniu
### 不删除Bucket以备下次使用
end
- context ".put_file" do
- it "should works" do
- result = Qiniu.put_file :file => __FILE__,
- :bucket => @bucket,
- :key => @key,
- :mime_type => 'application/x-ruby',
- :enable_crc32_check => true
- result.should be_true
- end
- end
-
context ".buckets" do
it "should works" do
result = Qiniu.buckets
diff --git a/spec/qiniu/upload_spec.rb b/spec/qiniu/upload_spec.rb
index 895d54a..e344c21 100755
--- a/spec/qiniu/upload_spec.rb
+++ b/spec/qiniu/upload_spec.rb
@@ -19,26 +19,31 @@ module Qiniu
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
@key = make_unique_key_in_bucket(@key)
+ puts "key=#{@key}"
@localfile_5m = "5M.txt"
File.open(@localfile_5m, "w"){|f| 5242888.times{ f.write(rand(9).to_s) }}
@key_5m = Digest::SHA1.hexdigest(@localfile_5m+Time.now.to_s)
@key_5m = make_unique_key_in_bucket(@key_5m)
+ puts "key_5m=#{@key_5m}"
@localfile_4m = "4M.txt"
File.open(@localfile_4m, "w"){|f| (1 << 22).times{ f.write(rand(9).to_s) }}
@key_4m = Digest::SHA1.hexdigest(@localfile_4m+Time.now.to_s)
@key_4m = make_unique_key_in_bucket(@key_4m)
+ puts "key_4m=#{@key_4m}"
@localfile_8m = "8M.txt"
File.open(@localfile_8m, "w"){|f| (1 << 23).times{ f.write(rand(9).to_s) }}
@key_8m = Digest::SHA1.hexdigest(@localfile_8m+Time.now.to_s)
@key_8m = make_unique_key_in_bucket(@key_8m)
+ puts "key_8m=#{@key_8m}"
@localfile_1m = "1M.txt"
File.open(@localfile_1m, "w"){|f| (1 << 20).times{ f.write(rand(9).to_s) }}
@key_1m = Digest::SHA1.hexdigest(@localfile_1m+Time.now.to_s)
@key_1m = make_unique_key_in_bucket(@key_1m)
+ puts "key_1m=#{@key_1m}"
end
after :all do
@@ -52,37 +57,23 @@ module Qiniu
end
### 测试单文件直传
- context ".put_file" do
- it "should works" do
- code, data = Qiniu::Storage.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true)
- code.should == 200
- puts data.inspect
- end
- end
-
- context ".stat" do
- it "should exists" do
- code, data = Qiniu::Storage.stat(@bucket, @key)
- puts data.inspect
- code.should == 200
- end
- end
-
- context ".delete" do
- it "should works" do
- code, data = Qiniu::Storage.delete(@bucket, @key)
- puts data.inspect
- code.should == 200
- end
- end
-
context ".upload_with_token" do
it "should works" do
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
uptoken = Qiniu.generate_upload_token(upopts)
- code, data = Qiniu::Storage.upload_with_token(uptoken, __FILE__, @bucket, @key, nil, nil, nil, true)
+ code, data, raw_headers = Qiniu::Storage.upload_with_token(
+ uptoken,
+ __FILE__,
+ @bucket,
+ @key,
+ nil,
+ nil,
+ nil,
+ true
+ )
code.should == 200
puts data.inspect
+ puts raw_headers.inspect
end
end
@@ -107,10 +98,15 @@ module Qiniu
upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"}
uptoken = Qiniu.generate_upload_token(upopts)
- code, data = Qiniu::Storage.upload_with_token_2(uptoken, __FILE__, @key)
+ code, data, raw_headers = Qiniu::Storage.upload_with_token_2(
+ uptoken,
+ __FILE__,
+ @key
+ )
code.should == 200
puts data.inspect
+ puts raw_headers.inspect
end
end # .upload_with_token_2
@@ -135,9 +131,16 @@ module Qiniu
it "should works" do
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
uptoken = Qiniu.generate_upload_token(upopts)
- code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_5m, @bucket, @key_5m)
- puts data.inspect
+ code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token(
+ uptoken,
+ @localfile_5m,
+ @bucket,
+ @key_5m
+ )
(code/100).should == 2
+ puts data.inspect
+ puts raw_headers.inspect
+ puts "key_5m=#{@key_5m}"
end
end
@@ -161,9 +164,16 @@ module Qiniu
it "should works" do
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
uptoken = Qiniu.generate_upload_token(upopts)
- code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_4m, @bucket, @key_4m)
- puts data.inspect
+ code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token(
+ uptoken,
+ @localfile_4m,
+ @bucket,
+ @key_4m
+ )
(code/100).should == 2
+ puts data.inspect
+ puts raw_headers.inspect
+ puts "key_4m=#{@key_4m}"
end
end
@@ -187,9 +197,16 @@ module Qiniu
it "should works" do
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
uptoken = Qiniu.generate_upload_token(upopts)
- code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_8m, @bucket, @key_8m)
- puts data.inspect
+ code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token(
+ uptoken,
+ @localfile_8m,
+ @bucket,
+ @key_8m
+ )
(code/100).should == 2
+ puts data.inspect
+ puts raw_headers.inspect
+ puts "key_8m=#{@key_8m}"
end
end
@@ -213,9 +230,16 @@ module Qiniu
it "should works" do
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
uptoken = Qiniu.generate_upload_token(upopts)
- code, data = Qiniu::Storage.resumable_upload_with_token(uptoken, @localfile_1m, @bucket, @key_1m)
- puts data.inspect
+ code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token(
+ uptoken,
+ @localfile_1m,
+ @bucket,
+ @key_1m
+ )
(code/100).should == 2
+ puts data.inspect
+ puts raw_headers.inspect
+ puts "key_1m=#{@key_1m}"
end
end
diff --git a/spec/qiniu/utils_spec.rb b/spec/qiniu/utils_spec.rb
index fb00074..5ef8625 100755
--- a/spec/qiniu/utils_spec.rb
+++ b/spec/qiniu/utils_spec.rb
@@ -28,7 +28,7 @@ module Qiniu
FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :body => {:abc => 123}.to_json)
res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get
- res.should == [200, {"abc" => 123}]
+ res.should == [200, {"abc" => 123}, {}]
end
[400, 500].each do |code|