httpx 0.14.1 → 0.15.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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes/0_13_2.md +1 -1
  3. data/doc/release_notes/0_14_1.md +1 -1
  4. data/doc/release_notes/0_14_2.md +6 -0
  5. data/doc/release_notes/0_14_3.md +5 -0
  6. data/doc/release_notes/0_14_4.md +5 -0
  7. data/doc/release_notes/0_14_5.md +11 -0
  8. data/doc/release_notes/0_15_0.md +44 -0
  9. data/lib/httpx.rb +1 -0
  10. data/lib/httpx/connection.rb +14 -3
  11. data/lib/httpx/connection/http1.rb +15 -2
  12. data/lib/httpx/connection/http2.rb +14 -0
  13. data/lib/httpx/domain_name.rb +0 -290
  14. data/lib/httpx/errors.rb +2 -0
  15. data/lib/httpx/extensions.rb +1 -1
  16. data/lib/httpx/options.rb +2 -0
  17. data/lib/httpx/plugins/digest_authentication.rb +19 -21
  18. data/lib/httpx/plugins/grpc.rb +1 -1
  19. data/lib/httpx/plugins/grpc/call.rb +1 -2
  20. data/lib/httpx/plugins/multipart/part.rb +1 -1
  21. data/lib/httpx/plugins/ntlm_authentication.rb +66 -0
  22. data/lib/httpx/plugins/proxy/socks4.rb +4 -0
  23. data/lib/httpx/plugins/proxy/socks5.rb +4 -0
  24. data/lib/httpx/pmatch_extensions.rb +33 -0
  25. data/lib/httpx/punycode.rb +304 -0
  26. data/lib/httpx/request.rb +1 -1
  27. data/lib/httpx/response.rb +2 -0
  28. data/lib/httpx/selector.rb +31 -31
  29. data/lib/httpx/utils.rb +6 -4
  30. data/lib/httpx/version.rb +1 -1
  31. data/sig/chainable.rbs +5 -0
  32. data/sig/connection/http1.rbs +2 -0
  33. data/sig/connection/http2.rbs +2 -0
  34. data/sig/options.rbs +1 -1
  35. data/sig/plugins/aws_sdk_authentication.rbs +2 -0
  36. data/sig/plugins/basic_authentication.rbs +1 -1
  37. data/sig/plugins/digest_authentication.rbs +1 -1
  38. data/sig/plugins/follow_redirects.rbs +1 -1
  39. data/sig/plugins/grpc.rbs +93 -0
  40. data/sig/plugins/multipart.rbs +2 -2
  41. data/sig/plugins/ntlm_authentication.rbs +27 -0
  42. data/sig/plugins/proxy/socks4.rbs +1 -0
  43. data/sig/plugins/proxy/socks5.rbs +1 -0
  44. data/sig/utils.rbs +7 -0
  45. metadata +18 -2
data/lib/httpx/request.rb CHANGED
@@ -45,7 +45,7 @@ module HTTPX
45
45
  def initialize(verb, uri, options = {})
46
46
  @verb = verb.to_s.downcase.to_sym
47
47
  @options = Options.new(options)
48
- @uri = Utils.uri(uri)
48
+ @uri = Utils.to_uri(uri)
49
49
  if @uri.relative?
50
50
  raise(Error, "invalid URI: #{@uri}") unless @options.origin
51
51
 
@@ -296,3 +296,5 @@ module HTTPX
296
296
  # rubocop:enable Style/MissingRespondToMissing
297
297
  end
298
298
  end
299
+
300
+ require "httpx/pmatch_extensions" if RUBY_VERSION >= "3.0.0"
@@ -52,41 +52,41 @@ class HTTPX::Selector
52
52
  # first, we group IOs based on interest type. On call to #interests however,
53
53
  # things might already happen, and new IOs might be registered, so we might
54
54
  # have to start all over again. We do this until we group all selectables
55
- loop do
56
- begin
57
- r = nil
58
- w = nil
59
-
60
- selectables = @selectables
61
- @selectables = []
62
-
63
- selectables.each do |io|
64
- interests = io.interests
65
-
66
- (r ||= []) << io if READ_INTERESTS.include?(interests)
67
- (w ||= []) << io if WRITE_INTERESTS.include?(interests)
68
- end
69
-
70
- if @selectables.empty?
71
- @selectables = selectables
72
-
73
- # do not run event loop if there's nothing to wait on.
74
- # this might happen if connect failed and connection was unregistered.
75
- return if (!r || r.empty?) && (!w || w.empty?)
76
-
77
- break
78
- else
79
- @selectables = [*selectables, @selectables]
55
+ begin
56
+ loop do
57
+ begin
58
+ r = nil
59
+ w = nil
60
+
61
+ selectables = @selectables
62
+ @selectables = []
63
+
64
+ selectables.each do |io|
65
+ interests = io.interests
66
+
67
+ (r ||= []) << io if READ_INTERESTS.include?(interests)
68
+ (w ||= []) << io if WRITE_INTERESTS.include?(interests)
69
+ end
70
+
71
+ if @selectables.empty?
72
+ @selectables = selectables
73
+
74
+ # do not run event loop if there's nothing to wait on.
75
+ # this might happen if connect failed and connection was unregistered.
76
+ return if (!r || r.empty?) && (!w || w.empty?)
77
+
78
+ break
79
+ else
80
+ @selectables = [*selectables, @selectables]
81
+ end
82
+ rescue StandardError
83
+ @selectables = selectables if selectables
84
+ raise
80
85
  end
81
- rescue StandardError
82
- @selectables = selectables if selectables
83
- raise
84
86
  end
85
- end
86
87
 
87
- # TODO: what to do if there are no selectables?
88
+ # TODO: what to do if there are no selectables?
88
89
 
89
- begin
90
90
  readers, writers = IO.select(r, w, nil, interval)
91
91
 
92
92
  raise HTTPX::TimeoutError.new(interval, "timed out while waiting on select") if readers.nil? && writers.nil?
data/lib/httpx/utils.rb CHANGED
@@ -18,14 +18,16 @@ module HTTPX
18
18
  end
19
19
 
20
20
  if RUBY_VERSION < "2.3"
21
- def uri(*args)
22
- URI(*args)
21
+
22
+ def to_uri(uri)
23
+ URI(uri)
23
24
  end
25
+
24
26
  else
25
27
 
26
28
  URIParser = URI::RFC2396_Parser.new
27
29
 
28
- def uri(uri)
30
+ def to_uri(uri)
29
31
  return Kernel.URI(uri) unless uri.is_a?(String) && !uri.ascii_only?
30
32
 
31
33
  uri = Kernel.URI(URIParser.escape(uri))
@@ -34,7 +36,7 @@ module HTTPX
34
36
 
35
37
  non_ascii_hostname.force_encoding(Encoding::UTF_8)
36
38
 
37
- idna_hostname = DomainName.new(non_ascii_hostname).hostname
39
+ idna_hostname = Punycode.encode_hostname(non_ascii_hostname)
38
40
 
39
41
  uri.host = idna_hostname
40
42
  uri.non_ascii_hostname = non_ascii_hostname
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.14.1"
4
+ VERSION = "0.15.0"
5
5
  end
data/sig/chainable.rbs CHANGED
@@ -14,6 +14,8 @@ module HTTPX
14
14
  def plugin: (:authentication) -> Plugins::sessionAuthentication
15
15
  | (:basic_authentication) -> Plugins::sessionBasicAuthentication
16
16
  | (:digest_authentication) -> Plugins::sessionDigestAuthentication
17
+ | (:ntlm_authentication) -> Plugins::sessionNTLMAuthentication
18
+ | (:aws_sdk_authentication) -> Plugins::sessionAwsSdkAuthentication
17
19
  | (:compression) -> Session
18
20
  | (:cookies) -> Plugins::sessionCookies
19
21
  | (:expect) -> Session
@@ -25,7 +27,10 @@ module HTTPX
25
27
  | (:proxy) -> Plugins::sessionProxy
26
28
  | (:push_promise) -> Plugins::sessionPushPromise
27
29
  | (:retries) -> Plugins::sessionRetries
30
+ | (:rate_limiter) -> Session
28
31
  | (:stream) -> Plugins::sessionStream
32
+ | (:aws_sigv4) -> Plugins::awsSigV4Session
33
+ | (:grpc) -> Plugins::grpcSession
29
34
  | (Symbol | Module, ?options?) { (Class) -> void } -> Session
30
35
  | (Symbol | Module, ?options?) -> Session
31
36
 
@@ -42,6 +42,8 @@ module HTTPX
42
42
 
43
43
  def ping: () -> void
44
44
 
45
+ def timeout: () -> Integer
46
+
45
47
  private
46
48
 
47
49
  def initialize: (Buffer, options) -> untyped
@@ -35,6 +35,8 @@ module HTTPX
35
35
 
36
36
  alias reset init_connection
37
37
 
38
+ def timeout: () -> Integer
39
+
38
40
  private
39
41
 
40
42
  def initialize: (Buffer, options) -> untyped
data/sig/options.rbs CHANGED
@@ -5,7 +5,7 @@ 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
8
+ type timeout_type = :connect_timeout | :settings_timeout | :operation_timeout | :keep_alive_timeout | :total_timeout
9
9
  type timeout = Hash[timeout_type, Numeric?]
10
10
 
11
11
  def self.new: (options) -> instance
@@ -15,5 +15,7 @@ module HTTPX
15
15
  def aws_sdk_authentication: (**untyped) -> instance
16
16
  end
17
17
  end
18
+
19
+ type sessionAwsSdkAuthentication = Session & Plugins::AwsSdkAuthentication::InstanceMethods
18
20
  end
19
21
  end
@@ -10,6 +10,6 @@ module HTTPX
10
10
  end
11
11
  end
12
12
 
13
- type sessionBasicAuthentication = Plugins::sessionAuthentication & Plugins::Authentication::InstanceMethods
13
+ type sessionBasicAuthentication = Plugins::sessionAuthentication & Plugins::BasicAuthentication::InstanceMethods
14
14
  end
15
15
  end
@@ -27,6 +27,6 @@ module HTTPX
27
27
  end
28
28
  end
29
29
 
30
- type sessionDigestAuthentication = Plugins::sessionAuthentication & Plugins::Authentication::InstanceMethods
30
+ type sessionDigestAuthentication = Plugins::sessionAuthentication & Plugins::DigestAuthentication::InstanceMethods
31
31
  end
32
32
  end
@@ -30,6 +30,6 @@ module HTTPX
30
30
  end
31
31
  end
32
32
 
33
- type sessionFollowRedirects = Session & Plugins::Authentication::InstanceMethods
33
+ type sessionFollowRedirects = Session & Plugins::FollowRedirects::InstanceMethods
34
34
  end
35
35
  end
@@ -0,0 +1,93 @@
1
+ module HTTPX
2
+ class GRPCError < Error
3
+ attr_reader status: Integer
4
+ attr_reader details: String
5
+ attr_reader metadata: headers
6
+ end
7
+
8
+ module Plugins
9
+ module GRPC
10
+ type compression_option = bool | String
11
+ type rpc_def = [String, untyped, untyped, Hash[Symbol, untyped]]
12
+
13
+ type grpc_message = String | _Each[String]
14
+
15
+ type grpc_request = untyped | _Each[untyped]
16
+ type grpc_response = untyped | _Each[untyped]
17
+
18
+ class Call
19
+ attr_writer decoder: _Callable
20
+
21
+ def metadata: () -> headers
22
+
23
+ def trailing_metadata: () -> headers?
24
+
25
+ private
26
+
27
+ def initialize: (Response | StreamResponse response) -> untyped
28
+
29
+ def grpc_response: () -> grpc_response
30
+ end
31
+
32
+ module Message
33
+ def self?.unary: (response) -> grpc_message
34
+
35
+ def self?.stream: (StreamResponse) { (String) -> void } -> void
36
+ | (StreamResponse) -> Enumerable[String]
37
+
38
+ def self?.encode: (String bytes, ?deflater: Compression::_Deflater?) -> String
39
+
40
+ def self?.decode: (String message, encodings: Array[String], encoders: Compression::encodings_registry) -> String
41
+ | (String message, encodings: Array[String], encoders: Compression::encodings_registry) { (String) -> void } -> void
42
+
43
+ def self?.cancel: (Request) -> void
44
+
45
+ def self?.verify_status: (StreamResponse | response) -> void
46
+ end
47
+
48
+ interface _GRPCOptions
49
+ def grpc_service: () -> String?
50
+ def grpc_service=: (string) -> String
51
+
52
+ def grpc_compression: () -> compression_option?
53
+ def grpc_compression=: (compression_option) -> compression_option
54
+
55
+ def grpc_rpcs: () -> Hash[String, rpc_def]?
56
+ def grpc_rpcs=: (Hash[String, rpc_def]) -> Hash[String, rpc_def]
57
+
58
+ def grpc_deadline: () -> Integer?
59
+ def grpc_deadline=: (Integer) -> Integer
60
+
61
+ def call_credentials: () -> credentials?
62
+ def call_credentials=: (credentials) -> credentials
63
+ end
64
+
65
+ def self.extra_options: (Options) -> (Options & _GRPCOptions)
66
+ def self.load_dependencies: (singleton(Session)) -> void
67
+
68
+ module ResponseMethods
69
+ def merge_headers: (headers_input trailers) -> void
70
+
71
+ def encoders: () -> Compression::encodings_registry
72
+ end
73
+
74
+ module InstanceMethods
75
+ def with_channel_credentials: (String ca_path, ?String? key, ?String? cert, **untyped) -> instance
76
+
77
+ def rpc: (_ToS rpc_name, untyped input, untyped output, **untyped) -> instance
78
+
79
+ def build_stub: (string origin, ?service: _ToS, ?compression: compression_option) -> instance
80
+
81
+ def execute: (_ToS rpc_method, grpc_message input, ?deadline: Integer, ?metadata: headers_input, **untyped) -> Call
82
+
83
+ private
84
+
85
+ def rpc_execute: (_ToS rpc_method, grpc_request input, **untyped) -> Call
86
+
87
+ def build_grpc_request: (string rpc_method, grpc_message input, ?deadline: Integer, ?metadata?: headers_input, **untyped) -> Request
88
+ end
89
+ end
90
+
91
+ type grpcSession = Session & Plugins::GRPC::InstanceMethods
92
+ end
93
+ end
@@ -23,7 +23,7 @@ module HTTPX
23
23
 
24
24
  private
25
25
 
26
- def initialize: (Hash[Symbol | string, multipart_nested_value] multipart_data) -> untyped
26
+ def initialize: (_Each[Symbol | string, multipart_nested_value] multipart_data) -> untyped
27
27
 
28
28
  def header_part: (string key, String content_type, String? filename) -> StringIO
29
29
 
@@ -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
@@ -0,0 +1,27 @@
1
+ module HTTPX
2
+ module Plugins
3
+ module NTLMAuthentication
4
+
5
+ interface _NTLMOptions
6
+ def ntlm: () -> NTLMParams?
7
+ def ntlm=: (NTLMParams) -> NTLMParams
8
+ end
9
+
10
+ def self.extra_options: (Options) -> (Options & _NTLMOptions)
11
+
12
+ def self.load_dependencies: (*untyped) -> void
13
+
14
+ module InstanceMethods
15
+ def ntlm_authentication: (string user, string password, ?string? domain) -> instance
16
+ end
17
+
18
+ class NTLMParams
19
+ attr_reader user: String
20
+ attr_reader password: String
21
+ attr_reader domain: String?
22
+ end
23
+ end
24
+
25
+ type sessionNTLMAuthentication = Plugins::sessionAuthentication & Plugins::NTLMAuthentication::InstanceMethods
26
+ end
27
+ end
@@ -14,6 +14,7 @@ module HTTPX
14
14
  class SocksParser
15
15
  include Callbacks
16
16
 
17
+ def timeout: () -> Integer
17
18
  def close: () -> void
18
19
  def consume: (*untyped) -> void
19
20
  def empty: () -> bool
@@ -15,6 +15,7 @@ module HTTPX
15
15
  class SocksParser
16
16
  include Callbacks
17
17
 
18
+ def timeout: () -> Integer
18
19
  def close: () -> void
19
20
  def consume: (*untyped) -> void
20
21
  def empty: () -> bool
data/sig/utils.rbs ADDED
@@ -0,0 +1,7 @@
1
+ module HTTPX
2
+ module Utils
3
+ def self?.parse_retry_after: (String) -> Numeric
4
+
5
+ def self?.to_uri: (generic_uri uri) -> URI::Generic
6
+ end
7
+ 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.14.1
4
+ version: 0.15.0
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-05-27 00:00:00.000000000 Z
11
+ date: 2021-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2-next
@@ -64,6 +64,11 @@ extra_rdoc_files:
64
64
  - doc/release_notes/0_13_2.md
65
65
  - doc/release_notes/0_14_0.md
66
66
  - doc/release_notes/0_14_1.md
67
+ - doc/release_notes/0_14_2.md
68
+ - doc/release_notes/0_14_3.md
69
+ - doc/release_notes/0_14_4.md
70
+ - doc/release_notes/0_14_5.md
71
+ - doc/release_notes/0_15_0.md
67
72
  - doc/release_notes/0_1_0.md
68
73
  - doc/release_notes/0_2_0.md
69
74
  - doc/release_notes/0_2_1.md
@@ -107,6 +112,11 @@ files:
107
112
  - doc/release_notes/0_13_2.md
108
113
  - doc/release_notes/0_14_0.md
109
114
  - doc/release_notes/0_14_1.md
115
+ - doc/release_notes/0_14_2.md
116
+ - doc/release_notes/0_14_3.md
117
+ - doc/release_notes/0_14_4.md
118
+ - doc/release_notes/0_14_5.md
119
+ - doc/release_notes/0_15_0.md
110
120
  - doc/release_notes/0_1_0.md
111
121
  - doc/release_notes/0_2_0.md
112
122
  - doc/release_notes/0_2_1.md
@@ -180,6 +190,7 @@ files:
180
190
  - lib/httpx/plugins/multipart/encoder.rb
181
191
  - lib/httpx/plugins/multipart/mime_type_detector.rb
182
192
  - lib/httpx/plugins/multipart/part.rb
193
+ - lib/httpx/plugins/ntlm_authentication.rb
183
194
  - lib/httpx/plugins/persistent.rb
184
195
  - lib/httpx/plugins/proxy.rb
185
196
  - lib/httpx/plugins/proxy/http.rb
@@ -192,7 +203,9 @@ files:
192
203
  - lib/httpx/plugins/stream.rb
193
204
  - lib/httpx/plugins/upgrade.rb
194
205
  - lib/httpx/plugins/upgrade/h2.rb
206
+ - lib/httpx/pmatch_extensions.rb
195
207
  - lib/httpx/pool.rb
208
+ - lib/httpx/punycode.rb
196
209
  - lib/httpx/registry.rb
197
210
  - lib/httpx/request.rb
198
211
  - lib/httpx/resolver.rb
@@ -237,8 +250,10 @@ files:
237
250
  - sig/plugins/digest_authentication.rbs
238
251
  - sig/plugins/expect.rbs
239
252
  - sig/plugins/follow_redirects.rbs
253
+ - sig/plugins/grpc.rbs
240
254
  - sig/plugins/h2c.rbs
241
255
  - sig/plugins/multipart.rbs
256
+ - sig/plugins/ntlm_authentication.rbs
242
257
  - sig/plugins/persistent.rbs
243
258
  - sig/plugins/proxy.rbs
244
259
  - sig/plugins/proxy/http.rbs
@@ -266,6 +281,7 @@ files:
266
281
  - sig/transcoder/chunker.rbs
267
282
  - sig/transcoder/form.rbs
268
283
  - sig/transcoder/json.rbs
284
+ - sig/utils.rbs
269
285
  homepage: https://gitlab.com/honeyryderchuck/httpx
270
286
  licenses:
271
287
  - Apache 2.0