httpx 1.7.4 → 1.7.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 125df778093197c9a1fe8872211cf4085a5a885a40536b58501ce1938f8d28ee
4
- data.tar.gz: 5a17b5b02212f65ba3472f4dfda96a017fc1ef9a4fb7a3dce85d7b4ac6a8c6bb
3
+ metadata.gz: 7e9530bb05303e7e15a05a84a26650fc2dd0ec0c35c11c909b07d8deb499f00f
4
+ data.tar.gz: 29043b781e3f12cf18ca80eeb6979833536b659dd13ce76d5312fe20f3b61342
5
5
  SHA512:
6
- metadata.gz: b6a4014db970d25a1ac51ea73ac5bd828bf8c0f1012ec778abdf054d9dd6dcfe6cf7fc5f73f915a39d74e4e420329e1293e020d63955601e6f669ae6164a016b
7
- data.tar.gz: 96b98469fe6194bbd3427adfd1bfc6032be9c44f2c68ff301a6da20a90741b1979aa194c113a11e1b82cb9a54c3559ef7c35b908d41c10297746e438b557eca3
6
+ metadata.gz: dea67bc736ed82b32c6c81257d66ca2dac2fae2cf41cb923fdca28c4c9741e5f57b0b56b3bfa23f6b0990f6faf26d14258b296ef771681d405564e02fafaceb5
7
+ data.tar.gz: 13dda593ac028e1d34b6ca0e22dd6a024705bf542da756a013f5da7f0abcccaab76860e80e5d8586ff95d4fe258542a295c004d33866a7986407c6cd4950f9e9
@@ -0,0 +1,10 @@
1
+ # 1.7.5
2
+
3
+ ## Improvements
4
+
5
+ * `:tracing` plugin: make `Request#init_time` a UTC timestamp.
6
+
7
+ ## Bugfixes
8
+
9
+ * fixed handling of conditional responses which was making a batch of concurrent requests being handled serially after they failed.
10
+ * `datadog` adapter: use `Request#init_time` as the span start time, which will fix the bug where the span wasn't including the time it takes to open the connection (TCP/TLS handhshakes).
@@ -51,7 +51,7 @@ module Datadog::Tracing
51
51
  end
52
52
 
53
53
  def start(request)
54
- request.datadog_span = initialize_span(request, now)
54
+ request.datadog_span = initialize_span(request, request.init_time)
55
55
  end
56
56
 
57
57
  def reset(request)
@@ -132,10 +132,6 @@ module Datadog::Tracing
132
132
  Datadog.logger.error(e.backtrace)
133
133
  end
134
134
 
135
- def now
136
- ::Datadog::Core::Utils::Time.now.utc
137
- end
138
-
139
135
  def configuration(request)
140
136
  Datadog.configuration.tracing[:httpx, request.uri.host]
141
137
  end
@@ -70,6 +70,9 @@ module HTTPX
70
70
  module RequestMethods
71
71
  def initialize(*)
72
72
  super
73
+
74
+ @informational_status = nil
75
+
73
76
  return if @body.empty?
74
77
 
75
78
  threshold = @options.expect_threshold_size
@@ -89,7 +89,7 @@ module HTTPX::Plugins
89
89
  on(:headers) do
90
90
  # the usual request init time (when not including the connection handshake)
91
91
  # should be the time the request is buffered the first time.
92
- @init_time ||= ::Time.now
92
+ @init_time ||= ::Time.now.utc
93
93
 
94
94
  tracer.start(self)
95
95
  end
@@ -102,7 +102,7 @@ module HTTPX::Plugins
102
102
  # Example is the :ssrf_filter plugin, which raises an error on
103
103
  # initialize if the host is an IP which matches against the known set.
104
104
  # in such cases, we'll just set here right here.
105
- @init_time ||= ::Time.now
105
+ @init_time ||= ::Time.now.utc
106
106
 
107
107
  super
108
108
  end
@@ -113,7 +113,7 @@ module HTTPX::Plugins
113
113
  def initialize(*)
114
114
  super
115
115
 
116
- @init_time = ::Time.now
116
+ @init_time = ::Time.now.utc
117
117
  end
118
118
 
119
119
  def send(request)
@@ -129,7 +129,7 @@ module HTTPX::Plugins
129
129
 
130
130
  # time of initial request(s) is accounted from the moment
131
131
  # the connection is back to :idle, and ready to connect again.
132
- @init_time = ::Time.now
132
+ @init_time = ::Time.now.utc
133
133
  end
134
134
  end
135
135
  end
@@ -29,7 +29,7 @@ module HTTPX
29
29
 
30
30
  def_delegator :@timers, :after
31
31
 
32
- def_delegator :@selectables, :empty?
32
+ def_delegator :@selectables, :each
33
33
 
34
34
  def initialize
35
35
  @timers = Timers.new
@@ -37,8 +37,8 @@ module HTTPX
37
37
  @is_timer_interval = false
38
38
  end
39
39
 
40
- def each(&blk)
41
- @selectables.each(&blk)
40
+ def empty?
41
+ @selectables.empty? && @timers.empty?
42
42
  end
43
43
 
44
44
  def next_tick
data/lib/httpx/session.rb CHANGED
@@ -325,53 +325,34 @@ module HTTPX
325
325
 
326
326
  # returns the array of HTTPX::Response objects corresponding to the array of HTTPX::Request +requests+.
327
327
  def receive_requests(requests, selector)
328
- responses = [] # : Array[response]
329
-
330
- # guarantee ordered responses
331
- loop do
332
- request = requests.first
333
-
334
- return responses unless request
335
-
336
- catch(:coalesced) { selector.next_tick } until (response = fetch_response(request, selector, request.options))
337
- request.complete!(response)
338
-
339
- responses << response
340
- requests.shift
341
-
342
- break if requests.empty?
328
+ waiting = 0
329
+ responses = requests.map do |request|
330
+ fetch_response(request, selector, request.options).tap do |response|
331
+ waiting += 1 if response.nil?
332
+ end
333
+ end
343
334
 
344
- next unless selector.empty?
335
+ until waiting.zero? || selector.empty?
336
+ # loop on selector until at least one response has been received.
337
+ catch(:coalesced) { selector.next_tick }
345
338
 
346
- # in some cases, the pool of connections might have been drained because there was some
347
- # handshake error, and the error responses have already been emitted, but there was no
348
- # opportunity to traverse the requests, hence we're returning only a fraction of the errors
349
- # we were supposed to. This effectively fetches the existing responses and return them.
350
- exit_from_loop = true
339
+ responses.each_with_index do |response, idx|
340
+ next unless response.nil?
351
341
 
352
- requests_to_remove = [] # : Array[Request]
342
+ request = requests[idx]
353
343
 
354
- requests.each do |req|
355
- response = fetch_response(req, selector, request.options)
344
+ response = fetch_response(request, selector, request.options)
356
345
 
357
- if exit_from_loop && response
358
- req.complete!(response)
359
- responses << response
360
- requests_to_remove << req
361
- else
362
- # fetch_response may resend requests. when that happens, we need to go back to the initial
363
- # loop and process the selector. we still do a pass-through on the remainder of requests, so
364
- # that every request that need to be resent, is resent.
365
- exit_from_loop = false
346
+ next unless response
366
347
 
367
- raise Error, "something went wrong, responses not found and requests not resent" if selector.empty?
368
- end
348
+ request.complete!(response)
349
+ responses[idx] = response
350
+ waiting -= 1
369
351
  end
352
+ end
370
353
 
371
- break if exit_from_loop
354
+ raise Error, "something went wrong, responses not found and requests not resent" unless waiting.zero?
372
355
 
373
- requests -= requests_to_remove
374
- end
375
356
  responses
376
357
  end
377
358
 
data/lib/httpx/timers.rb CHANGED
@@ -6,6 +6,10 @@ module HTTPX
6
6
  @intervals = []
7
7
  end
8
8
 
9
+ def empty?
10
+ @intervals.empty?
11
+ end
12
+
9
13
  def after(interval_in_secs, cb = nil, &blk)
10
14
  callback = cb || blk
11
15
 
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.4"
4
+ VERSION = "1.7.5"
5
5
  end
@@ -20,6 +20,10 @@ module HTTPX
20
20
  def delete: (String host) -> void
21
21
  end
22
22
 
23
+ module RequestMethods
24
+ @informational_status: Integer?
25
+ end
26
+
23
27
  interface _ExpectOptions
24
28
  def expect_timeout: () -> Integer?
25
29
 
@@ -9,12 +9,12 @@ module HTTPX
9
9
 
10
10
  def set_context!: () -> void
11
11
 
12
- def current_context?: () -> bool
12
+ def current_context?: () -> boolish
13
13
  end
14
14
 
15
15
  module ConnectionMethods
16
16
 
17
- def current_context?: () -> bool
17
+ def current_context?: () -> boolish
18
18
 
19
19
  def send: (request request) -> void
20
20
  end
data/sig/selector.rbs CHANGED
@@ -24,8 +24,6 @@ module HTTPX
24
24
 
25
25
  type io_select_selectable = (selectable | Array[selectable])?
26
26
 
27
- include _Each[selectable]
28
-
29
27
  extend Forwardable
30
28
 
31
29
  READABLE: Array[io_interests]
@@ -36,6 +34,9 @@ module HTTPX
36
34
  @selectables: Array[selectable]
37
35
  @is_timer_interval: bool
38
36
 
37
+ def each: () -> ::Enumerator[selectable, self]
38
+ | () { (selectable) -> void } -> self
39
+
39
40
  def next_tick: () -> void
40
41
 
41
42
  def terminate: () -> void
data/sig/timers.rbs CHANGED
@@ -14,6 +14,8 @@ module HTTPX
14
14
 
15
15
  def initialize: () -> void
16
16
 
17
+ def empty?: () -> bool
18
+
17
19
  private
18
20
 
19
21
  def drop_elapsed!: (Numeric elapsed_time) -> void
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.4
4
+ version: 1.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
@@ -164,6 +164,7 @@ extra_rdoc_files:
164
164
  - doc/release_notes/1_7_2.md
165
165
  - doc/release_notes/1_7_3.md
166
166
  - doc/release_notes/1_7_4.md
167
+ - doc/release_notes/1_7_5.md
167
168
  files:
168
169
  - LICENSE.txt
169
170
  - README.md
@@ -300,6 +301,7 @@ files:
300
301
  - doc/release_notes/1_7_2.md
301
302
  - doc/release_notes/1_7_3.md
302
303
  - doc/release_notes/1_7_4.md
304
+ - doc/release_notes/1_7_5.md
303
305
  - lib/httpx.rb
304
306
  - lib/httpx/adapters/datadog.rb
305
307
  - lib/httpx/adapters/faraday.rb