lib/faraday/retry/middleware.rb in faraday-retry-2.0.0 vs lib/faraday/retry/middleware.rb in faraday-retry-2.1.0
- old
+ new
@@ -24,11 +24,12 @@
# Options contains the configurable parameters for the Retry middleware.
class Options < Faraday::Options.new(:max, :interval, :max_interval,
:interval_randomness,
:backoff_factor, :exceptions,
:methods, :retry_if, :retry_block,
- :retry_statuses)
+ :retry_statuses, :rate_limit_retry_header,
+ :rate_limit_reset_header)
DEFAULT_CHECK = ->(_env, _exception) { false }
def self.from(value)
if value.is_a?(Integer)
@@ -211,18 +212,20 @@
value.rewind if value.is_a?(UploadIO)
end
end
# RFC for RateLimit Header Fields for HTTP:
- # https://tools.ietf.org/id/draft-polli-ratelimit-headers-00.html#rfc.section.3.3
+ # https://www.ietf.org/archive/id/draft-ietf-httpapi-ratelimit-headers-05.html#name-fields-definition
def calculate_rate_limit_reset(env)
- parse_retry_header(env, 'RateLimit-Reset')
+ reset_header = @options.rate_limit_reset_header || 'RateLimit-Reset'
+ parse_retry_header(env, reset_header)
end
# MDN spec for Retry-After header:
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
def calculate_retry_after(env)
- parse_retry_header(env, 'Retry-After')
+ retry_header = @options.rate_limit_retry_header || 'Retry-After'
+ parse_retry_header(env, retry_header)
end
def calculate_retry_interval(retries)
retry_index = @options.max - retries
current_interval = @options.interval *