httpx 0.15.1 → 0.16.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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes/0_15_2.md +9 -0
  3. data/doc/release_notes/0_15_3.md +5 -0
  4. data/doc/release_notes/0_15_4.md +5 -0
  5. data/doc/release_notes/0_16_0.md +93 -0
  6. data/lib/httpx.rb +6 -3
  7. data/lib/httpx/adapters/faraday.rb +3 -11
  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.rb +2 -2
  12. data/lib/httpx/connection/http1.rb +3 -1
  13. data/lib/httpx/connection/http2.rb +1 -11
  14. data/lib/httpx/errors.rb +11 -11
  15. data/lib/httpx/io/ssl.rb +2 -2
  16. data/lib/httpx/io/tls.rb +1 -1
  17. data/lib/httpx/loggable.rb +1 -1
  18. data/lib/httpx/options.rb +81 -74
  19. data/lib/httpx/parser/http1.rb +1 -1
  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.rb +20 -7
  23. data/lib/httpx/plugins/cookies/cookie.rb +4 -3
  24. data/lib/httpx/plugins/cookies/jar.rb +24 -1
  25. data/lib/httpx/plugins/digest_authentication.rb +15 -11
  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.rb +73 -47
  29. data/lib/httpx/plugins/grpc/call.rb +4 -1
  30. data/lib/httpx/plugins/ntlm_authentication.rb +8 -6
  31. data/lib/httpx/plugins/proxy.rb +4 -6
  32. data/lib/httpx/plugins/proxy/socks4.rb +2 -1
  33. data/lib/httpx/plugins/proxy/socks5.rb +2 -1
  34. data/lib/httpx/plugins/proxy/ssh.rb +9 -9
  35. data/lib/httpx/plugins/retries.rb +25 -21
  36. data/lib/httpx/plugins/upgrade.rb +7 -6
  37. data/lib/httpx/registry.rb +1 -1
  38. data/lib/httpx/request.rb +4 -12
  39. data/lib/httpx/resolver/https.rb +0 -2
  40. data/lib/httpx/response.rb +45 -18
  41. data/lib/httpx/selector.rb +13 -12
  42. data/lib/httpx/session.rb +19 -8
  43. data/lib/httpx/session2.rb +21 -0
  44. data/lib/httpx/transcoder/body.rb +1 -1
  45. data/lib/httpx/transcoder/chunker.rb +2 -1
  46. data/lib/httpx/version.rb +1 -1
  47. data/sig/buffer.rbs +2 -0
  48. data/sig/chainable.rbs +24 -28
  49. data/sig/connection.rbs +20 -8
  50. data/sig/connection/http1.rbs +3 -3
  51. data/sig/connection/http2.rbs +1 -1
  52. data/sig/errors.rbs +35 -1
  53. data/sig/headers.rbs +5 -5
  54. data/sig/httpx.rbs +4 -1
  55. data/sig/loggable.rbs +3 -1
  56. data/sig/options.rbs +35 -32
  57. data/sig/plugins/authentication.rbs +1 -1
  58. data/sig/plugins/aws_sdk_authentication.rbs +5 -1
  59. data/sig/plugins/aws_sigv4.rbs +1 -2
  60. data/sig/plugins/basic_authentication.rbs +1 -1
  61. data/sig/plugins/compression.rbs +4 -6
  62. data/sig/plugins/cookies.rbs +4 -5
  63. data/sig/plugins/cookies/cookie.rbs +5 -7
  64. data/sig/plugins/cookies/jar.rbs +9 -10
  65. data/sig/plugins/digest_authentication.rbs +2 -3
  66. data/sig/plugins/expect.rbs +2 -4
  67. data/sig/plugins/follow_redirects.rbs +3 -5
  68. data/sig/plugins/grpc.rbs +4 -7
  69. data/sig/plugins/h2c.rbs +0 -2
  70. data/sig/plugins/multipart.rbs +2 -4
  71. data/sig/plugins/ntlm_authentication.rbs +2 -3
  72. data/sig/plugins/persistent.rbs +3 -8
  73. data/sig/plugins/proxy.rbs +7 -7
  74. data/sig/plugins/proxy/ssh.rbs +4 -4
  75. data/sig/plugins/push_promise.rbs +0 -2
  76. data/sig/plugins/retries.rbs +4 -8
  77. data/sig/plugins/stream.rbs +1 -1
  78. data/sig/plugins/upgrade.rbs +2 -3
  79. data/sig/pool.rbs +1 -2
  80. data/sig/registry.rbs +1 -1
  81. data/sig/request.rbs +2 -2
  82. data/sig/resolver.rbs +7 -0
  83. data/sig/resolver/native.rbs +9 -5
  84. data/sig/resolver/resolver_mixin.rbs +4 -5
  85. data/sig/resolver/system.rbs +2 -0
  86. data/sig/response.rbs +17 -11
  87. data/sig/selector.rbs +7 -6
  88. data/sig/session.rbs +19 -14
  89. data/sig/transcoder.rbs +11 -4
  90. data/sig/transcoder/body.rbs +6 -1
  91. data/sig/transcoder/chunker.rbs +8 -2
  92. data/sig/transcoder/form.rbs +2 -1
  93. data/sig/transcoder/json.rbs +1 -0
  94. data/sig/utils.rbs +2 -0
  95. metadata +12 -2
@@ -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
@@ -14,11 +14,11 @@ module HTTPX
14
14
  attr_reader response: response?
15
15
  attr_reader drain_error: StandardError?
16
16
 
17
- def initialize: (verb | String, uri, ?options?) -> untyped
17
+ def initialize: (verb | String, generic_uri, ?options?) -> untyped
18
18
 
19
19
  def interests: () -> (:r | :w)
20
20
 
21
- def merge_headers: (Headers | Hash) -> void
21
+ def merge_headers: (_Each[[headers_key, headers_value]]) -> void
22
22
 
23
23
  def scheme: () -> ("http" | "https")
24
24
 
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 }
@@ -1,9 +1,13 @@
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
+ DEFAULTS: Hash[Symbol, untyped]
9
+ DNS_PORT: Integer
10
+
7
11
  @options: Options
8
12
  @ns_index: Integer
9
13
  @resolver_options: Hash[Symbol, untyped]
@@ -15,7 +19,7 @@ module HTTPX
15
19
  @queries: Hash[String, Connection]
16
20
  @read_buffer: String
17
21
  @write_buffer: Buffer
18
- @state: :idle | :closed
22
+ @state: :idle | :open | :closed
19
23
 
20
24
  def closed?: () -> bool
21
25
 
@@ -35,6 +39,8 @@ module HTTPX
35
39
 
36
40
  def initialize: (options) -> untyped
37
41
 
42
+ def calculate_interests: () -> (:r | :w)
43
+
38
44
  def consume: () -> void
39
45
 
40
46
  def do_retry: () -> void
@@ -46,15 +52,13 @@ module HTTPX
46
52
 
47
53
  def parse: (String) -> void
48
54
 
49
- def resolve: (Connection, String hostname) -> void
50
- | (Connection) -> void
51
- | () -> void
55
+ def resolve: (?Connection connection, ?String hostname) -> void
52
56
 
53
57
  def build_socket: () -> void
54
58
 
55
59
  def transition: (Symbol nextstate) -> void
56
60
 
57
- def handle_error: (StandardError) -> void
61
+ def handle_error: (NativeResolveError | StandardError) -> void
58
62
  end
59
63
  end
60
64
  end
@@ -4,6 +4,8 @@ module HTTPX
4
4
  include Callbacks
5
5
  include Loggable
6
6
 
7
+ CHECK_IF_IP: Proc
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[StandardError] # ResolvError
7
+
6
8
  def closed?: () -> true
7
9
 
8
10
  def empty?: () -> true
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,50 +20,54 @@ 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[[headers_key, headers_value]]) -> void
24
26
  def bodyless?: () -> bool
25
27
  def content_type: () -> ContentType
26
28
  def complete?: () -> bool
27
29
 
28
30
  private
29
31
 
30
- def initialize: (Request, _ToS, String, headers?) -> untyped
32
+ def initialize: (Request request, String | Integer status, String version, headers?) -> untyped
31
33
  def no_data?: () -> bool
32
34
 
33
35
  class Body
34
- include _Writer
35
36
  include _Reader
36
37
  include _ToS
37
38
  include _ToStr
38
39
 
39
- @state: :idle | :memory | :buffer
40
+ @state: :idle | :memory | :buffer | :closed
40
41
  @threshold_size: Integer
41
42
  @window_size: Integer
42
43
 
44
+ def write:(String chunk) -> Integer?
45
+
43
46
  def each: () { (String) -> void } -> void
44
47
  | () -> Enumerable[String]
45
48
 
46
49
  def bytesize: () -> Numeric
47
50
  def empty?: () -> bool
48
- def copy_to: (_ToPath | _Writer destination) -> void
51
+ def copy_to: (String | File | _Writer destination) -> void
49
52
  def close: () -> void
50
53
  def closed?: () -> bool
51
54
 
52
55
  private
53
56
 
54
- def initialize: (Response, options) -> untyped
57
+ def initialize: (Response, Options) -> untyped
55
58
  def rewind: () -> void
56
59
  def transition: () -> void
57
60
  end
58
61
  end
59
62
 
60
63
  class ContentType
64
+ MIME_TYPE_RE: Regexp
65
+ CHARSET_RE: Regexp
66
+
61
67
  attr_reader mime_type: String?
62
68
  attr_reader charset: String?
63
69
 
64
- def self.parse: (_ToS) -> instance
70
+ def self.parse: (_ToS) -> ContentType
65
71
  def self.mime_type: (_ToS) -> String?
66
72
  def self.charset: (_ToS) -> String?
67
73
 
data/sig/selector.rbs CHANGED
@@ -1,19 +1,20 @@
1
1
  module HTTPX
2
2
  class Selector
3
- READABLE: :r | :rw
4
- WRITABLE: :w | :rw
3
+ READABLE: Array[Symbol]
4
+ WRITABLE: Array[Symbol]
5
+ @selectables: Array[_ToIO]
5
6
 
6
7
  def register: (_ToIO) -> void
7
8
  def deregister: (_ToIO) -> void
8
9
 
9
- def select: (Numeric?) { (_ToIO) -> void } -> void
10
-
10
+ def select: (Numeric? interval) { (_ToIO) -> void } -> void
11
+
11
12
  private
12
13
 
13
14
  def initialize: () -> untyped
14
15
 
15
- def select_many: (Numeric?) { (_ToIO) -> void } -> void
16
- def select_one: (Numeric?) { (_ToIO) -> void } -> void
16
+ def select_many: (Numeric? interval) { (_ToIO) -> void } -> void
17
+ def select_one: (Numeric? interval) { (_ToIO) -> void } -> void
17
18
  end
18
19
 
19
20
  type io_interests = :r | :w | :rw
data/sig/session.rbs CHANGED
@@ -3,21 +3,23 @@ module HTTPX
3
3
  include Loggable
4
4
  include Chainable
5
5
 
6
+ EMPTY_HASH: Hash[untyped, untyped]
7
+
6
8
  @options: Options
7
- @responses: Hash[Request, Response]
8
- @persistent: bool
9
+ @responses: Hash[Request, response]
10
+ @persistent: bool?
9
11
 
10
12
  def wrap: () { (instance) -> void } -> void
11
- | () -> void
13
+
12
14
  def close: (*untyped) -> void
13
15
 
14
16
  def request: (*Request, **untyped) -> (response | Array[response])
15
17
  | (*untyped, **untyped) -> (response | Array[response])
16
18
 
17
- def build_request: (String | verb, uri, ?options) -> Request
19
+ def build_request: (String | verb, generic_uri, ?options) -> Request
18
20
 
19
- def self.plugin: (Symbol | Module, ?options) { (Class) -> void } -> singleton(Session)
20
- | (Symbol | Module, ?options) -> singleton(Session)
21
+ # def self.plugin: (Symbol | Module, ?options) { (Class) -> void } -> singleton(Session)
22
+ # | (Symbol | Module, ?options) -> singleton(Session)
21
23
 
22
24
 
23
25
 
@@ -25,28 +27,31 @@ module HTTPX
25
27
 
26
28
  private
27
29
 
28
- def initialize: (?options?) { (instance) -> void } -> untyped
29
- | (?options?) -> untyped
30
+ def initialize: (?options) { (instance) -> void } -> untyped
31
+ | (?options) -> untyped
30
32
 
31
33
  def pool: -> Pool
32
34
  def on_response: (Request, response) -> void
33
35
  def on_promise: (untyped, untyped) -> void
34
- def fetch_response: (Request, *untyped) -> response?
36
+ def fetch_response: (Request request, untyped, untyped) -> response?
37
+
38
+ def find_connection: (Request, Array[Connection] connections, Options options) -> Connection
39
+
35
40
  def set_connection_callbacks: (Connection, Array[Connection], Options) -> void
36
41
 
37
- def build_altsvc_connection: (Connection, Array[Connection], URI, String, Hash[String, String], Options) -> Connection?
42
+ def build_altsvc_connection: (Connection, Array[Connection], URI::Generic, String, Hash[String, String], Options) -> Connection?
38
43
 
39
44
  def build_requests: (verb | string, uri, options) -> Array[Request]
40
45
  | (Array[[verb | string, uri, options]], options) -> Array[Request]
41
46
  | (Array[[verb | string, uri]], options) -> Array[Request]
42
- | (verb | string, _Each[[uri, options], void], Options) -> Array[Request]
43
- | (verb | string, _Each[uri, void], options) -> Array[Request]
47
+ | (verb | string, _Each[[uri, options]], Options) -> Array[Request]
48
+ | (verb | string, _Each[uri], options) -> Array[Request]
44
49
 
45
- def build_connection: (URI, Options) -> Connection
50
+ def build_connection: (URI::Generic, Options) -> Connection
46
51
 
47
52
  def send_requests: (*Request, options) -> Array[response]
48
53
 
49
- def _send_requests: (Array[Request], options) -> Array[Connection]
54
+ def _send_requests: (Array[Request], Options) -> Array[Connection]
50
55
 
51
56
  def receive_requests: (Array[Request], Array[Connection], options) -> Array[response]
52
57
  end
data/sig/transcoder.rbs CHANGED
@@ -1,11 +1,18 @@
1
1
  module HTTPX
2
- type bodyIO = _Reader | _Each[String, untyped] | _ToS
2
+ type bodyIO = _Reader | _Each[[String, untyped]] | _ToS
3
3
 
4
4
  module Transcoder
5
- extend HTTPX::Registry[String, Class]
5
+ def self?.registry: (String tag) -> _Encode
6
+ | () -> Hash[String, _Encode]
6
7
 
7
- def self.normalize_keys: (string | Symbol, top, ?Proc?) { (string, top) -> void } -> void
8
- | (string | Symbol, top, ?Proc?) { (string) -> void } -> void
8
+ def self?.register: (String tag, _Encode handler) -> void
9
+
10
+ def self?.normalize_keys: (_ToS key, _ToAry[untyped] | _ToHash[_ToS, untyped] | untyped value) { (String, ?untyped) -> void } -> void
11
+ | (_ToS key, untyped value, Proc? cond) { (String, untyped) -> void } -> void
12
+
13
+ interface _Encode
14
+ def encode: (untyped payload) -> (_Encoder | _Each[String])
15
+ end
9
16
 
10
17
  interface _Encoder
11
18
  def bytesize: () -> Numeric
@@ -1,7 +1,12 @@
1
1
  module HTTPX
2
2
  module Transcoder
3
3
  module Body
4
+ class Error < HTTPX::Error
5
+ end
6
+
4
7
  class Encoder
8
+ extend Forwardable
9
+
5
10
  include _Encoder
6
11
  include _ToS
7
12
 
@@ -11,7 +16,7 @@ module HTTPX
11
16
 
12
17
  private
13
18
 
14
- def initialize: (untyped body ) -> untyped
19
+ def initialize: (untyped body) -> untyped
15
20
  end
16
21
 
17
22
  def self?.encode: (bodyIO body) -> Encoder
@@ -1,6 +1,11 @@
1
1
  module HTTPX::Transcoder
2
2
  module Chunker
3
- def self?.encode: (_Encoder chunks) -> Encoder
3
+ CRLF: String
4
+
5
+ class Error < HTTPX::Error
6
+ end
7
+
8
+ def self?.encode: (_Each[String] chunks) -> Encoder
4
9
 
5
10
  class Encoder
6
11
  @raw: _Each[String]
@@ -9,10 +14,11 @@ module HTTPX::Transcoder
9
14
 
10
15
  private
11
16
 
12
- def initialize: (_Encoder chunks) -> untyped
17
+ def initialize: (_Each[String] chunks) -> untyped
13
18
  end
14
19
 
15
20
  class Decoder
21
+ extend Forwardable
16
22
  include _ToS
17
23
  include _Each[String]
18
24
 
@@ -3,12 +3,13 @@ module HTTPX::Transcoder
3
3
 
4
4
  type form_nested_value = form_value | _ToAry[form_value] | _ToHash[string, form_value]
5
5
 
6
- type urlencoded_input = Enumerable[[string, form_nested_value], untyped]
6
+ type urlencoded_input = Enumerable[[_ToS, form_nested_value]]
7
7
 
8
8
  module Form
9
9
  def self?.encode: (urlencoded_input form) -> Encoder
10
10
 
11
11
  class Encoder
12
+ extend Forwardable
12
13
  include _Encoder
13
14
  include _ToS
14
15
 
@@ -3,6 +3,7 @@ module HTTPX::Transcoder
3
3
  def self?.encode: (_ToJson json) -> Encoder
4
4
 
5
5
  class Encoder
6
+ extend Forwardable
6
7
  include _Encoder
7
8
  include _ToS
8
9
 
data/sig/utils.rbs CHANGED
@@ -1,5 +1,7 @@
1
1
  module HTTPX
2
2
  module Utils
3
+ URIParser: URI::RFC2396_Parser
4
+
3
5
  def self?.parse_retry_after: (String) -> Numeric
4
6
 
5
7
  def self?.to_uri: (generic_uri uri) -> URI::Generic