faraday-retry 2.1.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2b88675fec154db2d70b835b98124879b77dbcd283b898fea74fe88c1a75a4b
4
- data.tar.gz: 57eefe94dd39d192dff652e90cfadda2ce06d244a3a20e849dd9f3df6a88ffb4
3
+ metadata.gz: 4215b6f0b7dd61fa8702103e77d6373cace2c46b469defeb0ed93ce94aa26e6c
4
+ data.tar.gz: 295faca61565e49a36a7f03201d6aee90b6a353c40d22a8bf8e1f6b1c729c041
5
5
  SHA512:
6
- metadata.gz: de85932e530b33168b83399f0135fd862071c10318faaaef324935c3e51bc1914dd9361c68a5c2a6d3a4fc81e9f0193b928a4fe65c2dbc34826998573465af86
7
- data.tar.gz: f5e12ca382154fac0fbff872f9f906a62c0a990b06226363c701fa52d05ee927d23b0358f005e6de974e7fad938944beb2621413419b48a5d43b29e4b3180af8
6
+ metadata.gz: 5b8f2bee0e35492efc578659ce28a0b947374c8cafdba07606d953c417e8844128248a639392e4ad60c682528c0d478d3a894ca688e1f72965172633aee3be7f
7
+ data.tar.gz: 148ac2094f76cd59ea9278a4d1948b3211f0c2abc1876b6f10fbdd88a384257dfdfab33f9a1cf102ed23352b5b0dd2e9f1f4d533cd8459c4b86d1f5e7578a053
data/CHANGELOG.md CHANGED
@@ -1,14 +1,20 @@
1
1
  # Changelog
2
2
 
3
- ## v2.1.1 (2023-02-17)
3
+ ## Unreleased
4
4
 
5
- ### Changed
5
+ * Avoid deprecation warning about ::UploadIO constant when used without faraday-multipart gem [PR #37](https://github.com/lostisland/faraday-retry/pull/37) [@iMacTia]
6
+ * Documentation update [PR #30](https://github.com/lostisland/faraday-retry/pull/30) [@olleolleolle]
7
+ * Documentation update [PR #32](https://github.com/lostisland/faraday-retry/pull/32) Thanks, [@Drowze]!
6
8
 
7
- * Support for custom RateLimit headers. [PR #13](https://github.com/lostisland/faraday-retry/pull/13). Thanks, [@brookemckim]!
9
+ ## v2.2.0 (2023-06-01)
10
+
11
+ * Support new `header_parser_block` option. [PR #28](https://github.com/lostisland/faraday-retry/pull/28). Thanks, [@zavan]!
8
12
 
9
- ## v2.1.0 (2023-02-17)
13
+ ## v2.1.0 (2023-03-03)
14
+
15
+ * Support for custom RateLimit headers. [PR #13](https://github.com/lostisland/faraday-retry/pull/13). Thanks, [@brookemckim]!
10
16
 
11
- Invalid release, use v2.1.1.
17
+ v2.1.1 (2023-02-17) is a spurious not-released version that you may have seen mentioned in this CHANGELOG.
12
18
 
13
19
  ## v2.0.0 (2022-06-08)
14
20
 
@@ -33,3 +39,7 @@ This release consists of the same middleware that was previously bundled with Fa
33
39
 
34
40
  [@maxprokopiev]: https://github.com/maxprokopiev
35
41
  [@brookemckim]: https://github.com/brookemckim
42
+ [@zavan]: https://github.com/zavan
43
+ [@Drowze]: https://github.com/Drowze
44
+ [@olleolleolle]: https://github.com/olleolleolle
45
+ [@iMacTia]: https://github.com/iMacTia
data/README.md CHANGED
@@ -75,7 +75,7 @@ retry_options = {
75
75
  #### Specify which exceptions should trigger a retry
76
76
 
77
77
  You can provide an `exceptions` option with a list of exceptions that will replace
78
- the default list of network-related exceptions: `Errno::ETIMEDOUT`, `Timeout::Error`, `Faraday::TimeoutError`.
78
+ the default exceptions: `Errno::ETIMEDOUT`, `Timeout::Error`, `Faraday::TimeoutError`, `Faraday::Error::RetriableResponse`.
79
79
  This can be particularly useful when combined with the [RaiseError][raise_error] middleware.
80
80
 
81
81
  ```ruby
@@ -84,6 +84,14 @@ retry_options = {
84
84
  }
85
85
  ```
86
86
 
87
+ If you want to inherit default exceptions, do it this way.
88
+
89
+ ```ruby
90
+ retry_options = {
91
+ exceptions: Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ResourceNotFound, Faraday::UnauthorizedError]
92
+ }
93
+ ```
94
+
87
95
  #### Specify on which response statuses to retry
88
96
 
89
97
  By default the `Retry` middleware will only retry the request if one of the expected exceptions arise.
@@ -111,13 +119,14 @@ retry_options = {
111
119
  }
112
120
  ```
113
121
 
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.
122
+ 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
123
 
116
124
  ```ruby
117
125
  retry_options = {
118
126
  retry_statuses: [429],
119
127
  rate_limit_retry_header: 'x-rate-limit-retry-after',
120
- rate_limit_reset_header: 'x-rate-limit-reset'
128
+ rate_limit_reset_header: 'x-rate-limit-reset',
129
+ header_parser_block: ->(value) { Time.at(value.to_i).utc - Time.now.utc }
121
130
  }
122
131
  ```
123
132
 
@@ -143,10 +152,8 @@ retry_options = {
143
152
  You can specify a proc object through the `retry_block` option that will be called before every
144
153
  retry, before There are many different applications for this feature, spacing from instrumentation to monitoring.
145
154
 
146
-
147
155
  The block is passed keyword arguments with contextual information: Request environment, middleware options, current number of retries, exception, and amount of time we will wait before retrying. (retry_block is called before the wait time happens)
148
156
 
149
-
150
157
  For example, you might want to keep track of the response statuses:
151
158
 
152
159
  ```ruby
@@ -176,4 +183,4 @@ Bug reports and pull requests are welcome on [GitHub](https://github.com/lostisl
176
183
 
177
184
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
178
185
 
179
- [raise_error]: https://lostisland.github.io/faraday/middleware/raise-error
186
+ [raise_error]: https://lostisland.github.io/faraday/#/middleware/included/raising-errors
@@ -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
 
@@ -95,8 +95,8 @@ module Faraday
95
95
  # 'Timeout::Error', Faraday::TimeoutError, Faraday::RetriableResponse])
96
96
  # The list of exceptions to handle. Exceptions can be given as
97
97
  # Class, Module, or String.
98
- # @option options [Array] :methods (the idempotent HTTP methods
99
- # in IDEMPOTENT_METHODS) A list of HTTP methods to retry without
98
+ # @option options [Array<Symbol>] :methods (the idempotent HTTP methods
99
+ # in IDEMPOTENT_METHODS) A list of HTTP methods, as symbols, to retry without
100
100
  # calling retry_if. Pass an empty Array to call retry_if
101
101
  # for all exceptions.
102
102
  # @option options [Block] :retry_if (false) block that will receive
@@ -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)
@@ -205,11 +209,11 @@ module Faraday
205
209
  end
206
210
 
207
211
  def rewind_files(body)
208
- return unless defined?(UploadIO)
212
+ return unless defined?(Faraday::UploadIO)
209
213
  return unless body.is_a?(Hash)
210
214
 
211
215
  body.each do |_, value|
212
- value.rewind if value.is_a?(UploadIO)
216
+ value.rewind if value.is_a?(Faraday::UploadIO)
213
217
  end
214
218
  end
215
219
 
@@ -244,12 +248,16 @@ module Faraday
244
248
 
245
249
  retry_after_value = env[:response_headers][header]
246
250
 
247
- # Try to parse date from the header value
248
- begin
249
- datetime = DateTime.rfc2822(retry_after_value)
250
- datetime.to_time - Time.now.utc
251
- rescue ArgumentError
252
- retry_after_value.to_f
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module Retry
5
- VERSION = '2.1.0'
5
+ VERSION = '2.2.1'
6
6
  end
7
7
  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.1.0
4
+ version: 2.2.1
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-03-03 00:00:00.000000000 Z
11
+ date: 2024-04-15 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.1.0/CHANGELOG.md
161
- documentation_uri: http://www.rubydoc.info/gems/faraday-retry/2.1.0
160
+ changelog_uri: https://github.com/lostisland/faraday-retry/blob/v2.2.1/CHANGELOG.md
161
+ documentation_uri: http://www.rubydoc.info/gems/faraday-retry/2.2.1
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: