httpx 0.13.1 → 0.14.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes/0_10_1.md +1 -1
  3. data/doc/release_notes/0_13_0.md +2 -2
  4. data/doc/release_notes/0_13_1.md +1 -1
  5. data/doc/release_notes/0_13_2.md +9 -0
  6. data/doc/release_notes/0_14_0.md +79 -0
  7. data/doc/release_notes/0_14_1.md +7 -0
  8. data/doc/release_notes/0_14_2.md +6 -0
  9. data/doc/release_notes/0_14_3.md +5 -0
  10. data/lib/httpx.rb +1 -2
  11. data/lib/httpx/callbacks.rb +12 -3
  12. data/lib/httpx/connection.rb +12 -9
  13. data/lib/httpx/connection/http1.rb +38 -15
  14. data/lib/httpx/connection/http2.rb +61 -15
  15. data/lib/httpx/headers.rb +7 -3
  16. data/lib/httpx/io/tcp.rb +1 -1
  17. data/lib/httpx/io/udp.rb +31 -7
  18. data/lib/httpx/options.rb +91 -56
  19. data/lib/httpx/plugins/aws_sdk_authentication.rb +5 -2
  20. data/lib/httpx/plugins/aws_sigv4.rb +5 -4
  21. data/lib/httpx/plugins/basic_authentication.rb +8 -3
  22. data/lib/httpx/plugins/compression.rb +8 -8
  23. data/lib/httpx/plugins/compression/brotli.rb +4 -3
  24. data/lib/httpx/plugins/compression/deflate.rb +4 -3
  25. data/lib/httpx/plugins/compression/gzip.rb +2 -1
  26. data/lib/httpx/plugins/cookies.rb +3 -7
  27. data/lib/httpx/plugins/digest_authentication.rb +4 -4
  28. data/lib/httpx/plugins/expect.rb +6 -6
  29. data/lib/httpx/plugins/follow_redirects.rb +3 -3
  30. data/lib/httpx/plugins/grpc.rb +247 -0
  31. data/lib/httpx/plugins/grpc/call.rb +62 -0
  32. data/lib/httpx/plugins/grpc/message.rb +85 -0
  33. data/lib/httpx/plugins/multipart/part.rb +2 -2
  34. data/lib/httpx/plugins/proxy.rb +3 -7
  35. data/lib/httpx/plugins/proxy/http.rb +5 -4
  36. data/lib/httpx/plugins/proxy/ssh.rb +3 -3
  37. data/lib/httpx/plugins/rate_limiter.rb +1 -1
  38. data/lib/httpx/plugins/retries.rb +13 -14
  39. data/lib/httpx/plugins/stream.rb +96 -74
  40. data/lib/httpx/plugins/upgrade.rb +6 -5
  41. data/lib/httpx/request.rb +25 -2
  42. data/lib/httpx/resolver/native.rb +7 -3
  43. data/lib/httpx/response.rb +4 -0
  44. data/lib/httpx/session.rb +17 -7
  45. data/lib/httpx/transcoder/chunker.rb +1 -1
  46. data/lib/httpx/version.rb +1 -1
  47. data/sig/callbacks.rbs +2 -0
  48. data/sig/connection/http1.rbs +5 -1
  49. data/sig/connection/http2.rbs +6 -2
  50. data/sig/headers.rbs +2 -2
  51. data/sig/options.rbs +9 -2
  52. data/sig/plugins/aws_sdk_authentication.rbs +2 -0
  53. data/sig/plugins/basic_authentication.rbs +2 -0
  54. data/sig/plugins/compression.rbs +2 -2
  55. data/sig/plugins/multipart.rbs +1 -1
  56. data/sig/plugins/stream.rbs +17 -16
  57. data/sig/request.rbs +7 -2
  58. data/sig/response.rbs +1 -0
  59. data/sig/session.rbs +4 -0
  60. metadata +18 -7
  61. data/lib/httpx/timeout.rb +0 -67
  62. data/sig/timeout.rbs +0 -29
data/lib/httpx/session.rb CHANGED
@@ -77,7 +77,7 @@ module HTTPX
77
77
  end
78
78
 
79
79
  def set_connection_callbacks(connection, connections, options)
80
- connection.on(:misdirected) do |misdirected_request|
80
+ connection.only(:misdirected) do |misdirected_request|
81
81
  other_connection = connection.create_idle(ssl: { alpn_protocols: %w[http/1.1] })
82
82
  other_connection.merge(connection)
83
83
  catch(:coalesced) do
@@ -88,11 +88,11 @@ module HTTPX
88
88
  misdirected_request.transition(:idle)
89
89
  other_connection.send(misdirected_request)
90
90
  end
91
- connection.on(:altsvc) do |alt_origin, origin, alt_params|
91
+ connection.only(:altsvc) do |alt_origin, origin, alt_params|
92
92
  other_connection = build_altsvc_connection(connection, connections, alt_origin, origin, alt_params, options)
93
93
  connections << other_connection if other_connection
94
94
  end
95
- connection.on(:exhausted) do
95
+ connection.only(:exhausted) do
96
96
  other_connection = connection.create_idle
97
97
  other_connection.merge(connection)
98
98
  catch(:coalesced) do
@@ -175,12 +175,18 @@ module HTTPX
175
175
  end
176
176
 
177
177
  def send_requests(*requests, options)
178
- connections = []
179
178
  request_options = @options.merge(options)
180
179
 
180
+ connections = _send_requests(requests, request_options)
181
+ receive_requests(requests, connections, request_options)
182
+ end
183
+
184
+ def _send_requests(requests, options)
185
+ connections = []
186
+
181
187
  requests.each do |request|
182
188
  error = catch(:resolve_error) do
183
- connection = find_connection(request, connections, request_options)
189
+ connection = find_connection(request, connections, options)
184
190
  connection.send(request)
185
191
  end
186
192
  next unless error.is_a?(ResolveError)
@@ -188,13 +194,17 @@ module HTTPX
188
194
  request.emit(:response, ErrorResponse.new(request, error, options))
189
195
  end
190
196
 
197
+ connections
198
+ end
199
+
200
+ def receive_requests(requests, connections, options)
191
201
  responses = []
192
202
 
193
203
  begin
194
204
  # guarantee ordered responses
195
205
  loop do
196
206
  request = requests.first
197
- pool.next_tick until (response = fetch_response(request, connections, request_options))
207
+ pool.next_tick until (response = fetch_response(request, connections, options))
198
208
 
199
209
  responses << response
200
210
  requests.shift
@@ -208,7 +218,7 @@ module HTTPX
208
218
  # opportunity to traverse the requests, hence we're returning only a fraction of the errors
209
219
  # we were supposed to. This effectively fetches the existing responses and return them.
210
220
  while (request = requests.shift)
211
- responses << fetch_response(request, connections, request_options)
221
+ responses << fetch_response(request, connections, options)
212
222
  end
213
223
  break
214
224
  end
@@ -20,7 +20,7 @@ module HTTPX::Transcoder
20
20
  @raw.each do |chunk|
21
21
  yield "#{chunk.bytesize.to_s(16)}#{CRLF}#{chunk}#{CRLF}"
22
22
  end
23
- yield "0#{CRLF}#{CRLF}"
23
+ yield "0#{CRLF}"
24
24
  end
25
25
 
26
26
  def respond_to_missing?(meth, *args)
data/lib/httpx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPX
4
- VERSION = "0.13.1"
4
+ VERSION = "0.14.3"
5
5
  end
data/sig/callbacks.rbs CHANGED
@@ -6,8 +6,10 @@ module HTTPX
6
6
  module Callbacks
7
7
  def on: (Symbol) { (*untyped) -> void } -> void
8
8
  def once: (Symbol) { (*untyped) -> void } -> void
9
+ def only: (Symbol) { (*untyped) -> void } -> void
9
10
  def emit: (Symbol, *untyped) -> void
10
11
 
12
+ def callbacks_for?: (Symbol) -> bool
11
13
  def callbacks: () -> Hash[Symbol, Array[_Callable]]
12
14
  | (Symbol) -> Array[_Callable]
13
15
  end
@@ -52,7 +52,7 @@ module HTTPX
52
52
 
53
53
  def disable_pipelining: () -> void
54
54
 
55
- def set_protocol_headers: (Request) -> void
55
+ def set_protocol_headers: (Request) -> _Each[headers_key, String]
56
56
 
57
57
  def headline_uri: (Request) -> String
58
58
 
@@ -60,6 +60,10 @@ module HTTPX
60
60
 
61
61
  def join_headers: (Request request) -> void
62
62
 
63
+ def join_trailers: (Request request) -> void
64
+
65
+ def join_headers2: (_Each[headers_key, String] headers) -> void
66
+
63
67
  def join_body: (Request request) -> void
64
68
 
65
69
  def capitalized: (String field) -> String
@@ -43,7 +43,7 @@ module HTTPX
43
43
 
44
44
  def headline_uri: (Request) -> String
45
45
 
46
- def set_protocol_headers: (Request) -> void
46
+ def set_protocol_headers: (Request) -> _Each[headers_key, String]
47
47
 
48
48
  def handle: (Request request, HTTP2Next::Stream stream) -> void
49
49
 
@@ -53,13 +53,17 @@ module HTTPX
53
53
 
54
54
  def join_headers: (HTTP2Next::Stream stream, Request request) -> void
55
55
 
56
+ def join_trailers: (HTTP2Next::Stream stream, Request request) -> void
57
+
56
58
  def join_body: (HTTP2Next::Stream stream, Request request) -> void
57
59
 
58
60
  def on_stream_headers: (HTTP2Next::Stream stream, Request request, Array[[String, String]] headers) -> void
59
61
 
62
+ def on_stream_trailers: (HTTP2Next::Stream stream, Request request, Array[[String, String]] headers) -> void
63
+
60
64
  def on_stream_data: (HTTP2Next::Stream stream, Request request, string data) -> void
61
65
 
62
- def on_stream_close: (HTTP2Next::Stream stream, Request request, Symbol? error) -> void
66
+ def on_stream_close: (HTTP2Next::Stream stream, Request request, (Symbol | StandardError)? error) -> void
63
67
 
64
68
  def on_frame: (string bytes) -> void
65
69
 
data/sig/headers.rbs CHANGED
@@ -14,8 +14,8 @@ module HTTPX
14
14
  def add: (headers_key field, string value) -> void
15
15
  def delete: (headers_key field) -> void
16
16
 
17
- def each: () { (headers_key, String) -> void } -> void
18
- | () -> Enumerable[[headers_key, String], void]
17
+ def each: (?_Each[headers_key, String]? extra_headers) { (headers_key, String) -> void } -> void
18
+ | (?_Each[headers_key, String]? extra_headers) -> Enumerable[[headers_key, String], void]
19
19
 
20
20
  def get: (headers_key field) -> Array[String]
21
21
  def key?: (headers_key downcased_key) -> bool
data/sig/options.rbs CHANGED
@@ -5,16 +5,23 @@ module HTTPX
5
5
  WINDOW_SIZE: Integer
6
6
  MAX_BODY_THRESHOLD_SIZE: Integer
7
7
 
8
+ type timeout_type = :connect_timeout | :operation_timeout | :keep_alive_timeout | :total_timeout
9
+ type timeout = Hash[timeout_type, Numeric?]
10
+
8
11
  def self.new: (options) -> instance
9
12
  | () -> instance
10
13
 
14
+ # headers
15
+ attr_reader uri: URI?
16
+ def uri=: (uri) -> void
17
+
11
18
  # headers
12
19
  attr_reader headers: Headers?
13
20
  def headers=: (headers) -> void
14
21
 
15
22
  # timeout
16
- attr_reader timeout: Timeout?
17
- def timeout=: (Hash[Symbol, untyped] | Timeout) -> void
23
+ attr_reader timeout: timeout
24
+ def timeout=: (timeout) -> void
18
25
 
19
26
  # max_concurrent_requests
20
27
  attr_reader max_concurrent_requests: Integer?
@@ -7,6 +7,8 @@ module HTTPX
7
7
 
8
8
  def self.load_dependencies: (singleton(Session)) -> void
9
9
 
10
+ def self.configure: (singleton(Session)) -> void
11
+
10
12
  def self.extra_options: (Options) -> (Options)
11
13
 
12
14
  module InstanceMethods
@@ -3,6 +3,8 @@ module HTTPX
3
3
  module BasicAuthentication
4
4
  def self.load_dependencies: (singleton(Session)) -> void
5
5
 
6
+ def self.configure: (singleton(Session)) -> void
7
+
6
8
  module InstanceMethods
7
9
  def basic_authentication: (string user, string password) -> instance
8
10
  end
@@ -6,8 +6,8 @@ module HTTPX
6
6
  type deflatable = _Reader | _ToS
7
7
 
8
8
  interface _Deflater
9
- def deflate: (deflatable, _Writer, chunk_size: Integer) -> void
10
- | (deflatable, _Writer, chunk_size: Integer) { (String) -> void } -> void
9
+ def deflate: (deflatable, ?_Writer, ?chunk_size: Integer) -> _ToS
10
+ | (deflatable, ?_Writer, ?chunk_size: Integer) { (String) -> void } -> _ToS
11
11
  end
12
12
 
13
13
  interface _Inflater
@@ -33,7 +33,7 @@ module HTTPX
33
33
  end
34
34
 
35
35
  module Part
36
- def self?.call: (multipart_nested_value) -> ([_Reader, String, String?] | [_Reader, String])
36
+ def self?.call: (multipart_nested_value) -> ([_Reader, String, String?])
37
37
  end
38
38
 
39
39
  module MimeTypeDetector
@@ -1,4 +1,21 @@
1
1
  module HTTPX
2
+ class StreamResponse
3
+ include _ToS
4
+
5
+ def each: () { (String) -> void } -> void
6
+ | () -> Enumerable[String]
7
+
8
+ def each_line: () { (String) -> void } -> void
9
+ | () -> Enumerable[String]
10
+
11
+ def on_chunk: (string) -> void
12
+
13
+ private
14
+
15
+ def response: () -> response
16
+ def initialize: (Request, Session, Array[Connection]) -> untyped
17
+ end
18
+
2
19
  module Plugins
3
20
  module Stream
4
21
  module InstanceMethods
@@ -16,22 +33,6 @@ module HTTPX
16
33
  def stream: () -> StreamResponse?
17
34
  end
18
35
 
19
- class StreamResponse
20
- include _ToS
21
-
22
- def each: () { (String) -> void } -> void
23
- | () -> Enumerable[String]
24
-
25
- def each_line: () { (String) -> void } -> void
26
- | () -> Enumerable[String]
27
-
28
- def on_chunk: (string) -> void
29
-
30
- private
31
-
32
- def response: () -> response
33
- def initialize: (Request, Session) -> untyped
34
- end
35
36
  end
36
37
 
37
38
  type sessionStream = Session & Plugins::Stream::InstanceMethods
data/sig/request.rbs CHANGED
@@ -11,7 +11,8 @@ module HTTPX
11
11
  attr_reader body: Body
12
12
  attr_reader state: Symbol
13
13
  attr_reader options: Options
14
- attr_reader response: Response?
14
+ attr_reader response: response?
15
+ attr_reader drain_error: StandardError?
15
16
 
16
17
  def initialize: (verb | String, uri, ?options?) -> untyped
17
18
 
@@ -21,7 +22,7 @@ module HTTPX
21
22
 
22
23
  def scheme: () -> ("http" | "https")
23
24
 
24
- def response=: (Response response) -> void
25
+ def response=: (response) -> void
25
26
 
26
27
  def path: () -> String
27
28
 
@@ -39,6 +40,10 @@ module HTTPX
39
40
 
40
41
  def expects?: () -> boolish
41
42
 
43
+ def trailers: () -> Headers
44
+
45
+ def trailers?: () -> boolish
46
+
42
47
  class Body
43
48
  def initialize: (Headers, Options) -> untyped
44
49
  def each: () { (String) -> void } -> void
data/sig/response.rbs CHANGED
@@ -47,6 +47,7 @@ module HTTPX
47
47
  def empty?: () -> bool
48
48
  def copy_to: (_ToPath | _Writer destination) -> void
49
49
  def close: () -> void
50
+ def closed?: () -> bool
50
51
 
51
52
  private
52
53
 
data/sig/session.rbs CHANGED
@@ -45,5 +45,9 @@ module HTTPX
45
45
  def build_connection: (URI, Options) -> Connection
46
46
 
47
47
  def send_requests: (*Request, options) -> Array[response]
48
+
49
+ def _send_requests: (Array[Request], options) -> Array[Connection]
50
+
51
+ def receive_requests: (Array[Request], Array[Connection], options) -> Array[response]
48
52
  end
49
53
  end
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: 0.13.1
4
+ version: 0.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-27 00:00:00.000000000 Z
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2-next
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
19
+ version: 0.4.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.2
26
+ version: 0.4.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: timers
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -61,6 +61,11 @@ extra_rdoc_files:
61
61
  - doc/release_notes/0_12_0.md
62
62
  - doc/release_notes/0_13_0.md
63
63
  - doc/release_notes/0_13_1.md
64
+ - doc/release_notes/0_13_2.md
65
+ - doc/release_notes/0_14_0.md
66
+ - doc/release_notes/0_14_1.md
67
+ - doc/release_notes/0_14_2.md
68
+ - doc/release_notes/0_14_3.md
64
69
  - doc/release_notes/0_1_0.md
65
70
  - doc/release_notes/0_2_0.md
66
71
  - doc/release_notes/0_2_1.md
@@ -101,6 +106,11 @@ files:
101
106
  - doc/release_notes/0_12_0.md
102
107
  - doc/release_notes/0_13_0.md
103
108
  - doc/release_notes/0_13_1.md
109
+ - doc/release_notes/0_13_2.md
110
+ - doc/release_notes/0_14_0.md
111
+ - doc/release_notes/0_14_1.md
112
+ - doc/release_notes/0_14_2.md
113
+ - doc/release_notes/0_14_3.md
104
114
  - doc/release_notes/0_1_0.md
105
115
  - doc/release_notes/0_2_0.md
106
116
  - doc/release_notes/0_2_1.md
@@ -165,6 +175,9 @@ files:
165
175
  - lib/httpx/plugins/digest_authentication.rb
166
176
  - lib/httpx/plugins/expect.rb
167
177
  - lib/httpx/plugins/follow_redirects.rb
178
+ - lib/httpx/plugins/grpc.rb
179
+ - lib/httpx/plugins/grpc/call.rb
180
+ - lib/httpx/plugins/grpc/message.rb
168
181
  - lib/httpx/plugins/h2c.rb
169
182
  - lib/httpx/plugins/internal_telemetry.rb
170
183
  - lib/httpx/plugins/multipart.rb
@@ -194,7 +207,6 @@ files:
194
207
  - lib/httpx/response.rb
195
208
  - lib/httpx/selector.rb
196
209
  - lib/httpx/session.rb
197
- - lib/httpx/timeout.rb
198
210
  - lib/httpx/transcoder.rb
199
211
  - lib/httpx/transcoder/body.rb
200
212
  - lib/httpx/transcoder/chunker.rb
@@ -253,7 +265,6 @@ files:
253
265
  - sig/response.rbs
254
266
  - sig/selector.rbs
255
267
  - sig/session.rbs
256
- - sig/timeout.rbs
257
268
  - sig/transcoder.rbs
258
269
  - sig/transcoder/body.rbs
259
270
  - sig/transcoder/chunker.rbs
@@ -282,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
293
  - !ruby/object:Gem::Version
283
294
  version: '0'
284
295
  requirements: []
285
- rubygems_version: 3.2.3
296
+ rubygems_version: 3.2.15
286
297
  signing_key:
287
298
  specification_version: 4
288
299
  summary: HTTPX, to the future, and beyond
data/lib/httpx/timeout.rb DELETED
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "timeout"
4
-
5
- module HTTPX
6
- class Timeout
7
- CONNECT_TIMEOUT = 60
8
- OPERATION_TIMEOUT = 60
9
- KEEP_ALIVE_TIMEOUT = 20
10
-
11
- def self.new(opts = {})
12
- return opts if opts.is_a?(Timeout)
13
-
14
- super(**opts)
15
- end
16
-
17
- attr_reader :connect_timeout, :operation_timeout, :keep_alive_timeout, :total_timeout
18
-
19
- def initialize(connect_timeout: CONNECT_TIMEOUT,
20
- operation_timeout: OPERATION_TIMEOUT,
21
- keep_alive_timeout: KEEP_ALIVE_TIMEOUT,
22
- total_timeout: nil,
23
- loop_timeout: nil)
24
- @connect_timeout = connect_timeout
25
- @operation_timeout = operation_timeout
26
- @keep_alive_timeout = keep_alive_timeout
27
- @total_timeout = total_timeout
28
-
29
- return unless loop_timeout
30
-
31
- # :nocov:
32
- warn ":loop_timeout is deprecated, use :operation_timeout instead"
33
- @operation_timeout = loop_timeout
34
- # :nocov:
35
- end
36
-
37
- def ==(other)
38
- if other.is_a?(Timeout)
39
- @connect_timeout == other.instance_variable_get(:@connect_timeout) &&
40
- @operation_timeout == other.instance_variable_get(:@operation_timeout) &&
41
- @keep_alive_timeout == other.instance_variable_get(:@keep_alive_timeout) &&
42
- @total_timeout == other.instance_variable_get(:@total_timeout)
43
- else
44
- super
45
- end
46
- end
47
-
48
- def merge(other)
49
- case other
50
- when Hash
51
- timeout = Timeout.new(other)
52
- merge(timeout)
53
- when Timeout
54
- connect_timeout = other.instance_variable_get(:@connect_timeout) || @connect_timeout
55
- operation_timeout = other.instance_variable_get(:@operation_timeout) || @operation_timeout
56
- keep_alive_timeout = other.instance_variable_get(:@keep_alive_timeout) || @keep_alive_timeout
57
- total_timeout = other.instance_variable_get(:@total_timeout) || @total_timeout
58
- Timeout.new(connect_timeout: connect_timeout,
59
- operation_timeout: operation_timeout,
60
- keep_alive_timeout: keep_alive_timeout,
61
- total_timeout: total_timeout)
62
- else
63
- raise ArgumentError, "can't merge with #{other.class}"
64
- end
65
- end
66
- end
67
- end