mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-09 04:46:10 +10:00
令http_request()输出HTTP Response Headers,并用于所有的上传测试用例。
This commit is contained in:
+7
-7
@@ -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
|
||||
|
||||
+5
-3
@@ -75,9 +75,10 @@ module Qiniu
|
||||
data = {}
|
||||
body = response.respond_to?(:body) ? response.body : {}
|
||||
data = safe_json_parse(body) unless body.empty?
|
||||
raw_headers = response.raw_headers
|
||||
end
|
||||
[code, data]
|
||||
end
|
||||
[code, data, raw_headers]
|
||||
end # send_request_with
|
||||
|
||||
def http_request url, data = nil, options = {}
|
||||
retry_times = 0
|
||||
@@ -100,8 +101,9 @@ module Qiniu
|
||||
code = res.code.to_i if res.respond_to? :code
|
||||
body = res.respond_to?(:body) ? res.body : ""
|
||||
data = safe_json_parse(body) unless body.empty?
|
||||
raw_headers = response.raw_headers
|
||||
end
|
||||
[code, data]
|
||||
[code, data, raw_headers]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+67
-11
@@ -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
|
||||
@@ -54,9 +59,17 @@ module Qiniu
|
||||
### 测试单文件直传
|
||||
context ".put_file" do
|
||||
it "should works" do
|
||||
code, data = Qiniu::Storage.put_file(__FILE__, @bucket, @key, 'application/x-ruby', 'customMeta', true)
|
||||
code, data, raw_headers = Qiniu::Storage.put_file(
|
||||
__FILE__,
|
||||
@bucket,
|
||||
@key,
|
||||
'application/x-ruby',
|
||||
'customMeta',
|
||||
true,
|
||||
)
|
||||
code.should == 200
|
||||
puts data.inspect
|
||||
puts raw_headers.inspect
|
||||
end
|
||||
end
|
||||
|
||||
@@ -80,9 +93,19 @@ 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.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 +130,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 +163,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 +196,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 +229,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 +262,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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user