azure-core 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/ChangeLog.md +4 -0
- data/lib/azure/core/filtered_service.rb +2 -2
- data/lib/azure/core/http/http_request.rb +37 -22
- data/lib/azure/core/http/retry_policy.rb +10 -6
- data/lib/azure/core/signed_service.rb +2 -2
- data/lib/azure/core/version.rb +1 -1
- data/test/support/fixtures.rb +13 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 28eb15120a2cc99f76064d85594a4126e014ff83be784b7ee8b6c7bc1dcaed0c
|
4
|
+
data.tar.gz: 6ae6620c660aa76e47841fb01d3a7089c044fd404feebc187568c6bfc1d0980d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d182d7cb1c220bfb20dac275166c1d948b25ef6ca5a914c7b450829dc04ca2d90a7b2dec7814bd458d5eed76408ac3b659a919e8653058ce5076f8674caa73c2
|
7
|
+
data.tar.gz: 7e3f948e02cf99a942e1bb5199a1020b5b09c821a7683dd58da2221f46dadec6f9acd627ab212b6c140e2c9b020fd6a17d820ec7375277183f920638e8028ac2
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 2017.11.10 - azure-core gem @version 0.1.13
|
2
|
+
* Added the call options in the retry data.
|
3
|
+
* Added the support for retrying a request with a different URL.
|
4
|
+
|
1
5
|
# 2017.08.31 - azure-core gem @version 0.1.12
|
2
6
|
* Changed default value of header `MaxDataServiceVersion` to `3.0;NetFx` now that the service is available.
|
3
7
|
* `Azure::Core::Http::HTTPError` now can also parse JSON format response body for error type and description.
|
@@ -30,9 +30,9 @@ module Azure
|
|
30
30
|
|
31
31
|
attr_accessor :filters
|
32
32
|
|
33
|
-
def call(method, uri, body=nil, headers=nil)
|
33
|
+
def call(method, uri, body=nil, headers=nil, options={})
|
34
34
|
super(method, uri, body, headers) do |request|
|
35
|
-
filters.reverse.each { |filter| request.with_filter filter } if filters
|
35
|
+
filters.reverse.each { |filter| request.with_filter filter, options } if filters
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -80,6 +80,9 @@ module Azure
|
|
80
80
|
# returns a HttpResponse eg. HttpFilter, Proc,
|
81
81
|
# lambda, etc. (optional)
|
82
82
|
#
|
83
|
+
# options - The options that are used when call Azure::Core::FilteredService.call.
|
84
|
+
# It can be used by retry policies to determine changes in the retry.
|
85
|
+
#
|
83
86
|
# &block - An inline block may be used instead of a filter
|
84
87
|
#
|
85
88
|
# example:
|
@@ -93,10 +96,13 @@ module Azure
|
|
93
96
|
# The code block provided must call _next or the filter pipeline
|
94
97
|
# will not complete and the HTTP request will never execute
|
95
98
|
#
|
96
|
-
def with_filter(filter=nil, &block)
|
99
|
+
def with_filter(filter=nil, options={}, &block)
|
97
100
|
filter = filter || block
|
98
101
|
if filter
|
99
|
-
|
102
|
+
is_retry_policy = filter.is_a?(Azure::Core::Http::RetryPolicy)
|
103
|
+
filter.retry_data[:request_options] = options if is_retry_policy
|
104
|
+
@has_retry_filter ||= is_retry_policy
|
105
|
+
|
100
106
|
original_call = self._method(:call)
|
101
107
|
|
102
108
|
# support 1.8.7 (define_singleton_method doesn't exist until 1.9.1)
|
@@ -151,27 +157,36 @@ module Azure
|
|
151
157
|
private
|
152
158
|
|
153
159
|
def apply_body_headers
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
body.rewind
|
166
|
-
end.base64digest
|
167
|
-
end
|
168
|
-
else
|
169
|
-
headers['Content-Length'] = body.bytesize.to_s
|
170
|
-
headers['Content-MD5'] = Base64.strict_encode64(Digest::MD5.digest(body)) unless headers['Content-MD5']
|
171
|
-
end
|
172
|
-
else
|
173
|
-
headers['Content-Length'] = '0'
|
160
|
+
return headers['Content-Length'] = '0' unless body
|
161
|
+
|
162
|
+
return apply_io_headers if IO === body
|
163
|
+
return apply_string_io_headers if StringIO === body
|
164
|
+
return apply_miscellaneous_headers
|
165
|
+
end
|
166
|
+
|
167
|
+
def apply_io_headers
|
168
|
+
headers['Content-Length'] = body.size.to_s if body.respond_to?('size')
|
169
|
+
if headers['Content-Length'].nil?
|
170
|
+
raise ArgumentError, '\'Content-Length\' must be defined if size cannot be obtained from body IO.'
|
174
171
|
end
|
172
|
+
headers['Content-MD5'] = Digest::MD5.file(body.path).base64digest unless headers['Content-MD5']
|
173
|
+
end
|
174
|
+
|
175
|
+
def apply_string_io_headers
|
176
|
+
headers['Content-Length'] = body.size.to_s
|
177
|
+
unless headers['Content-MD5']
|
178
|
+
headers['Content-MD5'] = Digest::MD5.new.tap do |checksum|
|
179
|
+
while chunk = body.read(5242880)
|
180
|
+
checksum << chunk
|
181
|
+
end
|
182
|
+
body.rewind
|
183
|
+
end.base64digest
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def apply_miscellaneous_headers
|
188
|
+
headers['Content-Length'] = body.bytesize.to_s
|
189
|
+
headers['Content-MD5'] = Base64.strict_encode64(Digest::MD5.digest(body)) unless headers['Content-MD5']
|
175
190
|
end
|
176
191
|
end
|
177
192
|
end
|
@@ -24,6 +24,7 @@ module Azure
|
|
24
24
|
|
25
25
|
def initialize(&block)
|
26
26
|
@block = block
|
27
|
+
@retry_data = {}
|
27
28
|
end
|
28
29
|
|
29
30
|
attr_accessor :retry_data
|
@@ -35,17 +36,20 @@ module Azure
|
|
35
36
|
# req - HttpRequest. The HTTP request
|
36
37
|
# _next - HttpFilter. The next filter in the pipeline
|
37
38
|
def call(req, _next)
|
38
|
-
retry_data = {}
|
39
39
|
response = nil
|
40
40
|
begin
|
41
|
+
# URI could change in the retry, e.g. secondary endpoint
|
42
|
+
unless @retry_data[:uri].nil?
|
43
|
+
req.uri = @retry_data[:uri]
|
44
|
+
end
|
41
45
|
response = _next.call
|
42
46
|
rescue
|
43
|
-
retry_data[:error] = $!
|
44
|
-
end while should_retry?(response, retry_data)
|
47
|
+
@retry_data[:error] = $!
|
48
|
+
end while should_retry?(response, @retry_data)
|
45
49
|
# Assign the error when HTTP error is not thrown from the previous filter
|
46
|
-
retry_data[:error] = response.error if response && !response.success?
|
47
|
-
if retry_data.has_key?(:error)
|
48
|
-
raise retry_data[:error]
|
50
|
+
@retry_data[:error] = response.error if response && !response.success?
|
51
|
+
if @retry_data.has_key?(:error)
|
52
|
+
raise @retry_data[:error]
|
49
53
|
else
|
50
54
|
response
|
51
55
|
end
|
@@ -37,8 +37,8 @@ module Azure
|
|
37
37
|
attr_accessor :account_name
|
38
38
|
attr_accessor :signer
|
39
39
|
|
40
|
-
def call(method, uri, body=nil, headers=nil)
|
41
|
-
super(method, uri, body, headers)
|
40
|
+
def call(method, uri, body=nil, headers=nil, options={})
|
41
|
+
super(method, uri, body, headers, options)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
data/lib/azure/core/version.rb
CHANGED
data/test/support/fixtures.rb
CHANGED
@@ -48,5 +48,18 @@ module Azure
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
class NewUriRetryPolicy < Azure::Core::Http::RetryPolicy
|
52
|
+
def initialize
|
53
|
+
@count = 1
|
54
|
+
super &:should_retry?
|
55
|
+
end
|
56
|
+
|
57
|
+
def should_retry?(response, retry_data)
|
58
|
+
retry_data[:uri] = URI.parse "http://bar.com"
|
59
|
+
@count = @count - 1
|
60
|
+
@count >= 0
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
51
64
|
end
|
52
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azure-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Microsoft Corporation
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
209
|
version: '0'
|
210
210
|
requirements: []
|
211
211
|
rubyforge_project:
|
212
|
-
rubygems_version: 2.
|
212
|
+
rubygems_version: 2.7.2
|
213
213
|
signing_key:
|
214
214
|
specification_version: 4
|
215
215
|
summary: Core library to be consumed by Ruby SDK gems
|