httpx 0.15.3 → 0.17.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 (109) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes/0_15_4.md +5 -0
  3. data/doc/release_notes/0_16_0.md +93 -0
  4. data/doc/release_notes/0_16_1.md +5 -0
  5. data/doc/release_notes/0_17_0.md +49 -0
  6. data/lib/httpx/adapters/faraday.rb +3 -11
  7. data/lib/httpx/adapters/webmock.rb +2 -2
  8. data/lib/httpx/buffer.rb +1 -1
  9. data/lib/httpx/callbacks.rb +1 -1
  10. data/lib/httpx/chainable.rb +15 -8
  11. data/lib/httpx/connection/http1.rb +18 -10
  12. data/lib/httpx/connection/http2.rb +14 -21
  13. data/lib/httpx/connection.rb +6 -7
  14. data/lib/httpx/errors.rb +11 -11
  15. data/lib/httpx/headers.rb +1 -1
  16. data/lib/httpx/io/ssl.rb +2 -2
  17. data/lib/httpx/io/tls.rb +1 -1
  18. data/lib/httpx/options.rb +108 -81
  19. data/lib/httpx/parser/http1.rb +11 -7
  20. data/lib/httpx/plugins/aws_sigv4.rb +10 -9
  21. data/lib/httpx/plugins/compression.rb +12 -11
  22. data/lib/httpx/plugins/cookies/cookie.rb +4 -2
  23. data/lib/httpx/plugins/cookies/jar.rb +20 -1
  24. data/lib/httpx/plugins/cookies.rb +20 -7
  25. data/lib/httpx/plugins/digest_authentication.rb +19 -15
  26. data/lib/httpx/plugins/expect.rb +19 -15
  27. data/lib/httpx/plugins/follow_redirects.rb +9 -9
  28. data/lib/httpx/plugins/grpc/call.rb +4 -1
  29. data/lib/httpx/plugins/grpc.rb +73 -47
  30. data/lib/httpx/plugins/h2c.rb +7 -3
  31. data/lib/httpx/plugins/multipart/decoder.rb +187 -0
  32. data/lib/httpx/plugins/multipart/mime_type_detector.rb +3 -3
  33. data/lib/httpx/plugins/multipart/part.rb +2 -2
  34. data/lib/httpx/plugins/multipart.rb +14 -0
  35. data/lib/httpx/plugins/ntlm_authentication.rb +12 -10
  36. data/lib/httpx/plugins/proxy/socks4.rb +2 -1
  37. data/lib/httpx/plugins/proxy/socks5.rb +2 -1
  38. data/lib/httpx/plugins/proxy/ssh.rb +20 -13
  39. data/lib/httpx/plugins/proxy.rb +10 -10
  40. data/lib/httpx/plugins/retries.rb +25 -21
  41. data/lib/httpx/plugins/stream.rb +2 -3
  42. data/lib/httpx/plugins/upgrade.rb +7 -6
  43. data/lib/httpx/registry.rb +2 -2
  44. data/lib/httpx/request.rb +10 -19
  45. data/lib/httpx/resolver/https.rb +0 -2
  46. data/lib/httpx/resolver/native.rb +15 -3
  47. data/lib/httpx/resolver/resolver_mixin.rb +2 -1
  48. data/lib/httpx/response.rb +72 -38
  49. data/lib/httpx/selector.rb +6 -7
  50. data/lib/httpx/session.rb +34 -21
  51. data/lib/httpx/session2.rb +23 -0
  52. data/lib/httpx/transcoder/body.rb +1 -1
  53. data/lib/httpx/transcoder/chunker.rb +2 -1
  54. data/lib/httpx/transcoder/form.rb +20 -0
  55. data/lib/httpx/transcoder/json.rb +12 -0
  56. data/lib/httpx/transcoder.rb +62 -1
  57. data/lib/httpx/utils.rb +2 -2
  58. data/lib/httpx/version.rb +1 -1
  59. data/lib/httpx.rb +6 -3
  60. data/sig/buffer.rbs +3 -1
  61. data/sig/chainable.rbs +30 -29
  62. data/sig/connection/http1.rbs +11 -5
  63. data/sig/connection/http2.rbs +16 -5
  64. data/sig/connection.rbs +23 -11
  65. data/sig/errors.rbs +35 -1
  66. data/sig/headers.rbs +20 -19
  67. data/sig/httpx.rbs +4 -1
  68. data/sig/loggable.rbs +3 -1
  69. data/sig/options.rbs +45 -34
  70. data/sig/parser/http1.rbs +3 -3
  71. data/sig/plugins/authentication.rbs +1 -1
  72. data/sig/plugins/aws_sdk_authentication.rbs +5 -1
  73. data/sig/plugins/aws_sigv4.rbs +13 -5
  74. data/sig/plugins/basic_authentication.rbs +1 -1
  75. data/sig/plugins/compression.rbs +4 -6
  76. data/sig/plugins/cookies/cookie.rbs +5 -7
  77. data/sig/plugins/cookies/jar.rbs +9 -10
  78. data/sig/plugins/cookies.rbs +4 -5
  79. data/sig/plugins/digest_authentication.rbs +2 -3
  80. data/sig/plugins/expect.rbs +2 -4
  81. data/sig/plugins/follow_redirects.rbs +3 -5
  82. data/sig/plugins/grpc.rbs +4 -7
  83. data/sig/plugins/h2c.rbs +0 -2
  84. data/sig/plugins/multipart.rbs +64 -10
  85. data/sig/plugins/ntlm_authentication.rbs +2 -3
  86. data/sig/plugins/persistent.rbs +3 -8
  87. data/sig/plugins/proxy/ssh.rbs +4 -4
  88. data/sig/plugins/proxy.rbs +13 -13
  89. data/sig/plugins/push_promise.rbs +0 -2
  90. data/sig/plugins/retries.rbs +4 -8
  91. data/sig/plugins/stream.rbs +1 -1
  92. data/sig/plugins/upgrade.rbs +2 -3
  93. data/sig/pool.rbs +1 -2
  94. data/sig/registry.rbs +1 -1
  95. data/sig/request.rbs +11 -8
  96. data/sig/resolver/native.rbs +12 -6
  97. data/sig/resolver/resolver_mixin.rbs +4 -5
  98. data/sig/resolver/system.rbs +2 -0
  99. data/sig/resolver.rbs +7 -0
  100. data/sig/response.rbs +24 -12
  101. data/sig/selector.rbs +11 -9
  102. data/sig/session.rbs +22 -23
  103. data/sig/transcoder/body.rbs +6 -1
  104. data/sig/transcoder/chunker.rbs +8 -2
  105. data/sig/transcoder/form.rbs +3 -1
  106. data/sig/transcoder/json.rbs +2 -0
  107. data/sig/transcoder.rbs +13 -5
  108. data/sig/utils.rbs +2 -0
  109. metadata +12 -2
@@ -4,9 +4,8 @@ module HTTPX
4
4
 
5
5
  interface _NTLMOptions
6
6
  def ntlm: () -> NTLMParams?
7
- def ntlm=: (NTLMParams) -> NTLMParams
8
7
  end
9
-
8
+
10
9
  def self.extra_options: (Options) -> (Options & _NTLMOptions)
11
10
 
12
11
  def self.load_dependencies: (*untyped) -> void
@@ -22,6 +21,6 @@ module HTTPX
22
21
  end
23
22
  end
24
23
 
25
- type sessionNTLMAuthentication = Plugins::sessionAuthentication & Plugins::NTLMAuthentication::InstanceMethods
24
+ type sessionNTLMAuthentication = sessionAuthentication & NTLMAuthentication::InstanceMethods
26
25
  end
27
26
  end
@@ -2,15 +2,10 @@ module HTTPX
2
2
  module Plugins
3
3
  module Persistent
4
4
  def self.load_dependencies: (singleton(Session)) -> void
5
-
6
- interface _PersistentOptions
7
- def persistent: () -> bool?
8
- def persistent=: (bool) -> bool
9
- end
10
-
11
- def self.extra_options: (Options) -> (Options & _PersistentOptions)
5
+
6
+ def self.extra_options: (Options) -> (Options)
12
7
  end
13
-
8
+
14
9
  type sessionPersistent = sessionFollowRedirects
15
10
  end
16
11
  end
@@ -3,16 +3,16 @@ module HTTPX
3
3
  module Proxy
4
4
  module SSH
5
5
  def self.load_dependencies: (singleton(Session)) -> void
6
-
7
- module InstancenMethods
6
+
7
+ module InstanceMethods
8
8
  private
9
9
 
10
- def build_gateway_socket: (int, URI::HTTPS | URI::HTTPS, Options) -> IO
10
+ def build_gateway_socket: (int, URI::HTTP | URI::HTTPS, Options) -> _ToIO
11
11
  end
12
12
  end
13
13
  end
14
14
 
15
15
 
16
- type sessionSSHProxy = Plugins::Proxy::InstanceMethods & Plugins::Proxy::SSH::InstanceMethods
16
+ type sessionSSHProxy = Proxy::InstanceMethods & Proxy::SSH::InstanceMethods
17
17
  end
18
18
  end
@@ -1,5 +1,6 @@
1
1
  module HTTPX
2
- HTTPProxyError: singleton(Error)
2
+ class HTTPProxyError < Error
3
+ end
3
4
 
4
5
  module Plugins
5
6
  module Proxy
@@ -8,8 +9,8 @@ module HTTPX
8
9
 
9
10
  class Parameters
10
11
  attr_reader uri: URI::Generic
11
- attr_reader username: string?
12
- attr_reader password: string?
12
+ attr_reader username: String?
13
+ attr_reader password: String?
13
14
 
14
15
  def authenticated?: () -> boolish
15
16
  def token_authentication: () -> String?
@@ -18,29 +19,28 @@ module HTTPX
18
19
 
19
20
  private
20
21
 
21
- def initialize: (uri: generic_uri, ?username: string, ?password: string) -> untyped
22
+ def initialize: (uri: generic_uri, ?username: String, ?password: String) -> untyped
22
23
  end
23
24
 
24
25
  def self.configure: (singleton(Session)) -> void
25
-
26
- type proxyParam = Parameters | Hash
27
-
26
+
27
+ type proxyParam = Parameters | Hash[Symbol, untyped]
28
+
28
29
  interface _ProxyOptions
29
30
  def proxy: () -> proxyParam?
30
- def proxy=: (Parameters | _ToHash) -> proxyParam
31
31
  end
32
-
32
+
33
33
  def self.extra_options: (Options) -> (Options & _ProxyOptions)
34
34
 
35
35
  module InstanceMethods
36
36
  private
37
37
 
38
- def proxy_uris: (uri, Options & _ProxyOptions) -> { uri: (URI | string), username: string, password: string }
39
- | (uri, Options & _ProxyOptions) -> { uri: (URI | string) }
40
- | (uri, Options & _ProxyOptions) -> nil
38
+ def proxy_uris: (generic_uri, Options & _ProxyOptions) -> { uri: generic_uri, username: String, password: String }
39
+ | (generic_uri, Options & _ProxyOptions) -> { uri: generic_uri }
40
+ | (generic_uri, Options & _ProxyOptions) -> nil
41
41
  end
42
42
  end
43
43
 
44
- type sessionProxy = Session & Plugins::Proxy::InstanceMethods
44
+ type sessionProxy = Session & Proxy::InstanceMethods
45
45
  end
46
46
  end
@@ -1,8 +1,6 @@
1
1
  module HTTPX
2
2
  module Plugins
3
3
  module PushPromise
4
- def self.extra_options: (Options) -> Options
5
-
6
4
  module ResponseMethods
7
5
  def pushed?: () -> boolish
8
6
  def mark_as_pushed!: () -> void
@@ -4,25 +4,21 @@ module HTTPX
4
4
  MAX_RETRIES: Integer
5
5
  IDEMPOTENT_METHODS: Array[verb]
6
6
  RETRYABLE_ERRORS: Array[singleton(StandardError)]
7
-
7
+
8
8
  interface _RetryCallback
9
9
  def call: (response) -> bool?
10
10
  end
11
11
 
12
12
  interface _RetriesOptions
13
13
  def retry_after: () -> Numeric?
14
- def retry_after=: (Numeric) -> Numeric
15
14
 
16
15
  def max_retries: () -> Integer?
17
- def max_retries=: (int) -> Integer
18
16
 
19
- def retry_change_requests: () -> bool?
20
- def retry_change_requests=: (bool) -> bool
17
+ def retry_change_requests: () -> boolish
21
18
 
22
19
  def retry_on: () -> _RetryCallback?
23
- def retry_on=: (_RetryCallback) -> _RetryCallback
24
20
  end
25
-
21
+
26
22
  def self.extra_options: (Options) -> (Options & _RetriesOptions)
27
23
 
28
24
  module InstanceMethods
@@ -39,6 +35,6 @@ module HTTPX
39
35
  end
40
36
  end
41
37
 
42
- type sessionRetries = Session & Plugins::Retries::InstanceMethods
38
+ type sessionRetries = Session & Retries::InstanceMethods
43
39
  end
44
40
  end
@@ -35,6 +35,6 @@ module HTTPX
35
35
 
36
36
  end
37
37
 
38
- type sessionStream = Session & Plugins::Stream::InstanceMethods
38
+ type sessionStream = Session & Stream::InstanceMethods
39
39
  end
40
40
  end
@@ -7,9 +7,8 @@ module HTTPX
7
7
 
8
8
  interface _UpgradeOptions
9
9
  def upgrade_handlers: () -> handlers_registry?
10
- def upgrade_handlers=: (handlers_registry) -> handlers_registry
11
10
  end
12
-
11
+
13
12
  def self.extra_options: (Options) -> (Options & _UpgradeOptions)
14
13
 
15
14
  module ConnectionMethods
@@ -18,6 +17,6 @@ module HTTPX
18
17
 
19
18
  def hijack_io: () -> void
20
19
  end
21
- end
20
+ end
22
21
  end
23
22
  end
data/sig/pool.rbs CHANGED
@@ -4,8 +4,7 @@ module HTTPX
4
4
 
5
5
  def next_tick: () -> void
6
6
 
7
- def close: (Array[Connection]) -> void
8
- | () -> void
7
+ def close: (*Array[Connection]) -> void
9
8
 
10
9
  def init_connection: (Connection, Options) -> void
11
10
 
data/sig/registry.rbs CHANGED
@@ -2,7 +2,7 @@ module HTTPX::Registry[T, V]
2
2
  # type registrable = Symbol | String | Class
3
3
 
4
4
  def self.registry: (T tag) -> Class
5
- | () -> Hash[K, V]
5
+ | () -> Hash[T, V]
6
6
  def self.register: (T tag, V handler) -> void
7
7
 
8
8
  def registry: (?T tag) -> V
data/sig/request.rbs CHANGED
@@ -1,12 +1,13 @@
1
1
  module HTTPX
2
2
  class Request
3
+ extend Forwardable
3
4
  include Callbacks
4
5
 
5
- METHODS: Array[verb]
6
+ METHODS: Array[Symbol]
6
7
  USER_AGENT: String
7
8
 
8
- attr_reader verb: verb
9
- attr_reader uri: URI::HTTP | URI::HTTPS
9
+ attr_reader verb: Symbol
10
+ attr_reader uri: URI::Generic
10
11
  attr_reader headers: Headers
11
12
  attr_reader body: Body
12
13
  attr_reader state: Symbol
@@ -14,13 +15,13 @@ module HTTPX
14
15
  attr_reader response: response?
15
16
  attr_reader drain_error: StandardError?
16
17
 
17
- def initialize: (verb | String, uri, ?options?) -> untyped
18
+ def initialize: (Symbol | String, generic_uri, ?options) -> untyped
18
19
 
19
20
  def interests: () -> (:r | :w)
20
21
 
21
- def merge_headers: (Headers | Hash) -> void
22
+ def merge_headers: (_Each[[String, headers_value]]) -> void
22
23
 
23
- def scheme: () -> ("http" | "https")
24
+ def scheme: () -> String
24
25
 
25
26
  def response=: (response) -> void
26
27
 
@@ -49,6 +50,7 @@ module HTTPX
49
50
  def each: () { (String) -> void } -> void
50
51
  | () -> Enumerable[String]
51
52
 
53
+ def rewind: () -> void
52
54
  def empty?: () -> bool
53
55
  def bytesize: () -> Numeric
54
56
  def stream: (Transcoder::_Encoder) -> bodyIO
@@ -59,8 +61,9 @@ module HTTPX
59
61
  end
60
62
 
61
63
  class ProcIO
62
- include _Writer
63
- def initialize: (^(_ToS) -> void) -> untyped
64
+ def initialize: (^(String) -> void) -> untyped
65
+
66
+ def write: (String data) -> Integer
64
67
  end
65
68
  end
66
69
  end
@@ -1,9 +1,15 @@
1
1
  module HTTPX
2
2
  module Resolver
3
3
  class Native
4
+ extend Forwardable
4
5
  include ResolverMixin
5
6
  include _ToIO
6
7
 
8
+ type state = :idle | :open | :closed
9
+
10
+ DEFAULTS: Hash[Symbol, untyped]
11
+ DNS_PORT: Integer
12
+
7
13
  @options: Options
8
14
  @ns_index: Integer
9
15
  @resolver_options: Hash[Symbol, untyped]
@@ -15,7 +21,7 @@ module HTTPX
15
21
  @queries: Hash[String, Connection]
16
22
  @read_buffer: String
17
23
  @write_buffer: Buffer
18
- @state: :idle | :closed
24
+ @state: state
19
25
 
20
26
  def closed?: () -> bool
21
27
 
@@ -35,6 +41,8 @@ module HTTPX
35
41
 
36
42
  def initialize: (options) -> untyped
37
43
 
44
+ def calculate_interests: () -> (:r | :w)
45
+
38
46
  def consume: () -> void
39
47
 
40
48
  def do_retry: () -> void
@@ -46,15 +54,13 @@ module HTTPX
46
54
 
47
55
  def parse: (String) -> void
48
56
 
49
- def resolve: (Connection, String hostname) -> void
50
- | (Connection) -> void
51
- | () -> void
57
+ def resolve: (?Connection connection, ?String hostname) -> void
52
58
 
53
59
  def build_socket: () -> void
54
60
 
55
- def transition: (Symbol nextstate) -> void
61
+ def transition: (state nextstate) -> void
56
62
 
57
- def handle_error: (StandardError) -> void
63
+ def handle_error: (NativeResolveError | StandardError) -> void
58
64
  end
59
65
  end
60
66
  end
@@ -4,6 +4,8 @@ module HTTPX
4
4
  include Callbacks
5
5
  include Loggable
6
6
 
7
+ CHECK_IF_IP: ^(String name) -> bool
8
+
7
9
  def uncache: (Connection) -> void
8
10
 
9
11
  private
@@ -16,12 +18,9 @@ module HTTPX
16
18
 
17
19
  def system_resolve: (String hostname) -> Array[ipaddr]?
18
20
 
19
- def emit_resolve_error: (Connection, String hostname, StandardError) -> void
20
- | (Connection, String hostname) -> void
21
- | (Connection) -> void
21
+ def emit_resolve_error: (Connection, ?String hostname, ?StandardError) -> void
22
22
 
23
- def resolve_error: (String hostname, StandardError?) -> void
24
- | (String hostname) -> void
23
+ def resolve_error: (String hostname, ?StandardError?) -> void
25
24
  end
26
25
  end
27
26
  end
@@ -3,6 +3,8 @@ module HTTPX
3
3
  class System
4
4
  include ResolverMixin
5
5
 
6
+ RESOLV_ERRORS: Array[singleton(StandardError)] # ResolvError
7
+
6
8
  def closed?: () -> true
7
9
 
8
10
  def empty?: () -> true
data/sig/resolver.rbs CHANGED
@@ -4,6 +4,13 @@ module HTTPX
4
4
  type resolver = Resolver::System | Resolver::Native | Resolver::HTTPS
5
5
 
6
6
  module Resolver
7
+ RESOLVE_TIMEOUT: Integer | Float
8
+
9
+ def self.registry: (Symbol tag) -> Class
10
+ | () -> Hash[Symbol, Class]
11
+
12
+ def self.register: (Symbol tag, Class handler) -> void
13
+
7
14
  type dns_resource = singleton(Resolv::DNS::Resource)
8
15
 
9
16
  type dns_result = { "name" => String, "TTL" => Numeric, "alias" => String }
data/sig/response.rbs CHANGED
@@ -1,15 +1,17 @@
1
1
  module HTTPX
2
2
  interface _Response
3
- def raise_for_status: () -> void
3
+ def raise_for_status: () -> void
4
4
  end
5
5
 
6
6
  class Response
7
+ extend Forwardable
8
+
7
9
  include _Response
8
10
  include _ToS
9
11
  include _Reader
10
12
 
11
- attr_reader status: int
12
- attr_reader headers: headers
13
+ attr_reader status: Integer
14
+ attr_reader headers: Headers
13
15
  attr_reader body: Body
14
16
  attr_reader version: String
15
17
 
@@ -18,56 +20,66 @@ module HTTPX
18
20
 
19
21
  def copy_to: (_ToPath | _Writer destination) -> void
20
22
  def close: () -> void
21
- def uri: () -> uri
23
+ def uri: () -> URI::Generic
22
24
 
23
- def merge_headers: (headers) -> void
25
+ def merge_headers: (_Each[[String, headers_value]]) -> void
24
26
  def bodyless?: () -> bool
25
27
  def content_type: () -> ContentType
26
28
  def complete?: () -> bool
27
29
 
30
+ def json: (?json_options opts) -> untyped
31
+
32
+ def form: () -> Hash[String, untyped]
33
+
28
34
  private
29
35
 
30
- def initialize: (Request, _ToS, String, headers?) -> untyped
36
+ def initialize: (Request request, String | Integer status, String version, headers?) -> untyped
31
37
  def no_data?: () -> bool
32
38
 
39
+ def decode:(String format, ?untyped options) -> untyped
40
+
33
41
  class Body
34
- include _Writer
35
42
  include _Reader
36
43
  include _ToS
37
44
  include _ToStr
38
45
 
39
- @state: :idle | :memory | :buffer
46
+ @state: :idle | :memory | :buffer | :closed
40
47
  @threshold_size: Integer
41
48
  @window_size: Integer
42
49
 
50
+ def write:(String chunk) -> Integer?
51
+
43
52
  def each: () { (String) -> void } -> void
44
53
  | () -> Enumerable[String]
45
54
 
46
55
  def bytesize: () -> Numeric
47
56
  def empty?: () -> bool
48
- def copy_to: (_ToPath | _Writer destination) -> void
57
+ def copy_to: (String | File | _Writer destination) -> void
49
58
  def close: () -> void
50
59
  def closed?: () -> bool
51
60
 
52
61
  private
53
62
 
54
- def initialize: (Response, options) -> untyped
63
+ def initialize: (Response, Options) -> untyped
55
64
  def rewind: () -> void
56
65
  def transition: () -> void
57
66
  end
58
67
  end
59
68
 
60
69
  class ContentType
70
+ MIME_TYPE_RE: Regexp
71
+ CHARSET_RE: Regexp
72
+
61
73
  attr_reader mime_type: String?
62
74
  attr_reader charset: String?
63
75
 
64
- def self.parse: (_ToS) -> instance
76
+ def self.parse: (_ToS) -> ContentType
65
77
  def self.mime_type: (_ToS) -> String?
66
78
  def self.charset: (_ToS) -> String?
67
79
 
68
80
  private
69
81
 
70
- def initialize: (String?, String?) -> untyped
82
+ def initialize: (String? header_value) -> void
71
83
  end
72
84
 
73
85
  class ErrorResponse