httpx 1.4.0 → 1.4.2

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -2
  3. data/doc/release_notes/1_4_1.md +19 -0
  4. data/doc/release_notes/1_4_2.md +20 -0
  5. data/lib/httpx/adapters/datadog.rb +55 -83
  6. data/lib/httpx/adapters/faraday.rb +1 -1
  7. data/lib/httpx/adapters/webmock.rb +7 -1
  8. data/lib/httpx/callbacks.rb +2 -2
  9. data/lib/httpx/connection/http2.rb +2 -2
  10. data/lib/httpx/connection.rb +106 -51
  11. data/lib/httpx/errors.rb +3 -0
  12. data/lib/httpx/loggable.rb +8 -1
  13. data/lib/httpx/plugins/callbacks.rb +1 -0
  14. data/lib/httpx/plugins/circuit_breaker.rb +1 -0
  15. data/lib/httpx/plugins/expect.rb +1 -1
  16. data/lib/httpx/plugins/grpc/grpc_encoding.rb +2 -0
  17. data/lib/httpx/request/body.rb +9 -14
  18. data/lib/httpx/request.rb +20 -0
  19. data/lib/httpx/resolver/https.rb +4 -2
  20. data/lib/httpx/resolver/native.rb +111 -55
  21. data/lib/httpx/resolver/resolver.rb +18 -11
  22. data/lib/httpx/resolver/system.rb +3 -5
  23. data/lib/httpx/selector.rb +33 -23
  24. data/lib/httpx/session.rb +17 -43
  25. data/lib/httpx/timers.rb +16 -1
  26. data/lib/httpx/transcoder/body.rb +15 -31
  27. data/lib/httpx/transcoder/multipart/part.rb +1 -1
  28. data/lib/httpx/version.rb +1 -1
  29. data/lib/httpx.rb +1 -1
  30. data/sig/callbacks.rbs +2 -2
  31. data/sig/connection.rbs +19 -5
  32. data/sig/errors.rbs +3 -0
  33. data/sig/request/body.rbs +0 -8
  34. data/sig/request.rbs +3 -0
  35. data/sig/resolver/native.rbs +6 -1
  36. data/sig/selector.rbs +1 -0
  37. data/sig/session.rbs +2 -0
  38. data/sig/timers.rbs +15 -4
  39. data/sig/transcoder/body.rbs +1 -3
  40. data/sig/transcoder/utils/body_reader.rbs +1 -1
  41. data/sig/transcoder/utils/deflater.rbs +1 -1
  42. metadata +7 -3
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "forwardable"
3
+ require "delegate"
4
4
 
5
5
  module HTTPX::Transcoder
6
6
  module Body
@@ -8,48 +8,32 @@ module HTTPX::Transcoder
8
8
 
9
9
  module_function
10
10
 
11
- class Encoder
12
- extend Forwardable
13
-
14
- def_delegator :@raw, :to_s
15
-
16
- def_delegator :@raw, :==
17
-
11
+ class Encoder < SimpleDelegator
18
12
  def initialize(body)
19
- @raw = body
13
+ body = body.open(File::RDONLY, encoding: Encoding::BINARY) if Object.const_defined?(:Pathname) && body.is_a?(Pathname)
14
+ @body = body
15
+ super(body)
20
16
  end
21
17
 
22
18
  def bytesize
23
- if @raw.respond_to?(:bytesize)
24
- @raw.bytesize
25
- elsif @raw.respond_to?(:to_ary)
26
- @raw.sum(&:bytesize)
27
- elsif @raw.respond_to?(:size)
28
- @raw.size || Float::INFINITY
29
- elsif @raw.respond_to?(:length)
30
- @raw.length || Float::INFINITY
31
- elsif @raw.respond_to?(:each)
19
+ if @body.respond_to?(:bytesize)
20
+ @body.bytesize
21
+ elsif @body.respond_to?(:to_ary)
22
+ @body.sum(&:bytesize)
23
+ elsif @body.respond_to?(:size)
24
+ @body.size || Float::INFINITY
25
+ elsif @body.respond_to?(:length)
26
+ @body.length || Float::INFINITY
27
+ elsif @body.respond_to?(:each)
32
28
  Float::INFINITY
33
29
  else
34
- raise Error, "cannot determine size of body: #{@raw.inspect}"
30
+ raise Error, "cannot determine size of body: #{@body.inspect}"
35
31
  end
36
32
  end
37
33
 
38
34
  def content_type
39
35
  "application/octet-stream"
40
36
  end
41
-
42
- private
43
-
44
- def respond_to_missing?(meth, *args)
45
- @raw.respond_to?(meth, *args) || super
46
- end
47
-
48
- def method_missing(meth, *args, &block)
49
- return super unless @raw.respond_to?(meth)
50
-
51
- @raw.__send__(meth, *args, &block)
52
- end
53
37
  end
54
38
 
55
39
  def encode(body)
@@ -19,7 +19,7 @@ module HTTPX
19
19
  value = value[:body]
20
20
  end
21
21
 
22
- value = value.open(File::RDONLY) if Object.const_defined?(:Pathname) && value.is_a?(Pathname)
22
+ value = value.open(File::RDONLY, encoding: Encoding::BINARY) if Object.const_defined?(:Pathname) && value.is_a?(Pathname)
23
23
 
24
24
  if value.respond_to?(:path) && value.respond_to?(:read)
25
25
  # either a File, a Tempfile, or something else which has to quack like a file
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.4.0"
4
+ VERSION = "1.4.2"
5
5
  end
data/lib/httpx.rb CHANGED
@@ -61,6 +61,6 @@ require "httpx/session_extensions"
61
61
 
62
62
  # load integrations when possible
63
63
 
64
- require "httpx/adapters/datadog" if defined?(DDTrace) || defined?(Datadog)
64
+ require "httpx/adapters/datadog" if defined?(DDTrace) || defined?(Datadog::Tracing)
65
65
  require "httpx/adapters/sentry" if defined?(Sentry)
66
66
  require "httpx/adapters/webmock" if defined?(WebMock)
data/sig/callbacks.rbs CHANGED
@@ -4,8 +4,8 @@ module HTTPX
4
4
  end
5
5
 
6
6
  module Callbacks
7
- def on: (Symbol) { (*untyped) -> void } -> self
8
- def once: (Symbol) { (*untyped) -> void } -> self
7
+ def on: (Symbol) { (*untyped) -> void } -> ^(*untyped) -> void
8
+ def once: (Symbol) { (*untyped) -> void } -> ^(*untyped) -> void
9
9
  def emit: (Symbol, *untyped) -> void
10
10
 
11
11
  def callbacks_for?: (Symbol) -> bool
data/sig/connection.rbs CHANGED
@@ -26,11 +26,12 @@ module HTTPX
26
26
  attr_reader pending: Array[Request]
27
27
  attr_reader options: Options
28
28
  attr_reader ssl_session: OpenSSL::SSL::Session?
29
+ attr_reader sibling: instance?
29
30
  attr_writer current_selector: Selector?
30
- attr_writer coalesced_connection: instance?
31
31
  attr_accessor current_session: Session?
32
32
  attr_accessor family: Integer?
33
33
 
34
+
34
35
  @window_size: Integer
35
36
  @read_buffer: Buffer
36
37
  @write_buffer: Buffer
@@ -42,9 +43,12 @@ module HTTPX
42
43
  @parser: Object & _Parser
43
44
  @connected_at: Float
44
45
  @response_received_at: Float
45
- @intervals: Array[Timers::Interval]
46
46
  @exhausted: bool
47
47
  @cloned: bool
48
+ @coalesced_connection: instance?
49
+ @sibling: instance?
50
+ @main_sibling: bool
51
+
48
52
 
49
53
  def addresses: () -> Array[ipaddr]?
50
54
 
@@ -70,6 +74,8 @@ module HTTPX
70
74
 
71
75
  def connecting?: () -> bool
72
76
 
77
+ def io_connected?: () -> bool
78
+
73
79
  def inflight?: () -> boolish
74
80
 
75
81
  def interests: () -> io_interests?
@@ -98,6 +104,14 @@ module HTTPX
98
104
 
99
105
  def handle_socket_timeout: (Numeric interval) -> void
100
106
 
107
+ def coalesced_connection=: (instance connection) -> void
108
+
109
+ def sibling=: (instance? connection) -> void
110
+
111
+ def handle_connect_error: (StandardError error) -> void
112
+
113
+ def disconnect: () -> void
114
+
101
115
  private
102
116
 
103
117
  def initialize: (http_uri uri, Options options) -> void
@@ -106,8 +120,6 @@ module HTTPX
106
120
 
107
121
  def connect: () -> void
108
122
 
109
- def disconnect: () -> void
110
-
111
123
  def exhausted?: () -> boolish
112
124
 
113
125
  def consume: () -> void
@@ -134,6 +146,8 @@ module HTTPX
134
146
 
135
147
  def handle_error: (StandardError error, ?Request? request) -> void
136
148
 
149
+ def close_sibling: () -> void
150
+
137
151
  def purge_after_closed: () -> void
138
152
 
139
153
  def set_request_timeouts: (Request request) -> void
@@ -148,7 +162,7 @@ module HTTPX
148
162
 
149
163
  def read_timeout_callback: (Request request, Numeric read_timeout, ?singleton(RequestTimeoutError) error_type) -> void
150
164
 
151
- def set_request_timeout: (Request request, Numeric timeout, Symbol start_event, Symbol | Array[Symbol] finish_events) { () -> void } -> void
165
+ def set_request_timeout: (Symbol label, Request request, Numeric timeout, Symbol start_event, Symbol | Array[Symbol] finish_events) { () -> void } -> void
152
166
 
153
167
  def self.parser_type: (String protocol) -> (singleton(HTTP1) | singleton(HTTP2))
154
168
  end
data/sig/errors.rbs CHANGED
@@ -45,6 +45,9 @@ module HTTPX
45
45
  class WriteTimeoutError < RequestTimeoutError
46
46
  end
47
47
 
48
+ class OperationTimeoutError < TimeoutError
49
+ end
50
+
48
51
  class ResolveError < Error
49
52
  end
50
53
 
data/sig/request/body.rbs CHANGED
@@ -31,12 +31,4 @@ module HTTPX
31
31
 
32
32
  def self.initialize_deflater_body: (body_encoder body, Encoding | String encoding) -> body_encoder
33
33
  end
34
-
35
- class ProcIO
36
- @block: ^(String) -> void
37
-
38
- def initialize: (^(String) -> void) -> untyped
39
-
40
- def write: (String data) -> Integer
41
- end
42
34
  end
data/sig/request.rbs CHANGED
@@ -14,6 +14,7 @@ module HTTPX
14
14
  attr_reader options: Options
15
15
  attr_reader response: response?
16
16
  attr_reader drain_error: StandardError?
17
+ attr_reader active_timeouts: Array[Symbol]
17
18
 
18
19
  attr_accessor peer_address: ipaddr?
19
20
 
@@ -63,6 +64,8 @@ module HTTPX
63
64
 
64
65
  def request_timeout: () -> Numeric?
65
66
 
67
+ def set_timeout_callback: (Symbol event) { (*untyped) -> void } -> void
68
+
66
69
  private
67
70
 
68
71
  def initialize_body: (Options options) -> Transcoder::_Encoder?
@@ -21,6 +21,7 @@ module HTTPX
21
21
  @write_buffer: Buffer
22
22
  @large_packet: Buffer?
23
23
  @io: UDP | TCP
24
+ @name: String?
24
25
 
25
26
  attr_reader state: Symbol
26
27
 
@@ -42,7 +43,9 @@ module HTTPX
42
43
 
43
44
  def consume: () -> void
44
45
 
45
- def do_retry: (?Numeric? loop_time) -> void
46
+ def schedule_retry: () -> void
47
+
48
+ def do_retry: (String host, Connection connection, Numeric interval) -> void
46
49
 
47
50
  def dread: (Integer) -> void
48
51
  | () -> void
@@ -64,6 +67,8 @@ module HTTPX
64
67
  def handle_error: (NativeResolveError | StandardError) -> void
65
68
 
66
69
  def reset_hostname: (String hostname, ?connection: Connection, ?reset_candidates: bool) -> void
70
+
71
+ def close_or_resolve: () -> void
67
72
  end
68
73
  end
69
74
  end
data/sig/selector.rbs CHANGED
@@ -10,6 +10,7 @@ module HTTPX
10
10
  @timers: Timers
11
11
 
12
12
  @selectables: Array[selectable]
13
+ @is_timer_interval: bool
13
14
 
14
15
  def next_tick: () -> void
15
16
 
data/sig/session.rbs CHANGED
@@ -25,6 +25,8 @@ module HTTPX
25
25
 
26
26
  def select_connection: (Connection connection, Selector selector) -> void
27
27
 
28
+ def pin_connection: (Resolver::Resolver | Connection connection, Selector selector) -> void
29
+
28
30
  def deselect_connection: (Connection connection, Selector selector, ?bool cloned) -> void
29
31
 
30
32
  def select_resolver: (Resolver::Native | Resolver::HTTPS resolver, Selector selector) -> void
data/sig/timers.rbs CHANGED
@@ -1,10 +1,12 @@
1
1
  module HTTPX
2
2
  class Timers
3
+ type callback = ^() -> void
4
+
3
5
  @intervals: Array[Interval]
4
6
  @next_interval_at: Float
5
7
 
6
- def after: (Numeric interval_in_secs, ^() -> void) -> Interval
7
- | (Numeric interval_in_secs) { () -> void } -> Interval
8
+ def after: (Numeric interval_in_secs, ^() -> void) -> Timer
9
+ | (Numeric interval_in_secs) { () -> void } -> Timer
8
10
 
9
11
  def wait_interval: () -> Numeric?
10
12
 
@@ -15,8 +17,6 @@ module HTTPX
15
17
  class Interval
16
18
  include Comparable
17
19
 
18
- type callback = ^() -> void
19
-
20
20
  attr_reader interval: Numeric
21
21
 
22
22
  @callbacks: Array[callback]
@@ -25,6 +25,8 @@ module HTTPX
25
25
 
26
26
  def on_empty: () { () -> void } -> void
27
27
 
28
+ def cancel: () -> void
29
+
28
30
  def to_f: () -> Float
29
31
 
30
32
  def <<: (callback) -> void
@@ -41,5 +43,14 @@ module HTTPX
41
43
 
42
44
  def initialize: (Numeric interval) -> void
43
45
  end
46
+
47
+ class Timer
48
+ @interval: Interval
49
+ @callback: callback
50
+
51
+ def initialize: (Interval interval, callback callback) -> void
52
+
53
+ def cancel: () -> void
54
+ end
44
55
  end
45
56
  end
@@ -4,9 +4,7 @@ module HTTPX
4
4
  class Error < HTTPX::Error
5
5
  end
6
6
 
7
- class Encoder
8
- extend Forwardable
9
-
7
+ class Encoder # < SimpleDelegator
10
8
  @raw: Object & bodyIO
11
9
 
12
10
  def bytesize: () -> (Integer | Float)
@@ -7,7 +7,7 @@ module HTTPX
7
7
 
8
8
  def bytesize: () -> (Integer | Float)
9
9
 
10
- def read: (?int? length, ?string outbuf) -> String?
10
+ def read: (?int? length, ?string? outbuf) -> String?
11
11
 
12
12
  def close: () -> void
13
13
  end
@@ -14,7 +14,7 @@ module HTTPX
14
14
 
15
15
  def bytesize: () -> (Integer | Float)
16
16
 
17
- def read: (?int? length, ?string outbuf) -> String?
17
+ def read: (?int? length, ?string? outbuf) -> String?
18
18
 
19
19
  def close: () -> void
20
20
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-18 00:00:00.000000000 Z
11
+ date: 2025-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2
@@ -150,6 +150,8 @@ extra_rdoc_files:
150
150
  - doc/release_notes/1_3_3.md
151
151
  - doc/release_notes/1_3_4.md
152
152
  - doc/release_notes/1_4_0.md
153
+ - doc/release_notes/1_4_1.md
154
+ - doc/release_notes/1_4_2.md
153
155
  files:
154
156
  - LICENSE.txt
155
157
  - README.md
@@ -271,6 +273,8 @@ files:
271
273
  - doc/release_notes/1_3_3.md
272
274
  - doc/release_notes/1_3_4.md
273
275
  - doc/release_notes/1_4_0.md
276
+ - doc/release_notes/1_4_1.md
277
+ - doc/release_notes/1_4_2.md
274
278
  - lib/httpx.rb
275
279
  - lib/httpx/adapters/datadog.rb
276
280
  - lib/httpx/adapters/faraday.rb
@@ -491,7 +495,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
491
495
  - !ruby/object:Gem::Version
492
496
  version: '0'
493
497
  requirements: []
494
- rubygems_version: 3.5.3
498
+ rubygems_version: 3.5.22
495
499
  signing_key:
496
500
  specification_version: 4
497
501
  summary: HTTPX, to the future, and beyond