httpx 1.7.2 → 1.7.4

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/doc/release_notes/1_7_3.md +29 -0
  4. data/doc/release_notes/1_7_4.md +42 -0
  5. data/lib/httpx/adapters/datadog.rb +24 -60
  6. data/lib/httpx/adapters/webmock.rb +3 -4
  7. data/lib/httpx/connection/http1.rb +6 -1
  8. data/lib/httpx/connection/http2.rb +43 -30
  9. data/lib/httpx/connection.rb +74 -22
  10. data/lib/httpx/plugins/auth/digest.rb +2 -1
  11. data/lib/httpx/plugins/brotli.rb +33 -5
  12. data/lib/httpx/plugins/cookies/cookie.rb +34 -11
  13. data/lib/httpx/plugins/cookies/jar.rb +93 -18
  14. data/lib/httpx/plugins/cookies.rb +7 -3
  15. data/lib/httpx/plugins/expect.rb +30 -3
  16. data/lib/httpx/plugins/fiber_concurrency.rb +2 -4
  17. data/lib/httpx/plugins/follow_redirects.rb +7 -1
  18. data/lib/httpx/plugins/h2c.rb +1 -1
  19. data/lib/httpx/plugins/proxy/http.rb +15 -8
  20. data/lib/httpx/plugins/proxy.rb +10 -2
  21. data/lib/httpx/plugins/rate_limiter.rb +19 -19
  22. data/lib/httpx/plugins/retries.rb +17 -9
  23. data/lib/httpx/plugins/ssrf_filter.rb +1 -0
  24. data/lib/httpx/plugins/stream_bidi.rb +6 -0
  25. data/lib/httpx/plugins/tracing.rb +137 -0
  26. data/lib/httpx/request.rb +1 -1
  27. data/lib/httpx/resolver/multi.rb +1 -8
  28. data/lib/httpx/resolver/native.rb +1 -1
  29. data/lib/httpx/resolver/resolver.rb +21 -2
  30. data/lib/httpx/resolver/system.rb +3 -1
  31. data/lib/httpx/selector.rb +4 -4
  32. data/lib/httpx/session.rb +11 -6
  33. data/lib/httpx/version.rb +1 -1
  34. data/sig/chainable.rbs +2 -1
  35. data/sig/connection/http1.rbs +2 -0
  36. data/sig/connection/http2.rbs +11 -4
  37. data/sig/connection.rbs +7 -0
  38. data/sig/plugins/brotli.rbs +11 -6
  39. data/sig/plugins/cookies/cookie.rbs +3 -2
  40. data/sig/plugins/cookies/jar.rbs +11 -0
  41. data/sig/plugins/cookies.rbs +2 -0
  42. data/sig/plugins/expect.rbs +17 -2
  43. data/sig/plugins/proxy/socks4.rbs +4 -0
  44. data/sig/plugins/rate_limiter.rbs +2 -2
  45. data/sig/plugins/response_cache.rbs +3 -3
  46. data/sig/plugins/retries.rbs +17 -13
  47. data/sig/plugins/tracing.rbs +41 -0
  48. data/sig/request.rbs +1 -0
  49. data/sig/resolver/native.rbs +2 -0
  50. data/sig/resolver/resolver.rbs +4 -2
  51. data/sig/resolver/system.rbs +0 -2
  52. data/sig/response/body.rbs +1 -1
  53. data/sig/selector.rbs +4 -0
  54. data/sig/session.rbs +2 -0
  55. data/sig/transcoder/gzip.rbs +1 -1
  56. data/sig/transcoder.rbs +0 -2
  57. metadata +9 -3
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HTTPX::Plugins
4
+ #
5
+ # This plugin adds a simple interface to integrate request tracing SDKs.
6
+ #
7
+ # An example of such an integration is the datadog adapter.
8
+ #
9
+ # https://gitlab.com/os85/httpx/wikis/Tracing
10
+ #
11
+ module Tracing
12
+ class Wrapper
13
+ attr_reader :tracers
14
+ protected :tracers
15
+
16
+ def initialize(*tracers)
17
+ @tracers = tracers.flat_map do |tracer|
18
+ case tracer
19
+ when Wrapper
20
+ tracer.tracers
21
+ else
22
+ tracer
23
+ end
24
+ end.uniq
25
+ end
26
+
27
+ def merge(tracer)
28
+ case tracer
29
+ when Wrapper
30
+ Wrapper.new(*@tracers, *tracer.tracers)
31
+ else
32
+ Wrapper.new(*@tracers, tracer)
33
+ end
34
+ end
35
+
36
+ def freeze
37
+ @tracers.each(&:freeze).freeze
38
+ super
39
+ end
40
+
41
+ %i[start finish reset enabled?].each do |callback|
42
+ class_eval(<<-OUT, __FILE__, __LINE__ + 1)
43
+ # proxies ##{callback} calls to wrapper tracers.
44
+ def #{callback}(*args) # def start(*args)
45
+ @tracers.each { |t| t.#{callback}(*args) } # @tracers.each { |t| t.start(*args) }
46
+ end # end
47
+ OUT
48
+ end
49
+ end
50
+
51
+ # adds support for the following options:
52
+ #
53
+ # :tracer :: object which responds to #start, #finish and #reset.
54
+ module OptionsMethods
55
+ private
56
+
57
+ def option_tracer(tracer)
58
+ unless tracer.respond_to?(:start) &&
59
+ tracer.respond_to?(:finish) &&
60
+ tracer.respond_to?(:reset) &&
61
+ tracer.respond_to?(:enabled?)
62
+ raise TypeError, "#{tracer} must to respond to `#start(r)`, `#finish` and `#reset` and `#enabled?"
63
+ end
64
+
65
+ tracer = Wrapper.new(@tracer, tracer) if @tracer
66
+ tracer
67
+ end
68
+ end
69
+
70
+ module RequestMethods
71
+ attr_accessor :init_time
72
+
73
+ # intercepts request initialization to inject the tracing logic.
74
+ def initialize(*)
75
+ super
76
+
77
+ @init_time = nil
78
+
79
+ tracer = @options.tracer
80
+
81
+ return unless tracer && tracer.enabled?(self)
82
+
83
+ on(:idle) do
84
+ tracer.reset(self)
85
+
86
+ # request is reset when it's retried.
87
+ @init_time = nil
88
+ end
89
+ on(:headers) do
90
+ # the usual request init time (when not including the connection handshake)
91
+ # should be the time the request is buffered the first time.
92
+ @init_time ||= ::Time.now
93
+
94
+ tracer.start(self)
95
+ end
96
+ on(:response) { |response| tracer.finish(self, response) }
97
+ end
98
+
99
+ def response=(*)
100
+ # init_time should be set when it's send to a connection.
101
+ # However, there are situations where connection initialization fails.
102
+ # Example is the :ssrf_filter plugin, which raises an error on
103
+ # initialize if the host is an IP which matches against the known set.
104
+ # in such cases, we'll just set here right here.
105
+ @init_time ||= ::Time.now
106
+
107
+ super
108
+ end
109
+ end
110
+
111
+ # Connection mixin
112
+ module ConnectionMethods
113
+ def initialize(*)
114
+ super
115
+
116
+ @init_time = ::Time.now
117
+ end
118
+
119
+ def send(request)
120
+ # request init time is only the same as the connection init time
121
+ # if the connection is going through the connection handshake.
122
+ request.init_time ||= @init_time unless open?
123
+
124
+ super
125
+ end
126
+
127
+ def idling
128
+ super
129
+
130
+ # time of initial request(s) is accounted from the moment
131
+ # the connection is back to :idle, and ready to connect again.
132
+ @init_time = ::Time.now
133
+ end
134
+ end
135
+ end
136
+ register_plugin :tracing, Tracing
137
+ end
data/lib/httpx/request.rb CHANGED
@@ -91,7 +91,7 @@ module HTTPX
91
91
  raise UnsupportedSchemeError, "#{@uri}: #{@uri.scheme}: unsupported URI scheme" unless ALLOWED_URI_SCHEMES.include?(@uri.scheme)
92
92
 
93
93
  @state = :idle
94
- @response = @peer_address = @informational_status = nil
94
+ @response = @drainer = @peer_address = @informational_status = nil
95
95
  @ping = false
96
96
  @persistent = @options.persistent
97
97
  @active_timeouts = []
@@ -71,14 +71,7 @@ module HTTPX
71
71
 
72
72
  def lazy_resolve(connection)
73
73
  @resolvers.each do |resolver|
74
- conn_to_resolve = @current_session.try_clone_connection(connection, @current_selector, resolver.family)
75
- resolver << conn_to_resolve
76
-
77
- next if resolver.empty?
78
-
79
- # both the resolver and the connection it's resolving must be pineed to the session
80
- @current_session.pin(conn_to_resolve, @current_selector)
81
- @current_session.select_resolver(resolver, @current_selector)
74
+ resolver.lazy_resolve(connection)
82
75
  end
83
76
  end
84
77
 
@@ -529,7 +529,7 @@ module HTTPX
529
529
 
530
530
  resolve if @queries.empty? && !@connections.empty?
531
531
  when :closed
532
- return unless @state == :open
532
+ return if @state == :closed
533
533
 
534
534
  @io.close if @io
535
535
  @start_timeout = nil
@@ -119,6 +119,11 @@ module HTTPX
119
119
  end
120
120
  end
121
121
 
122
+ def on_io_error(e)
123
+ on_error(e)
124
+ force_close(true)
125
+ end
126
+
122
127
  def on_error(error)
123
128
  handle_error(error)
124
129
  disconnect
@@ -138,6 +143,19 @@ module HTTPX
138
143
  true
139
144
  end
140
145
 
146
+ def lazy_resolve(connection)
147
+ return unless @current_session && @current_selector
148
+
149
+ conn_to_resolve = @current_session.try_clone_connection(connection, @current_selector, @family)
150
+ self << conn_to_resolve
151
+
152
+ return if empty?
153
+
154
+ # both the resolver and the connection it's resolving must be pinned to the session
155
+ @current_session.pin(conn_to_resolve, @current_selector)
156
+ @current_session.select_resolver(self, @current_selector)
157
+ end
158
+
141
159
  private
142
160
 
143
161
  def emit_resolved_connection(connection, addresses, early_resolve)
@@ -181,9 +199,10 @@ module HTTPX
181
199
  end
182
200
 
183
201
  def disconnect
184
- return if closed?
185
-
186
202
  close
203
+
204
+ return unless closed?
205
+
187
206
  @current_session.deselect_resolver(self, @current_selector)
188
207
  end
189
208
  end
@@ -116,7 +116,9 @@ module HTTPX
116
116
  @current_session.select_resolver(self, @current_selector)
117
117
  end
118
118
 
119
- def early_resolve(connection, **); end
119
+ def early_resolve(_, **) # rubocop:disable Naming/PredicateMethod
120
+ false
121
+ end
120
122
 
121
123
  def handle_socket_timeout(interval)
122
124
  error = HTTPX::ResolveTimeoutError.new(interval, "timed out while waiting on select")
@@ -204,8 +204,7 @@ module HTTPX
204
204
  rescue IOError => e
205
205
  (Array(r) + Array(w)).each do |sel|
206
206
  # TODO: is there a way to cheaply find the IO associated with the error?
207
- sel.on_error(e)
208
- sel.force_close(true)
207
+ sel.on_io_error(e)
209
208
  end
210
209
  rescue StandardError => e
211
210
  (Array(r) + Array(w)).each do |sel|
@@ -249,8 +248,9 @@ module HTTPX
249
248
  when :rw then rw_wait(io, interval)
250
249
  end
251
250
  rescue IOError => e
252
- io.on_error(e)
253
- io.force_close(true)
251
+ io.on_io_error(e)
252
+
253
+ return
254
254
  rescue StandardError => e
255
255
  io.on_error(e)
256
256
 
data/lib/httpx/session.rb CHANGED
@@ -140,9 +140,10 @@ module HTTPX
140
140
  end
141
141
  selector.deregister(connection)
142
142
 
143
+ # do not check-in connections only created for Happy Eyeballs
143
144
  return if cloned
144
145
 
145
- return if @closing && connection.state == :closed
146
+ return if @closing && connection.state == :closed && !connection.used?
146
147
 
147
148
  connection.log(level: 2) { "check-in connection##{connection.object_id}(#{connection.state}) in pool##{@pool.object_id}" }
148
149
  @pool.checkin_connection(connection)
@@ -177,16 +178,15 @@ module HTTPX
177
178
 
178
179
  # returns the HTTPX::Connection through which the +request+ should be sent through.
179
180
  def find_connection(request_uri, selector, options)
180
- log(level: 2) { "finding connection for #{request_uri}..." }
181
181
  if (connection = selector.find_connection(request_uri, options))
182
182
  connection.idling if connection.state == :closed
183
- connection.log(level: 2) { "found connection##{connection.object_id}(#{connection.state}) in selector##{selector.object_id}" }
183
+ log(level: 2) { "found connection##{connection.object_id}(#{connection.state}) in selector##{selector.object_id}" }
184
184
  return connection
185
185
  end
186
186
 
187
187
  connection = @pool.checkout_connection(request_uri, options)
188
188
 
189
- connection.log(level: 2) { "found connection##{connection.object_id}(#{connection.state}) in pool##{@pool.object_id}" }
189
+ log(level: 2) { "found connection##{connection.object_id}(#{connection.state}) in pool##{@pool.object_id}" }
190
190
 
191
191
  case connection.state
192
192
  when :idle
@@ -240,7 +240,7 @@ module HTTPX
240
240
 
241
241
  return unless response && response.finished?
242
242
 
243
- log(level: 2) { "response fetched" }
243
+ log(level: 2) { "response##{response.object_id} fetched" }
244
244
 
245
245
  response
246
246
  end
@@ -249,6 +249,7 @@ module HTTPX
249
249
  def send_request(request, selector, options = request.options)
250
250
  error = begin
251
251
  catch(:resolve_error) do
252
+ log(level: 2) { "finding connection for request##{request.object_id}..." }
252
253
  connection = find_connection(request.uri, selector, options)
253
254
  connection.send(request)
254
255
  end
@@ -391,7 +392,11 @@ module HTTPX
391
392
  resolver = find_resolver_for(connection, selector)
392
393
 
393
394
  pin(connection, selector)
394
- resolver.early_resolve(connection) || resolver.lazy_resolve(connection)
395
+ early_resolve(resolver, connection) || resolver.lazy_resolve(connection)
396
+ end
397
+
398
+ def early_resolve(resolver, connection)
399
+ resolver.early_resolve(connection)
395
400
  end
396
401
 
397
402
  def on_resolver_connection(connection, selector)
data/lib/httpx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPX
4
- VERSION = "1.7.2"
4
+ VERSION = "1.7.4"
5
5
  end
data/sig/chainable.rbs CHANGED
@@ -29,7 +29,7 @@ module HTTPX
29
29
  | (:proxy, ?options) -> (Plugins::sessionProxy & Plugins::httpProxy)
30
30
  | (:push_promise, ?options) -> Plugins::sessionPushPromise
31
31
  | (:retries, ?options) -> Plugins::sessionRetries
32
- | (:rate_limiter, ?options) -> Session
32
+ | (:rate_limiter, ?options) -> Plugins::sessionRateLimiter
33
33
  | (:stream, ?options) -> Plugins::sessionStream
34
34
  | (:stream_bidi, ?options) -> Plugins::sessionStreamBidi
35
35
  | (:aws_sigv4, ?options) -> Plugins::awsSigV4Session
@@ -43,6 +43,7 @@ module HTTPX
43
43
  | (:webdav, ?options) -> Plugins::sessionWebDav
44
44
  | (:xml, ?options) -> Plugins::sessionXML
45
45
  | (:query, ?options) -> Plugins::sessionQuery
46
+ | (:tracing, ?options) -> Plugins::sessionTracing
46
47
  | (Symbol | Module, ?options) { (Class) -> void } -> Session
47
48
  | (Symbol | Module, ?options) -> Session
48
49
 
@@ -26,6 +26,8 @@ module HTTPX
26
26
 
27
27
  def reset: () -> void
28
28
 
29
+ def reset_requests: () -> void
30
+
29
31
  def close: () -> void
30
32
 
31
33
  def empty?: () -> bool
@@ -6,6 +6,7 @@ module HTTPX
6
6
  MAX_CONCURRENT_REQUESTS: Integer
7
7
 
8
8
  attr_reader streams: Hash[Request, ::HTTP2::Stream]
9
+
9
10
  attr_reader pending: Array[Request]
10
11
 
11
12
  @connection: HTTP2::Client
@@ -43,6 +44,8 @@ module HTTPX
43
44
 
44
45
  def timeout: () -> Numeric?
45
46
 
47
+ def reset_requests: () -> void
48
+
46
49
  private
47
50
 
48
51
  def initialize: (Buffer buffer, Options options) -> untyped
@@ -79,6 +82,8 @@ module HTTPX
79
82
 
80
83
  def on_stream_refuse: (::HTTP2::Stream stream, Request request, StandardError error) -> void
81
84
 
85
+ def on_stream_half_close: (::HTTP2::Stream stream, Request request) -> void
86
+
82
87
  def on_stream_close: (::HTTP2::Stream stream, Request request, (Symbol | StandardError)? error) -> void
83
88
 
84
89
  def on_frame: (string bytes) -> void
@@ -87,13 +92,15 @@ module HTTPX
87
92
 
88
93
  def on_close: (Integer last_frame, Symbol? error, String? payload) -> void
89
94
 
90
- def on_frame_sent: (::HTTP2::frame) -> void
95
+ def on_frame_sent: (::HTTP2::frame frame) -> void
96
+
97
+ def frame_with_extra_info: (::HTTP2::frame frame) -> Hash[Symbol, untyped]
91
98
 
92
- def on_frame_received: (::HTTP2::frame) -> void
99
+ def on_frame_received: (::HTTP2::frame frame) -> void
93
100
 
94
- def on_altsvc: (String origin, ::HTTP2::frame) -> void
101
+ def on_altsvc: (String origin, ::HTTP2::frame frame) -> void
95
102
 
96
- def on_promise: (::HTTP2::Stream) -> void
103
+ def on_promise: (::HTTP2::Stream stream) -> void
97
104
 
98
105
  def on_origin: (String) -> void
99
106
 
data/sig/connection.rbs CHANGED
@@ -37,6 +37,7 @@ module HTTPX
37
37
  @read_buffer: Buffer
38
38
  @write_buffer: Buffer
39
39
  @inflight: Integer
40
+ @max_concurrent_requests: Integer?
40
41
  @keep_alive_timeout: Numeric?
41
42
  @timeout: Numeric?
42
43
  @current_timeout: Numeric?
@@ -119,6 +120,10 @@ module HTTPX
119
120
 
120
121
  def on_error: (HTTPX::TimeoutError | Error | StandardError error, ?Request? request) -> void
121
122
 
123
+ def on_io_error: (IOError error) -> void
124
+
125
+ def on_connect_error: (Exception error) -> void
126
+
122
127
  private
123
128
 
124
129
  def initialize: (http_uri uri, Options options) -> void
@@ -153,6 +158,8 @@ module HTTPX
153
158
 
154
159
  def handle_error: (StandardError error, ?Request? request) -> void
155
160
 
161
+ def force_purge: () -> void
162
+
156
163
  def close_sibling: () -> void
157
164
 
158
165
  def purge_after_closed: () -> void
@@ -5,17 +5,22 @@ module HTTPX
5
5
 
6
6
  def self?.encode: (body_encoder body) -> Deflater
7
7
 
8
- def self?.decode: (HTTPX::Response response, ?bytesize: Integer) -> Transcoder::_Decoder
8
+ def self?.decode: (HTTPX::Response response, ?bytesize: Integer | Float) -> Inflater
9
9
 
10
- class Deflater < Transcoder::Deflater
10
+ class Error < ::HTTPX::Error
11
11
  end
12
12
 
13
- module RequestBodyClassMethods
14
- def initialize_deflater_body: (body_encoder body, Encoding | String encoding) -> body_encoder
13
+ class Deflater < Transcoder::Deflater
14
+ @compressor: ::Brotli::Compressor
15
15
  end
16
16
 
17
- module ResponseBodyClassMethods
18
- def initialize_inflater_by_encoding: (Encoding | String encoding, Response response, ?bytesize: Integer) -> (Transcoder::_Decoder | Transcoder::GZIP::Inflater)
17
+ class Inflater
18
+ @inflater: ::Brotli::Decompressor
19
+ @bytesize: Integer | Float
20
+
21
+ def initialize: (Integer | Float bytesize) -> void
22
+
23
+ def call: (String chunk) -> String
19
24
  end
20
25
  end
21
26
  end
@@ -31,6 +31,8 @@ module HTTPX
31
31
  def cookie_value: () -> String
32
32
  alias to_s cookie_value
33
33
 
34
+ def match?: (String | cookie_attributes name_or_options) -> bool
35
+
34
36
  def valid_for_uri?: (http_uri uri) -> bool
35
37
 
36
38
  def self.new: (Cookie) -> instance
@@ -41,8 +43,7 @@ module HTTPX
41
43
 
42
44
  private
43
45
 
44
- def initialize: (cookie_attributes) -> untyped
45
- | (_ToS, _ToS, ?cookie_attributes) -> untyped
46
+ def initialize: (_ToS name, _ToS value, ?cookie_attributes) -> void
46
47
 
47
48
  def acceptable_from_uri?: (uri) -> bool
48
49
 
@@ -6,11 +6,20 @@ module HTTPX
6
6
  include Enumerable[Cookie]
7
7
 
8
8
  @cookies: Array[Cookie]
9
+ @mtx: Thread::Mutex
9
10
 
10
11
  def parse: (String set_cookie) -> void
11
12
 
13
+ def get: (String | cookie_attributes name_or_options) -> Cookie?
14
+
15
+ def get_all: (String | cookie_attributes name_or_options) -> Array[Cookie]
16
+
17
+ def set: (_ToS | Cookie name, ?(cookie_attributes | _ToS) value_or_options) -> void
18
+
12
19
  def add: (Cookie name, ?String path) -> void
13
20
 
21
+ def delete: (String | Cookie | cookie_attributes name_or_options) -> void
22
+
14
23
  def []: (http_uri) -> Array[Cookie]
15
24
 
16
25
  def each: (?http_uri?) { (Cookie) -> void } -> void
@@ -21,6 +30,8 @@ module HTTPX
21
30
  private
22
31
 
23
32
  def initialize: (?_Each[cookie] cookies) -> untyped
33
+
34
+ def synchronize: [T] { () -> T } -> T
24
35
  end
25
36
  end
26
37
  end
@@ -15,6 +15,8 @@ module HTTPX
15
15
 
16
16
  module InstanceMethods
17
17
  def cookies: () -> Jar
18
+
19
+ def make_jar: (*untyped) -> Jar
18
20
  end
19
21
 
20
22
  module HeadersMethods
@@ -2,14 +2,29 @@ module HTTPX
2
2
  module Plugins
3
3
  module Expect
4
4
  EXPECT_TIMEOUT: Integer
5
+ NOEXPECT_STORE_MUTEX: Thread::Mutex
6
+
7
+ self.@no_expect_store: Store
8
+ def self.no_expect_store: () -> Store
9
+
10
+ def self.extra_options: (Options) -> (Options & _ExpectOptions)
11
+
12
+ class Store
13
+ @store: Array[String]
14
+ @mutex: Thread::Mutex
15
+
16
+ def include?: (String host) -> bool
17
+
18
+ def add: (String host) -> void
19
+
20
+ def delete: (String host) -> void
21
+ end
5
22
 
6
23
  interface _ExpectOptions
7
24
  def expect_timeout: () -> Integer?
8
25
 
9
26
  def expect_threshold_size: () -> Integer?
10
27
  end
11
-
12
- def self.extra_options: (Options) -> (Options & _ExpectOptions)
13
28
  end
14
29
  end
15
30
  end
@@ -5,6 +5,10 @@ module HTTPX
5
5
  module Plugins
6
6
  module Proxy
7
7
  module Socks4
8
+ VERSION: Integer
9
+ CONNECT: Integer
10
+ GRANTED: Integer
11
+ PROTOCOLS: Array[String]
8
12
 
9
13
  module ConnectionMethods
10
14
  def __socks4_proxy_connect: () -> void
@@ -5,11 +5,11 @@ module HTTPX
5
5
 
6
6
  def self.load_dependencies: (singleton(Session)) -> void
7
7
 
8
- def self.retry_after_rate_limit: (untyped, response) -> Numeric?
9
-
10
8
  module InstanceMethods
11
9
  def rate_limit_error?: (response response) -> bool
12
10
  end
13
11
  end
12
+
13
+ type sessionRateLimiter = Session & RateLimiter::InstanceMethods
14
14
  end
15
15
  end
@@ -51,7 +51,7 @@ module HTTPX
51
51
  module ResponseMethods
52
52
  attr_writer original_request: cacheRequest
53
53
 
54
- @cache: bool
54
+ @cached: bool
55
55
  @cache_control: Array[String]?
56
56
  @vary: Array[String]?
57
57
  @date: Time?
@@ -66,9 +66,9 @@ module HTTPX
66
66
 
67
67
  def fresh?: () -> bool
68
68
 
69
- def cache_control: () -> Array[String]?
69
+ %a{pure} def cache_control: () -> Array[String]?
70
70
 
71
- def vary: () -> Array[String]?
71
+ %a{pure} def vary: () -> Array[String]?
72
72
 
73
73
  private
74
74
 
@@ -8,16 +8,16 @@ module HTTPX
8
8
  DEFAULT_JITTER: ^(Numeric) -> Numeric
9
9
  BACKOFF_ALGORITHMS: Array[Symbol]
10
10
 
11
- def self?.retry_after_polynomial_backoff: (retriesRequest request, response response) -> Numeric
11
+ def self?.retry_after_polynomial_backoff: (retriesRequest request, retriesResponse response) -> Numeric
12
12
 
13
- def self?.retry_after_exponential_backoff: (retriesRequest request, response response) -> Numeric
13
+ def self?.retry_after_exponential_backoff: (retriesRequest request, retriesResponse response) -> Numeric
14
14
 
15
15
  interface _RetryCallback
16
- def call: (response response) -> bool?
16
+ def call: (retriesResponse response) -> bool?
17
17
  end
18
18
 
19
19
  interface _RetriesOptions
20
- def retry_after: () -> (^(retriesRequest request, response response) -> Numeric | Numeric)?
20
+ def retry_after: () -> (^(retriesRequest request, retriesResponse response) -> Numeric | Numeric)?
21
21
 
22
22
  def retry_jitter: () -> ^(Numeric jitter) -> Numeric
23
23
 
@@ -35,17 +35,19 @@ module HTTPX
35
35
 
36
36
  private
37
37
 
38
- def fetch_response: (retriesRequest request, Selector selector, retriesOptions options) -> (retriesResponse | ErrorResponse)?
38
+ def fetch_response: (retriesRequest request, Selector selector, retriesOptions options) -> retriesResponse?
39
39
 
40
- def retryable_request?: (retriesRequest request, response response, retriesOptions options) -> boolish
40
+ def retryable_request?: (retriesRequest request, retriesResponse response, retriesOptions options) -> boolish
41
41
 
42
- def retryable_response?: (response response, retriesOptions options) -> boolish
42
+ def retryable_response?: (retriesResponse response, retriesOptions options) -> boolish
43
43
 
44
44
  def retryable_error?: (_Exception error, Options options) -> boolish
45
45
 
46
- def try_partial_retry: (retriesRequest request, (retriesResponse | ErrorResponse) response) -> void
46
+ def try_partial_retry: (retriesRequest request, retriesResponse response) -> void
47
47
 
48
- def prepare_to_retry: (Request & RequestMethods request, response response) -> void
48
+ def prepare_to_retry: (Request & RequestMethods request, retriesResponse response) -> void
49
+
50
+ def when_to_retry: (Request & RequestMethods request, retriesResponse response, retriesOptions options) -> void
49
51
  end
50
52
 
51
53
  module RequestMethods
@@ -53,20 +55,22 @@ module HTTPX
53
55
 
54
56
  attr_accessor retries: Integer
55
57
 
56
- attr_writer partial_response: Response?
58
+ attr_writer partial_response: retriesResponse?
57
59
 
58
- def response=: (retriesResponse | ErrorResponse response) -> void
60
+ def response=: (retriesResponse response) -> void
59
61
  end
60
62
 
61
63
  module ResponseMethods
62
- def from_partial_response: (Response response) -> void
64
+ def from_partial_response: (retriesHTTPResponse response) -> void
63
65
  end
64
66
 
65
67
  type retriesOptions = Options & _RetriesOptions
66
68
 
67
69
  type retriesRequest = Request & RequestMethods
68
70
 
69
- type retriesResponse = Response & ResponseMethods
71
+ type retriesHTTPResponse = Response & ResponseMethods
72
+
73
+ type retriesResponse = retriesHTTPResponse | ErrorResponse
70
74
  end
71
75
 
72
76
  type sessionRetries = Session & Retries::InstanceMethods