faraday-retry 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -5
- data/README.md +3 -2
- data/lib/faraday/retry/middleware.rb +15 -7
- data/lib/faraday/retry/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4c985b60e619c7a2161b8643fda86adcd4927847a66d903bbc22a32ed851d13
|
4
|
+
data.tar.gz: 010d8a002a7310f82c44395344cc81cb3f8acfe9e53ca8aae8ae84cd3b66d90a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6dc78fe8c3b3ccc189c086271eb646e06f6e598a0a2b311ce3f0831321ba8f00b01d24be1c29521f7bbef5367eb17c43be7f6dfaa6402f0ec9cf206483f8794
|
7
|
+
data.tar.gz: 6338884c1806a7d06f33457db3939d71aaf761c9cc8c427a14c68257600d0601ff6765dde9b061254fd5af8f4ff77315d018a8d42d5326842fd0d26d0e52219f
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## v2.
|
3
|
+
## v2.2.0 (2023-06-01)
|
4
4
|
|
5
|
-
|
5
|
+
* Support new `header_parser_block` option. [PR #28](https://github.com/lostisland/faraday-retry/pull/28). Thanks, [@zavan]!
|
6
6
|
|
7
|
-
|
7
|
+
## v2.1.0 (2023-03-03)
|
8
8
|
|
9
|
-
|
9
|
+
* Support for custom RateLimit headers. [PR #13](https://github.com/lostisland/faraday-retry/pull/13). Thanks, [@brookemckim]!
|
10
10
|
|
11
|
-
|
11
|
+
v2.1.1 (2023-02-17) is a spurious not-released version that you may have seen mentioned in this CHANGELOG.
|
12
12
|
|
13
13
|
## v2.0.0 (2022-06-08)
|
14
14
|
|
@@ -33,3 +33,4 @@ This release consists of the same middleware that was previously bundled with Fa
|
|
33
33
|
|
34
34
|
[@maxprokopiev]: https://github.com/maxprokopiev
|
35
35
|
[@brookemckim]: https://github.com/brookemckim
|
36
|
+
[@zavan]: https://github.com/zavan
|
data/README.md
CHANGED
@@ -111,13 +111,14 @@ retry_options = {
|
|
111
111
|
}
|
112
112
|
```
|
113
113
|
|
114
|
-
If you are working with an API which does not comply with the Rate Limit RFC you can specify custom headers to be used for retry and reset
|
114
|
+
If you are working with an API which does not comply with the Rate Limit RFC you can specify custom headers to be used for retry and reset, as well as a block to parse the headers:
|
115
115
|
|
116
116
|
```ruby
|
117
117
|
retry_options = {
|
118
118
|
retry_statuses: [429],
|
119
119
|
rate_limit_retry_header: 'x-rate-limit-retry-after',
|
120
|
-
rate_limit_reset_header: 'x-rate-limit-reset'
|
120
|
+
rate_limit_reset_header: 'x-rate-limit-reset',
|
121
|
+
header_parser_block: ->(value) { Time.at(value.to_i).utc - Time.now.utc }
|
121
122
|
}
|
122
123
|
```
|
123
124
|
|
@@ -27,7 +27,7 @@ module Faraday
|
|
27
27
|
:backoff_factor, :exceptions,
|
28
28
|
:methods, :retry_if, :retry_block,
|
29
29
|
:retry_statuses, :rate_limit_retry_header,
|
30
|
-
:rate_limit_reset_header)
|
30
|
+
:rate_limit_reset_header, :header_parser_block)
|
31
31
|
|
32
32
|
DEFAULT_CHECK = ->(_env, _exception) { false }
|
33
33
|
|
@@ -120,6 +120,10 @@ module Faraday
|
|
120
120
|
# codes or a single Integer value that determines whether to raise
|
121
121
|
# a Faraday::RetriableResponse exception based on the HTTP status code
|
122
122
|
# of an HTTP response.
|
123
|
+
# @option options [Block] :header_parser_block block that will receive
|
124
|
+
# the the value of the retry header and should return the number of
|
125
|
+
# seconds to wait before retrying the request. This is useful if the
|
126
|
+
# value of the header is not a number of seconds or a RFC 2822 formatted date.
|
123
127
|
def initialize(app, options = nil)
|
124
128
|
super(app)
|
125
129
|
@options = Options.from(options)
|
@@ -244,12 +248,16 @@ module Faraday
|
|
244
248
|
|
245
249
|
retry_after_value = env[:response_headers][header]
|
246
250
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
251
|
+
if @options.header_parser_block
|
252
|
+
@options.header_parser_block.call(retry_after_value)
|
253
|
+
else
|
254
|
+
# Try to parse date from the header value
|
255
|
+
begin
|
256
|
+
datetime = DateTime.rfc2822(retry_after_value)
|
257
|
+
datetime.to_time - Time.now.utc
|
258
|
+
rescue ArgumentError
|
259
|
+
retry_after_value.to_f
|
260
|
+
end
|
253
261
|
end
|
254
262
|
end
|
255
263
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-retry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Giuffrida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -157,8 +157,8 @@ licenses:
|
|
157
157
|
- MIT
|
158
158
|
metadata:
|
159
159
|
bug_tracker_uri: https://github.com/lostisland/faraday-retry/issues
|
160
|
-
changelog_uri: https://github.com/lostisland/faraday-retry/blob/v2.
|
161
|
-
documentation_uri: http://www.rubydoc.info/gems/faraday-retry/2.
|
160
|
+
changelog_uri: https://github.com/lostisland/faraday-retry/blob/v2.2.0/CHANGELOG.md
|
161
|
+
documentation_uri: http://www.rubydoc.info/gems/faraday-retry/2.2.0
|
162
162
|
homepage_uri: https://github.com/lostisland/faraday-retry
|
163
163
|
source_code_uri: https://github.com/lostisland/faraday-retry
|
164
164
|
post_install_message:
|