httpx 1.2.5 → 1.3.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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes/1_2_6.md +13 -0
  3. data/doc/release_notes/1_3_0.md +18 -0
  4. data/lib/httpx/adapters/datadog.rb +1 -1
  5. data/lib/httpx/adapters/faraday.rb +1 -0
  6. data/lib/httpx/adapters/webmock.rb +1 -1
  7. data/lib/httpx/connection/http1.rb +3 -2
  8. data/lib/httpx/connection/http2.rb +6 -6
  9. data/lib/httpx/connection.rb +11 -5
  10. data/lib/httpx/io/tcp.rb +1 -1
  11. data/lib/httpx/io/unix.rb +5 -3
  12. data/lib/httpx/options.rb +3 -7
  13. data/lib/httpx/parser/http1.rb +4 -0
  14. data/lib/httpx/plugins/aws_sigv4.rb +1 -1
  15. data/lib/httpx/plugins/cookies.rb +6 -6
  16. data/lib/httpx/plugins/follow_redirects.rb +44 -24
  17. data/lib/httpx/plugins/grpc.rb +3 -2
  18. data/lib/httpx/plugins/h2c.rb +1 -1
  19. data/lib/httpx/plugins/oauth.rb +1 -1
  20. data/lib/httpx/plugins/proxy/http.rb +2 -2
  21. data/lib/httpx/plugins/proxy/socks4.rb +1 -1
  22. data/lib/httpx/plugins/proxy/socks5.rb +1 -1
  23. data/lib/httpx/plugins/rate_limiter.rb +2 -0
  24. data/lib/httpx/plugins/ssrf_filter.rb +1 -1
  25. data/lib/httpx/request/body.rb +37 -41
  26. data/lib/httpx/request.rb +36 -10
  27. data/lib/httpx/resolver/https.rb +1 -1
  28. data/lib/httpx/resolver/native.rb +26 -8
  29. data/lib/httpx/resolver/resolver.rb +1 -1
  30. data/lib/httpx/response.rb +2 -2
  31. data/lib/httpx/session.rb +20 -17
  32. data/lib/httpx/timers.rb +1 -1
  33. data/lib/httpx/transcoder/multipart/encoder.rb +1 -1
  34. data/lib/httpx/version.rb +1 -1
  35. data/sig/chainable.rbs +2 -2
  36. data/sig/connection/http1.rbs +2 -2
  37. data/sig/connection/http2.rbs +17 -17
  38. data/sig/connection.rbs +7 -6
  39. data/sig/httpx.rbs +3 -3
  40. data/sig/io/ssl.rbs +1 -0
  41. data/sig/io/tcp.rbs +1 -1
  42. data/sig/io/unix.rbs +18 -1
  43. data/sig/options.rbs +5 -14
  44. data/sig/parser/http1.rbs +1 -1
  45. data/sig/plugins/callbacks.rbs +1 -1
  46. data/sig/plugins/follow_redirects.rbs +10 -5
  47. data/sig/plugins/grpc.rbs +5 -0
  48. data/sig/plugins/proxy/http.rbs +3 -0
  49. data/sig/plugins/proxy/socks4.rbs +5 -2
  50. data/sig/plugins/proxy/socks5.rbs +5 -2
  51. data/sig/plugins/push_promise.rbs +3 -3
  52. data/sig/plugins/rate_limiter.rbs +1 -1
  53. data/sig/plugins/retries.rbs +2 -0
  54. data/sig/request/body.rbs +1 -3
  55. data/sig/request.rbs +2 -1
  56. data/sig/resolver/https.rbs +1 -1
  57. data/sig/resolver/native.rbs +2 -0
  58. data/sig/resolver/resolver.rbs +1 -1
  59. data/sig/response.rbs +1 -1
  60. data/sig/session.rbs +10 -7
  61. data/sig/transcoder/multipart.rbs +11 -6
  62. data/sig/transcoder/xml.rbs +1 -0
  63. data/sig/utils.rbs +4 -0
  64. metadata +10 -6
@@ -4,30 +4,53 @@ module HTTPX
4
4
  # Implementation of the HTTP Request body as a delegator which iterates (responds to +each+) payload chunks.
5
5
  class Request::Body < SimpleDelegator
6
6
  class << self
7
- def new(_, options)
8
- return options.body if options.body.is_a?(self)
7
+ def new(_, options, body: nil, **params)
8
+ if body.is_a?(self)
9
+ # request derives its options from body
10
+ body.options = options.merge(params)
11
+ return body
12
+ end
9
13
 
10
14
  super
11
15
  end
12
16
  end
13
17
 
14
- # inits the instance with the request +headers+ and +options+, which contain the payload definition.
15
- def initialize(headers, options)
16
- @headers = headers
18
+ attr_accessor :options
17
19
 
18
- # forego compression in the Range request case
19
- if @headers.key?("range")
20
- @headers.delete("accept-encoding")
21
- else
22
- @headers["accept-encoding"] ||= options.supported_compression_formats
20
+ # inits the instance with the request +headers+, +options+ and +params+, which contain the payload definition.
21
+ # it wraps the given body with the appropriate encoder on initialization.
22
+ #
23
+ # ..., json: { foo: "bar" }) #=> json encoder
24
+ # ..., form: { foo: "bar" }) #=> form urlencoded encoder
25
+ # ..., form: { foo: Pathname.open("path/to/file") }) #=> multipart urlencoded encoder
26
+ # ..., form: { foo: File.open("path/to/file") }) #=> multipart urlencoded encoder
27
+ # ..., form: { body: "bla") }) #=> raw data encoder
28
+ def initialize(headers, options, body: nil, form: nil, json: nil, xml: nil, **params)
29
+ @headers = headers
30
+ @options = options.merge(params)
31
+
32
+ @body = if body
33
+ Transcoder::Body.encode(body)
34
+ elsif form
35
+ Transcoder::Form.encode(form)
36
+ elsif json
37
+ Transcoder::JSON.encode(json)
38
+ elsif xml
39
+ Transcoder::Xml.encode(xml)
23
40
  end
24
41
 
25
- initialize_body(options)
42
+ if @body
43
+ if @options.compress_request_body && @headers.key?("content-encoding")
26
44
 
27
- return if @body.nil?
45
+ @headers.get("content-encoding").each do |encoding|
46
+ @body = self.class.initialize_deflater_body(@body, encoding)
47
+ end
48
+ end
49
+
50
+ @headers["content-type"] ||= @body.content_type
51
+ @headers["content-length"] = @body.bytesize unless unbounded_body?
52
+ end
28
53
 
29
- @headers["content-type"] ||= @body.content_type
30
- @headers["content-length"] = @body.bytesize unless unbounded_body?
31
54
  super(@body)
32
55
  end
33
56
 
@@ -99,33 +122,6 @@ module HTTPX
99
122
  end
100
123
  # :nocov:
101
124
 
102
- private
103
-
104
- # wraps the given body with the appropriate encoder.
105
- #
106
- # ..., json: { foo: "bar" }) #=> json encoder
107
- # ..., form: { foo: "bar" }) #=> form urlencoded encoder
108
- # ..., form: { foo: Pathname.open("path/to/file") }) #=> multipart urlencoded encoder
109
- # ..., form: { foo: File.open("path/to/file") }) #=> multipart urlencoded encoder
110
- # ..., form: { body: "bla") }) #=> raw data encoder
111
- def initialize_body(options)
112
- @body = if options.body
113
- Transcoder::Body.encode(options.body)
114
- elsif options.form
115
- Transcoder::Form.encode(options.form)
116
- elsif options.json
117
- Transcoder::JSON.encode(options.json)
118
- elsif options.xml
119
- Transcoder::Xml.encode(options.xml)
120
- end
121
-
122
- return unless @body && options.compress_request_body && @headers.key?("content-encoding")
123
-
124
- @headers.get("content-encoding").each do |encoding|
125
- @body = self.class.initialize_deflater_body(@body, encoding)
126
- end
127
- end
128
-
129
125
  class << self
130
126
  # returns the +body+ wrapped with the correct deflater accordinng to the given +encodisng+.
131
127
  def initialize_deflater_body(body, encoding)
data/lib/httpx/request.rb CHANGED
@@ -46,12 +46,43 @@ module HTTPX
46
46
  # will be +true+ when request body has been completely flushed.
47
47
  def_delegator :@body, :empty?
48
48
 
49
- # initializes the instance with the given +verb+, an absolute or relative +uri+, and the
50
- # request options.
51
- def initialize(verb, uri, options = {})
49
+ # initializes the instance with the given +verb+ (an upppercase String, ex. 'GEt'),
50
+ # an absolute or relative +uri+ (either as String or URI::HTTP object), the
51
+ # request +options+ (instance of HTTPX::Options) and an optional Hash of +params+.
52
+ #
53
+ # Besides any of the options documented in HTTPX::Options (which would override or merge with what
54
+ # +options+ sets), it accepts also the following:
55
+ #
56
+ # :params :: hash or array of key-values which will be encoded and set in the query string of request uris.
57
+ # :body :: to be encoded in the request body payload. can be a String, an IO object (i.e. a File), or an Enumerable.
58
+ # :form :: hash of array of key-values which will be form-urlencoded- or multipart-encoded in requests body payload.
59
+ # :json :: hash of array of key-values which will be JSON-encoded in requests body payload.
60
+ # :xml :: Nokogiri XML nodes which will be encoded in requests body payload.
61
+ #
62
+ # :body, :form, :json and :xml are all mutually exclusive, i.e. only one of them gets picked up.
63
+ def initialize(verb, uri, options, params = EMPTY_HASH)
52
64
  @verb = verb.to_s.upcase
53
- @options = Options.new(options)
54
65
  @uri = Utils.to_uri(uri)
66
+
67
+ @headers = options.headers.dup
68
+ merge_headers(params.delete(:headers)) if params.key?(:headers)
69
+
70
+ @headers["user-agent"] ||= USER_AGENT
71
+ @headers["accept"] ||= "*/*"
72
+
73
+ # forego compression in the Range request case
74
+ if @headers.key?("range")
75
+ @headers.delete("accept-encoding")
76
+ else
77
+ @headers["accept-encoding"] ||= options.supported_compression_formats
78
+ end
79
+
80
+ @query_params = params.delete(:params) if params.key?(:params)
81
+
82
+ @body = options.request_body_class.new(@headers, options, **params)
83
+
84
+ @options = @body.options
85
+
55
86
  if @uri.relative?
56
87
  origin = @options.origin
57
88
  raise(Error, "invalid URI: #{@uri}") unless origin
@@ -61,11 +92,6 @@ module HTTPX
61
92
  @uri = origin.merge("#{base_path}#{@uri}")
62
93
  end
63
94
 
64
- @headers = @options.headers.dup
65
- @headers["user-agent"] ||= USER_AGENT
66
- @headers["accept"] ||= "*/*"
67
-
68
- @body = @options.request_body_class.new(@headers, @options)
69
95
  @state = :idle
70
96
  @response = nil
71
97
  @peer_address = nil
@@ -172,7 +198,7 @@ module HTTPX
172
198
  return @query if defined?(@query)
173
199
 
174
200
  query = []
175
- if (q = @options.params)
201
+ if (q = @query_params)
176
202
  query << Transcoder::Form.encode(q)
177
203
  end
178
204
  query << @uri.query if @uri.query
@@ -219,7 +219,7 @@ module HTTPX
219
219
  uri.query = URI.encode_www_form(params)
220
220
  request = rklass.new("GET", uri, @options)
221
221
  else
222
- request = rklass.new("POST", uri, @options.merge(body: [payload]))
222
+ request = rklass.new("POST", uri, @options, body: [payload])
223
223
  request.headers["content-type"] = "application/dns-message"
224
224
  end
225
225
  request.headers["accept"] = "application/dns-message"
@@ -65,6 +65,7 @@ module HTTPX
65
65
  if nameserver && @ns_index < nameserver.size
66
66
  log { "resolver: failed resolving on nameserver #{@nameserver[@ns_index - 1]} (#{e.message})" }
67
67
  transition(:idle)
68
+ @timeouts.clear
68
69
  else
69
70
  handle_error(e)
70
71
  end
@@ -143,13 +144,16 @@ module HTTPX
143
144
 
144
145
  if !@timeouts[host].empty?
145
146
  log { "resolver: timeout after #{timeout}s, retry(#{@timeouts[host].first}) #{host}..." }
146
- resolve(connection)
147
+ # must downgrade to tcp AND retry on same host as last
148
+ downgrade_socket
149
+ resolve(connection, h)
147
150
  elsif @ns_index + 1 < @nameserver.size
148
151
  # try on the next nameserver
149
152
  @ns_index += 1
150
153
  log { "resolver: failed resolving #{host} on nameserver #{@nameserver[@ns_index - 1]} (timeout error)" }
151
154
  transition(:idle)
152
- resolve(connection)
155
+ @timeouts.clear
156
+ resolve(connection, h)
153
157
  else
154
158
 
155
159
  @timeouts.delete(host)
@@ -187,10 +191,9 @@ module HTTPX
187
191
  next unless @large_packet.full?
188
192
 
189
193
  parse(@large_packet.to_s)
190
- @socket_type = @resolver_options.fetch(:socket_type, :udp)
191
194
  @large_packet = nil
192
- transition(:idle)
193
- transition(:open)
195
+ # downgrade to udp again
196
+ downgrade_socket
194
197
  return
195
198
  else
196
199
  size = @read_buffer[0, 2].unpack1("n")
@@ -304,13 +307,21 @@ module HTTPX
304
307
  end
305
308
 
306
309
  if address.key?("alias") # CNAME
310
+ hostname_alias = address["alias"]
307
311
  # clean up intermediate queries
308
312
  @timeouts.delete(name) unless connection.origin.host == name
309
313
 
310
- if catch(:coalesced) { early_resolve(connection, hostname: address["alias"]) }
314
+ if catch(:coalesced) { early_resolve(connection, hostname: hostname_alias) }
311
315
  @connections.delete(connection)
312
316
  else
313
- resolve(connection, address["alias"])
317
+ if @socket_type == :tcp
318
+ # must downgrade to udp if tcp
319
+ @socket_type = @resolver_options.fetch(:socket_type, :udp)
320
+ transition(:idle)
321
+ transition(:open)
322
+ end
323
+ log { "resolver: ALIAS #{hostname_alias} for #{name}" }
324
+ resolve(connection, hostname_alias)
314
325
  return
315
326
  end
316
327
  else
@@ -386,6 +397,14 @@ module HTTPX
386
397
  end
387
398
  end
388
399
 
400
+ def downgrade_socket
401
+ return unless @socket_type == :tcp
402
+
403
+ @socket_type = @resolver_options.fetch(:socket_type, :udp)
404
+ transition(:idle)
405
+ transition(:open)
406
+ end
407
+
389
408
  def transition(nextstate)
390
409
  case nextstate
391
410
  when :idle
@@ -393,7 +412,6 @@ module HTTPX
393
412
  @io.close
394
413
  @io = nil
395
414
  end
396
- @timeouts.clear
397
415
  when :open
398
416
  return unless @state == :idle
399
417
 
@@ -33,7 +33,7 @@ module HTTPX
33
33
  def initialize(family, options)
34
34
  @family = family
35
35
  @record_type = RECORD_TYPES[family]
36
- @options = Options.new(options)
36
+ @options = options
37
37
  end
38
38
 
39
39
  def close; end
@@ -247,11 +247,11 @@ module HTTPX
247
247
  # the IP address of the peer server.
248
248
  def_delegator :@request, :peer_address
249
249
 
250
- def initialize(request, error, options)
250
+ def initialize(request, error)
251
251
  @request = request
252
252
  @response = request.response if request.response.is_a?(Response)
253
253
  @error = error
254
- @options = Options.new(options)
254
+ @options = request.options
255
255
  log_exception(@error)
256
256
  end
257
257
 
data/lib/httpx/session.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPX
4
+ EMPTY_HASH = {}.freeze
5
+
4
6
  # Class implementing the APIs being used publicly.
5
7
  #
6
8
  # HTTPX.get(..) #=> delegating to an internal HTTPX::Session object.
@@ -9,8 +11,6 @@ module HTTPX
9
11
  include Loggable
10
12
  include Chainable
11
13
 
12
- EMPTY_HASH = {}.freeze
13
-
14
14
  # initializes the session with a set of +options+, which will be shared by all
15
15
  # requests sent from it.
16
16
  #
@@ -65,10 +65,10 @@ module HTTPX
65
65
  # resp1, resp2 = session.request(["POST", "https://server.org/a", form: { "foo" => "bar" }], ["GET", "https://server.org/b"])
66
66
  # resp1, resp2 = session.request("GET", ["https://server.org/a", "https://server.org/b"], headers: { "x-api-token" => "TOKEN" })
67
67
  #
68
- def request(*args, **options)
68
+ def request(*args, **params)
69
69
  raise ArgumentError, "must perform at least one request" if args.empty?
70
70
 
71
- requests = args.first.is_a?(Request) ? args : build_requests(*args, options)
71
+ requests = args.first.is_a?(Request) ? args : build_requests(*args, params)
72
72
  responses = send_requests(*requests)
73
73
  return responses.first if responses.size == 1
74
74
 
@@ -81,10 +81,9 @@ module HTTPX
81
81
  #
82
82
  # req = session.build_request("GET", "https://server.com")
83
83
  # resp = session.request(req)
84
- def build_request(verb, uri, options = EMPTY_HASH)
85
- rklass = @options.request_class
86
- options = @options.merge(options) unless options.is_a?(Options)
87
- request = rklass.new(verb, uri, options)
84
+ def build_request(verb, uri, params = EMPTY_HASH, options = @options)
85
+ rklass = options.request_class
86
+ request = rklass.new(verb, uri, options, params)
88
87
  request.persistent = @persistent
89
88
  set_request_callbacks(request)
90
89
  request
@@ -133,7 +132,7 @@ module HTTPX
133
132
  end
134
133
  return unless error.is_a?(Error)
135
134
 
136
- request.emit(:response, ErrorResponse.new(request, error, options))
135
+ request.emit(:response, ErrorResponse.new(request, error))
137
136
  end
138
137
 
139
138
  # sets the callbacks on the +connection+ required to process certain specific
@@ -192,22 +191,26 @@ module HTTPX
192
191
  end
193
192
 
194
193
  # returns a set of HTTPX::Request objects built from the given +args+ and +options+.
195
- def build_requests(*args, options)
196
- request_options = @options.merge(options)
197
-
194
+ def build_requests(*args, params)
198
195
  requests = if args.size == 1
199
196
  reqs = args.first
200
- reqs.map do |verb, uri, opts = EMPTY_HASH|
201
- build_request(verb, uri, request_options.merge(opts))
197
+ # TODO: find a way to make requests share same options object
198
+ reqs.map do |verb, uri, ps = EMPTY_HASH|
199
+ request_params = params
200
+ request_params = request_params.merge(ps) unless ps.empty?
201
+ build_request(verb, uri, request_params)
202
202
  end
203
203
  else
204
204
  verb, uris = args
205
205
  if uris.respond_to?(:each)
206
- uris.enum_for(:each).map do |uri, opts = EMPTY_HASH|
207
- build_request(verb, uri, request_options.merge(opts))
206
+ # TODO: find a way to make requests share same options object
207
+ uris.enum_for(:each).map do |uri, ps = EMPTY_HASH|
208
+ request_params = params
209
+ request_params = request_params.merge(ps) unless ps.empty?
210
+ build_request(verb, uri, request_params)
208
211
  end
209
212
  else
210
- [build_request(verb, uris, request_options)]
213
+ [build_request(verb, uris, params)]
211
214
  end
212
215
  end
213
216
  raise ArgumentError, "wrong number of URIs (given 0, expect 1..+1)" if requests.empty?
data/lib/httpx/timers.rb CHANGED
@@ -43,7 +43,7 @@ module HTTPX
43
43
 
44
44
  elapsed_time = Utils.elapsed_time(@next_interval_at)
45
45
 
46
- @intervals.delete_if { |interval| interval.elapse(elapsed_time) <= 0 }
46
+ @intervals = @intervals.drop_while { |interval| interval.elapse(elapsed_time) <= 0 }
47
47
 
48
48
  @next_interval_at = nil if @intervals.empty?
49
49
  end
@@ -19,7 +19,7 @@ module HTTPX
19
19
  end
20
20
 
21
21
  def read(length = nil, outbuf = nil)
22
- data = outbuf.clear.force_encoding(Encoding::BINARY) if outbuf
22
+ data = String(outbuf).clear.force_encoding(Encoding::BINARY) if outbuf
23
23
  data ||= "".b
24
24
 
25
25
  read_chunks(data, length)
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.2.5"
4
+ VERSION = "1.3.0"
5
5
  end
data/sig/chainable.rbs CHANGED
@@ -3,8 +3,8 @@ module HTTPX
3
3
  def request: (*Request, **untyped) -> Array[response]
4
4
  | (Request, **untyped) -> response
5
5
  | (verb, uri | [uri], **untyped) -> response
6
- | (Array[[verb, uri] | [verb, uri, options]], **untyped) -> Array[response]
7
- | (verb, _Each[uri | [uri, options]], **untyped) -> Array[response]
6
+ | (Array[[verb, uri] | [verb, uri, request_params]], **untyped) -> Array[response]
7
+ | (verb, _Each[uri | [uri, request_params]], **untyped) -> Array[response]
8
8
 
9
9
  def accept: (String) -> Session
10
10
  def wrap: () { (Session) -> void } -> void
@@ -32,7 +32,7 @@ module HTTPX
32
32
 
33
33
  def exhausted?: () -> bool
34
34
 
35
- def <<: (String) -> void
35
+ def <<: (string) -> void
36
36
 
37
37
  def send: (Request) -> void
38
38
 
@@ -58,7 +58,7 @@ module HTTPX
58
58
 
59
59
  private
60
60
 
61
- def initialize: (Buffer, options) -> untyped
61
+ def initialize: (Buffer buffer, Options options) -> untyped
62
62
 
63
63
  def manage_connection: (Request request, Response response) -> void
64
64
 
@@ -5,7 +5,7 @@ module HTTPX
5
5
 
6
6
  MAX_CONCURRENT_REQUESTS: Integer
7
7
 
8
- attr_reader streams: Hash[Request, HTTP2Next::Stream]
8
+ attr_reader streams: Hash[Request, ::HTTP2::Stream]
9
9
  attr_reader pending: Array[Request]
10
10
 
11
11
  @options: Options
@@ -24,7 +24,7 @@ module HTTPX
24
24
 
25
25
  def exhausted?: () -> bool
26
26
 
27
- def <<: (String) -> void
27
+ def <<: (string) -> void
28
28
 
29
29
  def can_buffer_more_requests?: () -> bool
30
30
 
@@ -42,35 +42,35 @@ module HTTPX
42
42
 
43
43
  private
44
44
 
45
- def initialize: (Buffer, options) -> untyped
45
+ def initialize: (Buffer buffer, Options options) -> untyped
46
46
 
47
47
  def send_pending: () -> void
48
48
 
49
49
  def set_protocol_headers: (Request) -> _Each[[String, String]]
50
50
 
51
- def handle: (Request request, HTTP2Next::Stream stream) -> void
51
+ def handle: (Request request, ::HTTP2::Stream stream) -> void
52
52
 
53
53
  def init_connection: () -> void
54
54
 
55
- def handle_stream: (HTTP2Next::Stream stream, Request request) -> void
55
+ def handle_stream: (::HTTP2::Stream stream, Request request) -> void
56
56
 
57
57
  def join_headline: (Request request) -> String
58
58
 
59
- def join_headers: (HTTP2Next::Stream stream, Request request) -> void
59
+ def join_headers: (::HTTP2::Stream stream, Request request) -> void
60
60
 
61
- def join_trailers: (HTTP2Next::Stream stream, Request request) -> void
61
+ def join_trailers: (::HTTP2::Stream stream, Request request) -> void
62
62
 
63
- def join_body: (HTTP2Next::Stream stream, Request request) -> void
63
+ def join_body: (::HTTP2::Stream stream, Request request) -> void
64
64
 
65
- def on_stream_headers: (HTTP2Next::Stream stream, Request request, Array[[String, String]] headers) -> void
65
+ def on_stream_headers: (::HTTP2::Stream stream, Request request, Array[[String, String]] headers) -> void
66
66
 
67
- def on_stream_trailers: (HTTP2Next::Stream stream, Response response, Array[[String, String]] headers) -> void
67
+ def on_stream_trailers: (::HTTP2::Stream stream, Response response, Array[[String, String]] headers) -> void
68
68
 
69
- def on_stream_data: (HTTP2Next::Stream stream, Request request, String data) -> void
69
+ def on_stream_data: (::HTTP2::Stream stream, Request request, String data) -> void
70
70
 
71
- def on_stream_refuse: (HTTP2Next::Stream stream, Request request, StandardError error) -> void
71
+ def on_stream_refuse: (::HTTP2::Stream stream, Request request, StandardError error) -> void
72
72
 
73
- def on_stream_close: (HTTP2Next::Stream stream, Request request, (Symbol | StandardError)? error) -> void
73
+ def on_stream_close: (::HTTP2::Stream stream, Request request, (Symbol | StandardError)? error) -> void
74
74
 
75
75
  def on_frame: (string bytes) -> void
76
76
 
@@ -78,13 +78,13 @@ module HTTPX
78
78
 
79
79
  def on_close: (Integer last_frame, Symbol? error, String? payload) -> void
80
80
 
81
- def on_frame_sent: (HTTP2Next::frame) -> void
81
+ def on_frame_sent: (::HTTP2::frame) -> void
82
82
 
83
- def on_frame_received: (HTTP2Next::frame) -> void
83
+ def on_frame_received: (::HTTP2::frame) -> void
84
84
 
85
- def on_altsvc: (String origin, HTTP2Next::frame) -> void
85
+ def on_altsvc: (String origin, ::HTTP2::frame) -> void
86
86
 
87
- def on_promise: (HTTP2Next::Stream) -> void
87
+ def on_promise: (::HTTP2::Stream) -> void
88
88
 
89
89
  def on_origin: (String) -> void
90
90
 
data/sig/connection.rbs CHANGED
@@ -20,11 +20,12 @@ module HTTPX
20
20
 
21
21
 
22
22
  attr_reader type: io_type
23
- attr_reader origin: URI::Generic
23
+ attr_reader origin: http_uri
24
24
  attr_reader origins: Array[String]
25
25
  attr_reader state: Symbol
26
26
  attr_reader pending: Array[Request]
27
27
  attr_reader options: Options
28
+ attr_reader ssl_session: OpenSSL::SSL::Session?
28
29
  attr_writer timers: Timers
29
30
 
30
31
  attr_accessor family: Integer?
@@ -37,7 +38,7 @@ module HTTPX
37
38
  @timeout: Numeric?
38
39
  @current_timeout: Numeric?
39
40
  @io: TCP | SSL | UNIX
40
- @parser: HTTP1 | HTTP2 | _Parser
41
+ @parser: Object & _Parser
41
42
  @connected_at: Float
42
43
  @response_received_at: Float
43
44
  @intervals: Array[Timers::Interval]
@@ -92,9 +93,9 @@ module HTTPX
92
93
 
93
94
  private
94
95
 
95
- def initialize: (URI::Generic uri, options) -> void
96
+ def initialize: (http_uri uri, Options options) -> void
96
97
 
97
- def initialize_type: (URI::Generic uri, options) -> io_type
98
+ def initialize_type: (http_uri uri, Options options) -> io_type
98
99
 
99
100
  def connect: () -> void
100
101
 
@@ -104,11 +105,11 @@ module HTTPX
104
105
 
105
106
  def send_pending: () -> void
106
107
 
107
- def parser: () -> (HTTP1 | HTTP2 | _Parser)
108
+ def parser: () -> (Object & _Parser)
108
109
 
109
110
  def send_request_to_parser: (Request request) -> void
110
111
 
111
- def build_parser: (?String protocol) -> (HTTP1 | HTTP2)
112
+ def build_parser: (?String protocol) -> (Object & _Parser)
112
113
 
113
114
  def set_parser_callbacks: (HTTP1 | HTTP2 parser) -> void
114
115
 
data/sig/httpx.rbs CHANGED
@@ -9,9 +9,9 @@ module HTTPX
9
9
  type uri = http_uri | string
10
10
  type generic_uri = String | URI::Generic
11
11
 
12
- type verb = "OPTIONS" | "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE" | "CONNECT" |
13
- "PROPFIND" | "PROPPATCH" | "MKCOL" | "COPY" | "MOVE" | "LOCK" | "UNLOCK" | "ORDERPATCH" |
14
- "ACL" | "REPORT" | "PATCH" | "SEARCH"
12
+ type verb = String
13
+
14
+ type request_params = Hash[Symbol, untyped]
15
15
 
16
16
  type ip_family = Integer #Socket::AF_INET6 | Socket::AF_INET
17
17
 
data/sig/io/ssl.rbs CHANGED
@@ -14,6 +14,7 @@ module HTTPX
14
14
  # TODO: lift when https://github.com/ruby/rbs/issues/1497 fixed
15
15
  # def initialize: (URI::Generic origin, Array[ipaddr]? addresses, options options) ?{ (self) -> void } -> void
16
16
 
17
+ def session_new_cb: { (OpenSSL::SSL::Session sess) -> void } -> void
17
18
  def can_verify_peer?: () -> bool
18
19
 
19
20
  def verify_hostname: (String host) -> bool
data/sig/io/tcp.rbs CHANGED
@@ -15,7 +15,7 @@ module HTTPX
15
15
  alias host ip
16
16
 
17
17
  # TODO: lift when https://github.com/ruby/rbs/issues/1497 fixed
18
- def initialize: (URI::Generic origin, Array[ipaddr]? addresses, options options) ?{ (self) -> void } -> void
18
+ def initialize: (URI::Generic origin, Array[ipaddr]? addresses, Options options) ?{ (instance) -> void } -> void
19
19
 
20
20
  def add_addresses: (Array[ipaddr] addrs) -> void
21
21
 
data/sig/io/unix.rbs CHANGED
@@ -5,6 +5,23 @@ module HTTPX
5
5
 
6
6
  alias host path
7
7
 
8
- def initialize: (http_uri origin, Array[String]? addresses, options options) -> void
8
+ @hostname: String
9
+
10
+ @options: Options
11
+
12
+ @fallback_protocol: String
13
+
14
+ @keep_open: bool
15
+
16
+ @io: Socket
17
+
18
+ def initialize: (http_uri origin, String? path, Options options) -> void
19
+
20
+ def connect: () -> void
21
+
22
+ def expired?: () -> bool
23
+ private
24
+
25
+ def build_socket: () -> Socket
9
26
  end
10
27
  end
data/sig/options.rbs CHANGED
@@ -6,6 +6,9 @@ module HTTPX
6
6
  WINDOW_SIZE: Integer
7
7
  MAX_BODY_THRESHOLD_SIZE: Integer
8
8
  CONNECT_TIMEOUT: Integer
9
+ READ_TIMEOUT: Integer
10
+ WRITE_TIMEOUT: Integer
11
+ REQUEST_TIMEOUT: Integer
9
12
  OPERATION_TIMEOUT: Integer
10
13
  KEEP_ALIVE_TIMEOUT: Integer
11
14
  SETTINGS_TIMEOUT: Integer
@@ -46,7 +49,7 @@ module HTTPX
46
49
  attr_reader body_threshold_size: Integer
47
50
 
48
51
  # transport
49
- attr_reader transport: "unix" | nil
52
+ attr_reader transport: io_type | nil
50
53
 
51
54
  # addresses
52
55
  attr_reader addresses: Array[ipaddr]?
@@ -60,19 +63,7 @@ module HTTPX
60
63
  # decompress_response_body
61
64
  attr_reader decompress_response_body: bool
62
65
 
63
- # params
64
- attr_reader params: Transcoder::urlencoded_input?
65
-
66
- # form
67
- attr_reader form: Transcoder::urlencoded_input?
68
-
69
- # json
70
- attr_reader json: _ToJson?
71
-
72
- # body
73
- attr_reader body: bodyIO?
74
-
75
- # body
66
+ # origin
76
67
  attr_reader origin: URI::Generic?
77
68
 
78
69
  # base_path