microsoft_kiota_faraday 0.26.0 → 0.27.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/lib/microsoft_kiota_faraday/kiota_client_factory.rb +4 -5
- data/lib/microsoft_kiota_faraday/middleware/body_inspection_option.rb +2 -1
- data/lib/microsoft_kiota_faraday/middleware/retry_handler.rb +20 -4
- data/lib/microsoft_kiota_faraday/middleware/retry_handler_option.rb +15 -2
- data/lib/microsoft_kiota_faraday/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3da6955eda884a0c15e44c4ebca183743f2df5885b548bfc35a93d8ffb76693
|
|
4
|
+
data.tar.gz: 0d642edb7b9b03cf4fff93f15a8dcca9750f8befc249fbbadcc268a4ec864d26
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ff7aff496686cb0a21b0992241687818700751b99339fa9aaef273a63bdb8e67bc907f9c4e10ce7241685bc58f441cc2864448dc5c9784a634b9a6cfd4163bd
|
|
7
|
+
data.tar.gz: 38fcfb238907fbfa0f215e569b5b1427d0a6572c7c88c0a56ab590c882c8565e2c37e4fcbdada5807fd8d9dbb1a9b029294b6524f08392da2287eabf8de72a2e
|
|
@@ -12,13 +12,12 @@ module MicrosoftKiotaFaraday
|
|
|
12
12
|
class KiotaClientFactory
|
|
13
13
|
def self.get_default_middleware
|
|
14
14
|
[
|
|
15
|
-
# Inspect the original request before redirects buffer or rewrite it.
|
|
16
|
-
MicrosoftKiotaFaraday::Middleware::BodyInspectionHandler,
|
|
17
|
-
MicrosoftKiotaFaraday::Middleware::RedirectHandler,
|
|
18
|
-
MicrosoftKiotaFaraday::Middleware::RetryHandler,
|
|
19
15
|
MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler,
|
|
20
16
|
MicrosoftKiotaFaraday::Middleware::UserAgentHandler,
|
|
21
|
-
MicrosoftKiotaFaraday::Middleware::
|
|
17
|
+
MicrosoftKiotaFaraday::Middleware::RedirectHandler,
|
|
18
|
+
MicrosoftKiotaFaraday::Middleware::RetryHandler,
|
|
19
|
+
MicrosoftKiotaFaraday::Middleware::HeadersInspectionHandler,
|
|
20
|
+
MicrosoftKiotaFaraday::Middleware::BodyInspectionHandler
|
|
22
21
|
]
|
|
23
22
|
end
|
|
24
23
|
|
|
@@ -5,7 +5,8 @@ require 'microsoft_kiota_abstractions'
|
|
|
5
5
|
|
|
6
6
|
module MicrosoftKiotaFaraday
|
|
7
7
|
module Middleware
|
|
8
|
-
# Opt in per request.
|
|
8
|
+
# Opt in per request. Each capture replaces the previous snapshot, and the caller
|
|
9
|
+
# owns and should close any in-memory copy it keeps.
|
|
9
10
|
# Capturing large payloads increases memory use; non-seekable streams are skipped.
|
|
10
11
|
class BodyInspectionOption
|
|
11
12
|
include MicrosoftKiotaAbstractions::RequestOption
|
|
@@ -17,6 +17,10 @@ module MicrosoftKiotaFaraday
|
|
|
17
17
|
RETRY_AFTER_HEADER = 'Retry-After'
|
|
18
18
|
MAX_DELAY = RetryHandlerOption::MAX_DELAY
|
|
19
19
|
DRAIN_CHUNK_SIZE = 16 * 1024
|
|
20
|
+
NON_IDEMPOTENT_METHODS = %w[POST PATCH].freeze
|
|
21
|
+
# By common service convention, these status codes mean the server didn't process the
|
|
22
|
+
# request, so resending it is treated as safe for any method.
|
|
23
|
+
UNPROCESSED_STATUS_CODES = [429, 503].freeze
|
|
20
24
|
|
|
21
25
|
# @param app [#call] the next Faraday handler in the stack
|
|
22
26
|
# @param default_option [RetryHandlerOption, nil] used for requests that don't carry their
|
|
@@ -37,7 +41,7 @@ module MicrosoftKiotaFaraday
|
|
|
37
41
|
position = body_position(request_body)
|
|
38
42
|
response = @app.call(retry_env(request_env, request_body, nil))
|
|
39
43
|
|
|
40
|
-
return response unless request_option.max_retries.positive? && retryable?(
|
|
44
|
+
return response unless request_option.max_retries.positive? && retryable?(request_env, response, 0, request_option)
|
|
41
45
|
|
|
42
46
|
retry_until_resolved(request_env, request_body, response, request_option, position)
|
|
43
47
|
end
|
|
@@ -73,7 +77,7 @@ module MicrosoftKiotaFaraday
|
|
|
73
77
|
retries += 1
|
|
74
78
|
sleep delay
|
|
75
79
|
response = @app.call(retry_env(request_env, request_body, retries))
|
|
76
|
-
return response unless retryable?(
|
|
80
|
+
return response unless retryable?(request_env, response, retries, request_option)
|
|
77
81
|
end
|
|
78
82
|
end
|
|
79
83
|
|
|
@@ -87,9 +91,21 @@ module MicrosoftKiotaFaraday
|
|
|
87
91
|
env
|
|
88
92
|
end
|
|
89
93
|
|
|
90
|
-
def retryable?(
|
|
94
|
+
def retryable?(request_env, response, retries, request_option)
|
|
95
|
+
request_body = request_env[:body]
|
|
91
96
|
(!request_body.respond_to?(:read) || request_body.respond_to?(:seek)) &&
|
|
92
|
-
request_option.should_retry.call(request_option.delay, retries, response)
|
|
97
|
+
request_option.should_retry.call(request_option.delay, retries, response) &&
|
|
98
|
+
retryable_for_method?(request_env[:method], response, request_option)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# With retry_unprocessed_mutations_only set, POST and PATCH requests are retried only after a
|
|
102
|
+
# response showing the server didn't process them, because a 504 may arrive after the server
|
|
103
|
+
# already acted on the request. Each retry resends request_env, so its method is the one to check.
|
|
104
|
+
def retryable_for_method?(method, response, request_option)
|
|
105
|
+
return true unless request_option.retry_unprocessed_mutations_only
|
|
106
|
+
return true unless NON_IDEMPOTENT_METHODS.include?(method.to_s.upcase)
|
|
107
|
+
|
|
108
|
+
UNPROCESSED_STATUS_CODES.include?(response.status)
|
|
93
109
|
end
|
|
94
110
|
|
|
95
111
|
def retry_delay(value, retries, request_option)
|
|
@@ -14,7 +14,7 @@ module MicrosoftKiotaFaraday
|
|
|
14
14
|
# @return [Proc] the default retry policy: retries 429, 503 and 504 responses
|
|
15
15
|
DEFAULT_SHOULD_RETRY = ->(_delay, _retries, response) { RETRYABLE_STATUS_CODES.include?(response.status) }
|
|
16
16
|
|
|
17
|
-
attr_reader :max_retries, :delay, :should_retry, :retries_time_limit
|
|
17
|
+
attr_reader :max_retries, :delay, :should_retry, :retries_time_limit, :retry_unprocessed_mutations_only
|
|
18
18
|
|
|
19
19
|
# @param max_retries [Integer] maximum number of retry attempts (0..10)
|
|
20
20
|
# @param delay [Integer] base delay in seconds for exponential backoff (0..180)
|
|
@@ -22,7 +22,19 @@ module MicrosoftKiotaFaraday
|
|
|
22
22
|
# returns whether the response should be retried. Defaults to {DEFAULT_SHOULD_RETRY}.
|
|
23
23
|
# @param retries_time_limit [Numeric] maximum cumulative delay in seconds to spend waiting
|
|
24
24
|
# across all retries, or 0 (the default) for no limit
|
|
25
|
-
|
|
25
|
+
# @param retry_unprocessed_mutations_only [Boolean] whether POST and PATCH requests are retried
|
|
26
|
+
# only after a response showing the server didn't process them. Defaults to false.
|
|
27
|
+
# POST and PATCH aren't idempotent, so resending one the server already processed can repeat
|
|
28
|
+
# its side effect, such as sending an email twice. A 504 can arrive after the server processed
|
|
29
|
+
# the request. When this is true, POST and PATCH requests are retried only after a 429 or 503
|
|
30
|
+
# response, and any other response is returned to the caller, even when should_retry accepts it.
|
|
31
|
+
# This relies on the common service convention, followed by Microsoft Graph, that a 429 or 503
|
|
32
|
+
# response means the server didn't process the request. HTTP doesn't guarantee this, so a
|
|
33
|
+
# service that returns 429 or 503 after acting on a request can still see it repeated. PUT and
|
|
34
|
+
# DELETE also change state, but they're idempotent, so they aren't affected, and neither are
|
|
35
|
+
# other methods.
|
|
36
|
+
def initialize(max_retries: 3, delay: 3, should_retry: DEFAULT_SHOULD_RETRY, retries_time_limit: 0,
|
|
37
|
+
retry_unprocessed_mutations_only: false)
|
|
26
38
|
raise ArgumentError, "max_retries must be between 0 and #{MAX_RETRIES}" unless max_retries.is_a?(Integer) && (0..MAX_RETRIES).cover?(max_retries)
|
|
27
39
|
raise ArgumentError, "delay must be between 0 and #{MAX_DELAY}" unless (0..MAX_DELAY).cover?(delay)
|
|
28
40
|
raise ArgumentError, 'retries_time_limit must be non-negative' if retries_time_limit.negative?
|
|
@@ -31,6 +43,7 @@ module MicrosoftKiotaFaraday
|
|
|
31
43
|
@delay = delay
|
|
32
44
|
@should_retry = should_retry
|
|
33
45
|
@retries_time_limit = retries_time_limit
|
|
46
|
+
@retry_unprocessed_mutations_only = retry_unprocessed_mutations_only
|
|
34
47
|
end
|
|
35
48
|
|
|
36
49
|
# @return [String] the key this option is registered under in the request context
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: microsoft_kiota_faraday
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.27.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Microsoft Corporation
|
|
@@ -35,14 +35,14 @@ dependencies:
|
|
|
35
35
|
requirements:
|
|
36
36
|
- - '='
|
|
37
37
|
- !ruby/object:Gem::Version
|
|
38
|
-
version: 0.
|
|
38
|
+
version: 0.27.0
|
|
39
39
|
type: :runtime
|
|
40
40
|
prerelease: false
|
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
42
42
|
requirements:
|
|
43
43
|
- - '='
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
|
-
version: 0.
|
|
45
|
+
version: 0.27.0
|
|
46
46
|
- !ruby/object:Gem::Dependency
|
|
47
47
|
name: rake
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|