httpx 0.20.0 → 1.3.1

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 (250) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +0 -48
  3. data/README.md +54 -45
  4. data/doc/release_notes/0_10_0.md +2 -2
  5. data/doc/release_notes/0_11_0.md +3 -5
  6. data/doc/release_notes/0_12_0.md +5 -5
  7. data/doc/release_notes/0_13_0.md +5 -5
  8. data/doc/release_notes/0_14_0.md +2 -2
  9. data/doc/release_notes/0_16_0.md +3 -3
  10. data/doc/release_notes/0_17_0.md +1 -1
  11. data/doc/release_notes/0_18_0.md +4 -4
  12. data/doc/release_notes/0_18_2.md +1 -1
  13. data/doc/release_notes/0_19_0.md +1 -1
  14. data/doc/release_notes/0_19_8.md +1 -1
  15. data/doc/release_notes/0_20_0.md +2 -2
  16. data/doc/release_notes/0_20_1.md +5 -0
  17. data/doc/release_notes/0_20_2.md +7 -0
  18. data/doc/release_notes/0_20_3.md +6 -0
  19. data/doc/release_notes/0_20_4.md +17 -0
  20. data/doc/release_notes/0_20_5.md +3 -0
  21. data/doc/release_notes/0_21_0.md +96 -0
  22. data/doc/release_notes/0_21_1.md +12 -0
  23. data/doc/release_notes/0_22_0.md +13 -0
  24. data/doc/release_notes/0_22_1.md +11 -0
  25. data/doc/release_notes/0_22_2.md +5 -0
  26. data/doc/release_notes/0_22_3.md +55 -0
  27. data/doc/release_notes/0_22_4.md +6 -0
  28. data/doc/release_notes/0_22_5.md +6 -0
  29. data/doc/release_notes/0_23_0.md +42 -0
  30. data/doc/release_notes/0_23_1.md +5 -0
  31. data/doc/release_notes/0_23_2.md +5 -0
  32. data/doc/release_notes/0_23_3.md +6 -0
  33. data/doc/release_notes/0_23_4.md +5 -0
  34. data/doc/release_notes/0_24_0.md +48 -0
  35. data/doc/release_notes/0_24_1.md +12 -0
  36. data/doc/release_notes/0_24_2.md +12 -0
  37. data/doc/release_notes/0_24_3.md +12 -0
  38. data/doc/release_notes/0_24_4.md +18 -0
  39. data/doc/release_notes/0_24_5.md +6 -0
  40. data/doc/release_notes/0_24_6.md +5 -0
  41. data/doc/release_notes/0_24_7.md +10 -0
  42. data/doc/release_notes/1_0_0.md +60 -0
  43. data/doc/release_notes/1_0_1.md +5 -0
  44. data/doc/release_notes/1_0_2.md +7 -0
  45. data/doc/release_notes/1_1_0.md +32 -0
  46. data/doc/release_notes/1_1_1.md +17 -0
  47. data/doc/release_notes/1_1_2.md +12 -0
  48. data/doc/release_notes/1_1_3.md +18 -0
  49. data/doc/release_notes/1_1_4.md +6 -0
  50. data/doc/release_notes/1_1_5.md +12 -0
  51. data/doc/release_notes/1_2_0.md +49 -0
  52. data/doc/release_notes/1_2_1.md +6 -0
  53. data/doc/release_notes/1_2_2.md +10 -0
  54. data/doc/release_notes/1_2_3.md +16 -0
  55. data/doc/release_notes/1_2_4.md +8 -0
  56. data/doc/release_notes/1_2_5.md +7 -0
  57. data/doc/release_notes/1_2_6.md +13 -0
  58. data/doc/release_notes/1_3_0.md +18 -0
  59. data/doc/release_notes/1_3_1.md +17 -0
  60. data/lib/httpx/adapters/datadog.rb +215 -122
  61. data/lib/httpx/adapters/faraday.rb +145 -107
  62. data/lib/httpx/adapters/sentry.rb +26 -7
  63. data/lib/httpx/adapters/webmock.rb +34 -18
  64. data/lib/httpx/altsvc.rb +63 -26
  65. data/lib/httpx/base64.rb +27 -0
  66. data/lib/httpx/buffer.rb +12 -0
  67. data/lib/httpx/callbacks.rb +5 -3
  68. data/lib/httpx/chainable.rb +54 -39
  69. data/lib/httpx/connection/http1.rb +75 -44
  70. data/lib/httpx/connection/http2.rb +31 -38
  71. data/lib/httpx/connection.rb +287 -117
  72. data/lib/httpx/domain_name.rb +10 -13
  73. data/lib/httpx/errors.rb +52 -2
  74. data/lib/httpx/extensions.rb +24 -131
  75. data/lib/httpx/io/ssl.rb +83 -77
  76. data/lib/httpx/io/tcp.rb +48 -71
  77. data/lib/httpx/io/udp.rb +18 -52
  78. data/lib/httpx/io/unix.rb +10 -15
  79. data/lib/httpx/io.rb +3 -9
  80. data/lib/httpx/loggable.rb +4 -19
  81. data/lib/httpx/options.rb +176 -118
  82. data/lib/httpx/parser/http1.rb +4 -0
  83. data/lib/httpx/plugins/{authentication → auth}/basic.rb +1 -5
  84. data/lib/httpx/plugins/{authentication → auth}/digest.rb +14 -14
  85. data/lib/httpx/plugins/{authentication → auth}/ntlm.rb +1 -3
  86. data/lib/httpx/plugins/{authentication → auth}/socks5.rb +0 -2
  87. data/lib/httpx/plugins/auth.rb +25 -0
  88. data/lib/httpx/plugins/aws_sdk_authentication.rb +4 -3
  89. data/lib/httpx/plugins/aws_sigv4.rb +12 -9
  90. data/lib/httpx/plugins/basic_auth.rb +29 -0
  91. data/lib/httpx/plugins/brotli.rb +50 -0
  92. data/lib/httpx/plugins/callbacks.rb +91 -0
  93. data/lib/httpx/plugins/circuit_breaker/circuit.rb +100 -0
  94. data/lib/httpx/plugins/circuit_breaker/circuit_store.rb +53 -0
  95. data/lib/httpx/plugins/circuit_breaker.rb +148 -0
  96. data/lib/httpx/plugins/cookies/set_cookie_parser.rb +0 -2
  97. data/lib/httpx/plugins/cookies.rb +30 -17
  98. data/lib/httpx/plugins/{digest_authentication.rb → digest_auth.rb} +14 -12
  99. data/lib/httpx/plugins/expect.rb +21 -14
  100. data/lib/httpx/plugins/follow_redirects.rb +140 -41
  101. data/lib/httpx/plugins/grpc/call.rb +2 -3
  102. data/lib/httpx/plugins/grpc/grpc_encoding.rb +88 -0
  103. data/lib/httpx/plugins/grpc/message.rb +7 -37
  104. data/lib/httpx/plugins/grpc.rb +36 -29
  105. data/lib/httpx/plugins/h2c.rb +26 -19
  106. data/lib/httpx/plugins/internal_telemetry.rb +16 -0
  107. data/lib/httpx/plugins/{ntlm_authentication.rb → ntlm_auth.rb} +7 -5
  108. data/lib/httpx/plugins/oauth.rb +175 -0
  109. data/lib/httpx/plugins/persistent.rb +1 -1
  110. data/lib/httpx/plugins/proxy/http.rb +23 -13
  111. data/lib/httpx/plugins/proxy/socks4.rb +9 -7
  112. data/lib/httpx/plugins/proxy/socks5.rb +11 -9
  113. data/lib/httpx/plugins/proxy.rb +80 -61
  114. data/lib/httpx/plugins/push_promise.rb +1 -1
  115. data/lib/httpx/plugins/rate_limiter.rb +5 -1
  116. data/lib/httpx/plugins/response_cache/file_store.rb +40 -0
  117. data/lib/httpx/plugins/response_cache/store.rb +62 -25
  118. data/lib/httpx/plugins/response_cache.rb +105 -12
  119. data/lib/httpx/plugins/retries.rb +87 -17
  120. data/lib/httpx/plugins/ssrf_filter.rb +145 -0
  121. data/lib/httpx/plugins/stream.rb +27 -23
  122. data/lib/httpx/plugins/upgrade/h2.rb +4 -4
  123. data/lib/httpx/plugins/upgrade.rb +8 -10
  124. data/lib/httpx/plugins/webdav.rb +80 -0
  125. data/lib/httpx/pool/synch_pool.rb +93 -0
  126. data/lib/httpx/pool.rb +102 -27
  127. data/lib/httpx/punycode.rb +9 -291
  128. data/lib/httpx/request/body.rb +154 -0
  129. data/lib/httpx/request.rb +130 -146
  130. data/lib/httpx/resolver/https.rb +62 -27
  131. data/lib/httpx/resolver/multi.rb +9 -13
  132. data/lib/httpx/resolver/native.rb +192 -76
  133. data/lib/httpx/resolver/resolver.rb +34 -9
  134. data/lib/httpx/resolver/system.rb +16 -11
  135. data/lib/httpx/resolver.rb +38 -16
  136. data/lib/httpx/response/body.rb +242 -0
  137. data/lib/httpx/response/buffer.rb +96 -0
  138. data/lib/httpx/response.rb +159 -217
  139. data/lib/httpx/selector.rb +9 -4
  140. data/lib/httpx/session.rb +137 -89
  141. data/lib/httpx/session_extensions.rb +4 -1
  142. data/lib/httpx/timers.rb +34 -8
  143. data/lib/httpx/transcoder/body.rb +0 -2
  144. data/lib/httpx/transcoder/chunker.rb +0 -1
  145. data/lib/httpx/transcoder/deflate.rb +37 -0
  146. data/lib/httpx/transcoder/form.rb +52 -33
  147. data/lib/httpx/transcoder/gzip.rb +74 -0
  148. data/lib/httpx/transcoder/json.rb +21 -8
  149. data/lib/httpx/transcoder/multipart/decoder.rb +139 -0
  150. data/lib/httpx/{plugins → transcoder}/multipart/encoder.rb +4 -4
  151. data/lib/httpx/{plugins → transcoder}/multipart/mime_type_detector.rb +1 -1
  152. data/lib/httpx/{plugins → transcoder}/multipart/part.rb +3 -2
  153. data/lib/httpx/transcoder/multipart.rb +17 -0
  154. data/lib/httpx/transcoder/utils/body_reader.rb +46 -0
  155. data/lib/httpx/transcoder/utils/deflater.rb +72 -0
  156. data/lib/httpx/transcoder/utils/inflater.rb +19 -0
  157. data/lib/httpx/transcoder/xml.rb +52 -0
  158. data/lib/httpx/transcoder.rb +5 -6
  159. data/lib/httpx/utils.rb +36 -16
  160. data/lib/httpx/version.rb +1 -1
  161. data/lib/httpx.rb +12 -14
  162. data/sig/altsvc.rbs +33 -0
  163. data/sig/buffer.rbs +2 -1
  164. data/sig/callbacks.rbs +3 -3
  165. data/sig/chainable.rbs +11 -9
  166. data/sig/connection/http1.rbs +8 -7
  167. data/sig/connection/http2.rbs +19 -19
  168. data/sig/connection.rbs +64 -24
  169. data/sig/errors.rbs +22 -3
  170. data/sig/httpx.rbs +5 -4
  171. data/sig/io/ssl.rbs +27 -0
  172. data/sig/io/tcp.rbs +60 -0
  173. data/sig/io/udp.rbs +20 -0
  174. data/sig/io/unix.rbs +27 -0
  175. data/sig/io.rbs +6 -0
  176. data/sig/options.rbs +32 -22
  177. data/sig/parser/http1.rbs +1 -1
  178. data/sig/plugins/{authentication → auth}/basic.rbs +0 -2
  179. data/sig/plugins/{authentication → auth}/digest.rbs +2 -1
  180. data/sig/plugins/auth.rbs +13 -0
  181. data/sig/plugins/{basic_authentication.rbs → basic_auth.rbs} +2 -2
  182. data/sig/plugins/brotli.rbs +22 -0
  183. data/sig/plugins/callbacks.rbs +38 -0
  184. data/sig/plugins/circuit_breaker.rbs +71 -0
  185. data/sig/plugins/compression.rbs +7 -5
  186. data/sig/plugins/cookies/jar.rbs +2 -2
  187. data/sig/plugins/cookies.rbs +2 -0
  188. data/sig/plugins/{digest_authentication.rbs → digest_auth.rbs} +2 -2
  189. data/sig/plugins/follow_redirects.rbs +18 -4
  190. data/sig/plugins/grpc/call.rbs +19 -0
  191. data/sig/plugins/grpc/grpc_encoding.rbs +37 -0
  192. data/sig/plugins/grpc/message.rbs +17 -0
  193. data/sig/plugins/grpc.rbs +7 -32
  194. data/sig/plugins/h2c.rbs +1 -1
  195. data/sig/plugins/{ntlm_authentication.rbs → ntlm_auth.rbs} +2 -2
  196. data/sig/plugins/oauth.rbs +54 -0
  197. data/sig/plugins/proxy/http.rbs +3 -0
  198. data/sig/plugins/proxy/socks4.rbs +9 -6
  199. data/sig/plugins/proxy/socks5.rbs +10 -6
  200. data/sig/plugins/proxy/ssh.rbs +1 -1
  201. data/sig/plugins/proxy.rbs +13 -5
  202. data/sig/plugins/push_promise.rbs +3 -3
  203. data/sig/plugins/rate_limiter.rbs +1 -1
  204. data/sig/plugins/response_cache.rbs +36 -7
  205. data/sig/plugins/retries.rbs +30 -8
  206. data/sig/plugins/stream.rbs +24 -17
  207. data/sig/plugins/upgrade.rbs +5 -3
  208. data/sig/pool.rbs +10 -7
  209. data/sig/request/body.rbs +38 -0
  210. data/sig/request.rbs +15 -24
  211. data/sig/resolver/https.rbs +8 -3
  212. data/sig/resolver/native.rbs +17 -4
  213. data/sig/resolver/resolver.rbs +8 -6
  214. data/sig/resolver/system.rbs +2 -0
  215. data/sig/resolver.rbs +9 -5
  216. data/sig/response/body.rbs +53 -0
  217. data/sig/response/buffer.rbs +24 -0
  218. data/sig/response.rbs +24 -39
  219. data/sig/selector.rbs +1 -1
  220. data/sig/session.rbs +29 -18
  221. data/sig/timers.rbs +18 -8
  222. data/sig/transcoder/body.rbs +4 -3
  223. data/sig/transcoder/deflate.rbs +11 -0
  224. data/sig/transcoder/form.rbs +5 -3
  225. data/sig/transcoder/gzip.rbs +24 -0
  226. data/sig/transcoder/json.rbs +8 -3
  227. data/sig/{plugins → transcoder}/multipart.rbs +15 -19
  228. data/sig/transcoder/utils/body_reader.rbs +15 -0
  229. data/sig/transcoder/utils/deflater.rbs +29 -0
  230. data/sig/transcoder/utils/inflater.rbs +12 -0
  231. data/sig/transcoder/xml.rbs +22 -0
  232. data/sig/transcoder.rbs +24 -9
  233. data/sig/utils.rbs +8 -2
  234. metadata +163 -41
  235. data/lib/httpx/plugins/authentication.rb +0 -20
  236. data/lib/httpx/plugins/basic_authentication.rb +0 -30
  237. data/lib/httpx/plugins/compression/brotli.rb +0 -54
  238. data/lib/httpx/plugins/compression/deflate.rb +0 -49
  239. data/lib/httpx/plugins/compression/gzip.rb +0 -88
  240. data/lib/httpx/plugins/compression.rb +0 -164
  241. data/lib/httpx/plugins/multipart/decoder.rb +0 -187
  242. data/lib/httpx/plugins/multipart.rb +0 -84
  243. data/lib/httpx/registry.rb +0 -85
  244. data/sig/plugins/authentication.rbs +0 -11
  245. data/sig/plugins/compression/brotli.rbs +0 -21
  246. data/sig/plugins/compression/deflate.rbs +0 -17
  247. data/sig/plugins/compression/gzip.rbs +0 -29
  248. data/sig/registry.rbs +0 -12
  249. /data/sig/plugins/{authentication → auth}/ntlm.rbs +0 -0
  250. /data/sig/plugins/{authentication → auth}/socks5.rbs +0 -0
data/lib/httpx.rb CHANGED
@@ -11,7 +11,6 @@ require "httpx/domain_name"
11
11
  require "httpx/altsvc"
12
12
  require "httpx/callbacks"
13
13
  require "httpx/loggable"
14
- require "httpx/registry"
15
14
  require "httpx/transcoder"
16
15
  require "httpx/timers"
17
16
  require "httpx/pool"
@@ -21,7 +20,6 @@ require "httpx/response"
21
20
  require "httpx/options"
22
21
  require "httpx/chainable"
23
22
 
24
- require "mutex_m"
25
23
  # Top-Level Namespace
26
24
  #
27
25
  module HTTPX
@@ -32,16 +30,17 @@ module HTTPX
32
30
  #
33
31
  module Plugins
34
32
  @plugins = {}
35
- @plugins.extend(Mutex_m)
33
+ @plugins_mutex = Thread::Mutex.new
36
34
 
37
35
  # Loads a plugin based on a name. If the plugin hasn't been loaded, tries to load
38
36
  # it from the load path under "httpx/plugins/" directory.
39
37
  #
40
38
  def self.load_plugin(name)
41
39
  h = @plugins
42
- unless (plugin = h.synchronize { h[name] })
40
+ m = @plugins_mutex
41
+ unless (plugin = m.synchronize { h[name] })
43
42
  require "httpx/plugins/#{name}"
44
- raise "Plugin #{name} hasn't been registered" unless (plugin = h.synchronize { h[name] })
43
+ raise "Plugin #{name} hasn't been registered" unless (plugin = m.synchronize { h[name] })
45
44
  end
46
45
  plugin
47
46
  end
@@ -50,20 +49,19 @@ module HTTPX
50
49
  #
51
50
  def self.register_plugin(name, mod)
52
51
  h = @plugins
53
- h.synchronize { h[name] = mod }
52
+ m = @plugins_mutex
53
+ m.synchronize { h[name] = mod }
54
54
  end
55
55
  end
56
56
 
57
- # :nocov:
58
- def self.const_missing(const_name)
59
- super unless const_name == :Client
60
- warn "DEPRECATION WARNING: the class #{self}::Client is deprecated. Use #{self}::Session instead."
61
- Session
62
- end
63
- # :nocov:
64
-
65
57
  extend Chainable
66
58
  end
67
59
 
68
60
  require "httpx/session"
69
61
  require "httpx/session_extensions"
62
+
63
+ # load integrations when possible
64
+
65
+ require "httpx/adapters/datadog" if defined?(DDTrace) || defined?(Datadog)
66
+ require "httpx/adapters/sentry" if defined?(Sentry)
67
+ require "httpx/adapters/webmock" if defined?(WebMock)
data/sig/altsvc.rbs ADDED
@@ -0,0 +1,33 @@
1
+ module HTTPX
2
+ module AltSvc
3
+ module ConnectionMixin
4
+
5
+ def send: (Request request) -> void
6
+
7
+ def match?: (URI::Generic uri, Options options) -> bool
8
+
9
+ private
10
+
11
+ def match_altsvcs?: (URI::Generic uri) -> bool
12
+
13
+ def match_altsvc_options?: (URI::Generic uri, Options options) -> bool
14
+ end
15
+
16
+ type altsvc_params = Hash[String, untyped]
17
+
18
+ def self?.cached_altsvc: (String origin) -> Array[altsvc_params]
19
+
20
+ def self?.cached_altsvc_set: (String origin, altsvc_params) -> void
21
+
22
+ def self?.lookup: (String origin, Integer | Float ttl) -> Array[altsvc_params]
23
+
24
+ def self?.emit: (Request request, response response) { (http_uri alt_origin, String origin, altsvc_params alt_params) -> void } -> void
25
+
26
+ def self?.parse: (String altsvc) { (http_uri alt_origin, altsvc_params alt_params) -> void } -> void
27
+ | (String altsvc) -> Enumerable[[http_uri, altsvc_params]]
28
+
29
+ def self?.parse_altsvc_scheme: (String alt_proto) -> String?
30
+
31
+ def self.parse_altsvc_origin: (string alt_proto, String alt_origin) -> http_uri?
32
+ end
33
+ end
data/sig/buffer.rbs CHANGED
@@ -11,11 +11,12 @@ module HTTPX
11
11
 
12
12
  def full?: () -> bool
13
13
  def shift!: (Integer) -> void
14
+ def capacity: () -> Integer
14
15
 
15
16
  # delegated
16
17
  def <<: (string data) -> String
17
18
  def empty?: () -> bool
18
- def bytesize: () -> Integer
19
+ def bytesize: () -> (Integer | Float)
19
20
  def clear: () -> void
20
21
  def replace: (string) -> void
21
22
 
data/sig/callbacks.rbs CHANGED
@@ -4,9 +4,9 @@ module HTTPX
4
4
  end
5
5
 
6
6
  module Callbacks
7
- def on: (Symbol) { (*untyped) -> void } -> void
8
- def once: (Symbol) { (*untyped) -> void } -> void
9
- def only: (Symbol) { (*untyped) -> void } -> void
7
+ def on: (Symbol) { (*untyped) -> void } -> self
8
+ def once: (Symbol) { (*untyped) -> void } -> self
9
+ def only: (Symbol) { (*untyped) -> void } -> self
10
10
  def emit: (Symbol, *untyped) -> void
11
11
 
12
12
  def callbacks_for?: (Symbol) -> bool
data/sig/chainable.rbs CHANGED
@@ -2,9 +2,9 @@ module HTTPX
2
2
  module Chainable
3
3
  def request: (*Request, **untyped) -> Array[response]
4
4
  | (Request, **untyped) -> response
5
- | (verb | string, uri | [uri], **untyped) -> response
6
- | (Array[[verb | string, uri] | [verb | string, uri, options]], **untyped) -> Array[response]
7
- | (verb | string, _Each[uri | [uri, options]], **untyped) -> Array[response]
5
+ | (verb, uri | [uri], **untyped) -> 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
@@ -12,18 +12,17 @@ module HTTPX
12
12
  def with: (options) -> Session
13
13
  | (options) { (Session) -> void } -> void
14
14
 
15
- def plugin: (:authentication, ?options) -> Plugins::sessionAuthentication
16
- | (:basic_authentication, ?options) -> Plugins::sessionBasicAuth
17
- | (:digest_authentication, ?options) -> Plugins::sessionDigestAuth
18
- | (:ntlm_authentication, ?options) -> Plugins::sessionNTLMAuth
15
+ def plugin: (:auth, ?options) -> Plugins::sessionAuthorization
16
+ | (:basic_auth, ?options) -> Plugins::sessionBasicAuth
17
+ | (:digest_auth, ?options) -> Plugins::sessionDigestAuth
18
+ | (:ntlm_auth, ?options) -> Plugins::sessionNTLMAuth
19
19
  | (:aws_sdk_authentication, ?options) -> Plugins::sessionAwsSdkAuthentication
20
- | (:compression, ?options) -> Session
20
+ | (:brotli, ?options) -> Session
21
21
  | (:cookies, ?options) -> Plugins::sessionCookies
22
22
  | (:expect, ?options) -> Session
23
23
  | (:follow_redirects, ?options) -> Plugins::sessionFollowRedirects
24
24
  | (:upgrade, ?options) -> Session
25
25
  | (:h2c, ?options) -> Session
26
- | (:multipart, ?options) -> Session
27
26
  | (:persistent, ?options) -> Plugins::sessionPersistent
28
27
  | (:proxy, ?options) -> (Plugins::sessionProxy & Plugins::httpProxy)
29
28
  | (:push_promise, ?options) -> Plugins::sessionPushPromise
@@ -33,6 +32,9 @@ module HTTPX
33
32
  | (:aws_sigv4, ?options) -> Plugins::awsSigV4Session
34
33
  | (:grpc, ?options) -> Plugins::grpcSession
35
34
  | (:response_cache, ?options) -> Plugins::sessionResponseCache
35
+ | (:circuit_breaker, ?options) -> Plugins::sessionCircuitBreaker
36
+ | (:oauth, ?options) -> Plugins::sessionOAuth
37
+ | (:callbacks, ?options) -> Plugins::sessionCallbacks
36
38
  | (Symbol | Module, ?options) { (Class) -> void } -> Session
37
39
  | (Symbol | Module, ?options) -> Session
38
40
 
@@ -10,8 +10,9 @@ module HTTPX
10
10
  attr_reader pending: Array[Request]
11
11
  attr_reader requests: Array[Request]
12
12
 
13
+ attr_accessor max_concurrent_requests: Integer
14
+
13
15
  @options: Options
14
- @max_concurrent_requests: Integer
15
16
  @max_requests: Integer
16
17
  @parser: Parser::HTTP1
17
18
  @buffer: Buffer
@@ -31,13 +32,13 @@ module HTTPX
31
32
 
32
33
  def exhausted?: () -> bool
33
34
 
34
- def <<: (String) -> void
35
+ def <<: (string) -> void
35
36
 
36
37
  def send: (Request) -> void
37
38
 
38
39
  def consume: () -> void
39
40
 
40
- def handle_error: (StandardError ex) -> void
41
+ def handle_error: (StandardError ex, ?Request? request) -> void
41
42
 
42
43
  def on_start: () -> void
43
44
 
@@ -53,19 +54,19 @@ module HTTPX
53
54
 
54
55
  def ping: () -> void
55
56
 
56
- def timeout: () -> Numeric
57
+ def timeout: () -> Numeric?
57
58
 
58
59
  private
59
60
 
60
- def initialize: (Buffer, options) -> untyped
61
+ def initialize: (Buffer buffer, Options options) -> untyped
61
62
 
62
- def manage_connection: (Response) -> void
63
+ def manage_connection: (Request request, Response response) -> void
63
64
 
64
65
  def disable: () -> void
65
66
 
66
67
  def disable_pipelining: () -> void
67
68
 
68
- def set_protocol_headers: (Request) -> _Each[[String, String]]
69
+ def set_protocol_headers: (Request request) -> _Each[[String, String]]
69
70
 
70
71
  def handle: (Request request) -> void
71
72
 
@@ -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
 
@@ -32,45 +32,45 @@ module HTTPX
32
32
 
33
33
  def consume: () -> void
34
34
 
35
- def handle_error: (StandardError ex) -> void
35
+ def handle_error: (StandardError ex, ?Request? request) -> void
36
36
 
37
37
  def ping: () -> void
38
38
 
39
39
  alias reset init_connection
40
40
 
41
- def timeout: () -> Numeric
41
+ def timeout: () -> Numeric?
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
@@ -17,42 +17,51 @@ module HTTPX
17
17
  extend Forwardable
18
18
  include Loggable
19
19
  include Callbacks
20
- include HTTPX::Registry[String, Class]
21
20
 
22
- BUFFER_SIZE: Integer
23
21
 
24
- attr_reader origin: URI::Generic
22
+ attr_reader type: io_type
23
+ attr_reader origin: http_uri
25
24
  attr_reader origins: Array[String]
26
25
  attr_reader state: Symbol
27
26
  attr_reader pending: Array[Request]
28
27
  attr_reader options: Options
28
+ attr_reader ssl_session: OpenSSL::SSL::Session?
29
29
  attr_writer timers: Timers
30
30
 
31
- @origins: Array[URI::Generic]
31
+ attr_accessor family: Integer?
32
+
32
33
  @window_size: Integer
33
34
  @read_buffer: Buffer
34
35
  @write_buffer: Buffer
35
36
  @inflight: Integer
36
37
  @keep_alive_timeout: Numeric?
37
- @total_timeout: Numeric?
38
+ @timeout: Numeric?
39
+ @current_timeout: Numeric?
40
+ @io: TCP | SSL | UNIX
41
+ @parser: Object & _Parser
42
+ @connected_at: Float
43
+ @response_received_at: Float
44
+ @intervals: Array[Timers::Interval]
38
45
 
39
46
  def addresses: () -> Array[ipaddr]?
40
47
 
41
- def addresses=: (Array[ipaddr]) -> void
48
+ def addresses=: (Array[ipaddr] addresses) -> void
42
49
 
43
- def match?: (URI::Generic, options) -> bool
50
+ def send: (Request request) -> void
44
51
 
45
- def mergeable?: (Connection) -> bool
52
+ def match?: (URI::Generic uri, Options options) -> bool
46
53
 
47
- def coalescable?: (Connection) -> bool
54
+ def expired?: () -> boolish
48
55
 
49
- def create_idle: (?Hash[Symbol, untyped] options) -> Connection
56
+ def mergeable?: (Connection connection) -> bool
57
+
58
+ def coalescable?: (Connection connection) -> bool
50
59
 
51
- def merge: (Connection) -> void
60
+ def create_idle: (?Hash[Symbol, untyped] options) -> Connection
52
61
 
53
- def purge_pending: () { (Request) -> void } -> void
62
+ def merge: (Connection connection) -> void
54
63
 
55
- def match_altsvcs?: (URI::Generic uri) -> bool
64
+ def purge_pending: () { (Request request) -> void } -> void
56
65
 
57
66
  def connecting?: () -> bool
58
67
 
@@ -60,21 +69,33 @@ module HTTPX
60
69
 
61
70
  def interests: () -> io_interests?
62
71
 
63
- def to_io: () -> IO
72
+ def to_io: () -> ::IO
64
73
 
65
74
  def call: () -> void
66
75
 
76
+ def terminate: () -> void
77
+
67
78
  def close: () -> void
68
- def reset: () -> void
69
79
 
70
- def send: (Request) -> void
80
+ def reset: () -> void
71
81
 
72
82
  def timeout: () -> Numeric?
73
83
 
84
+ def idling: () -> void
85
+
86
+ def used?: () -> boolish
87
+
74
88
  def deactivate: () -> void
89
+
90
+ def open?: () -> bool
91
+
92
+ def handle_socket_timeout: (Numeric interval) -> void
93
+
75
94
  private
76
95
 
77
- def initialize: (String, URI::Generic, options) -> untyped
96
+ def initialize: (http_uri uri, Options options) -> void
97
+
98
+ def initialize_type: (http_uri uri, Options options) -> io_type
78
99
 
79
100
  def connect: () -> void
80
101
 
@@ -84,21 +105,40 @@ module HTTPX
84
105
 
85
106
  def send_pending: () -> void
86
107
 
87
- def parser: () -> _Parser
108
+ def parser: () -> (Object & _Parser)
88
109
 
89
110
  def send_request_to_parser: (Request request) -> void
90
111
 
91
- def build_parser: () -> _Parser
92
- | (String) -> _Parser
112
+ def build_parser: (?String protocol) -> (Object & _Parser)
113
+
114
+ def set_parser_callbacks: (HTTP1 | HTTP2 parser) -> void
115
+
116
+ def transition: (Symbol nextstate) -> void
93
117
 
94
- def set_parser_callbacks: (_Parser) -> void
118
+ def handle_transition: (Symbol nextstate) -> void
95
119
 
96
- def transition: (Symbol) -> void
120
+ def build_socket: (?Array[ipaddr]? addrs) -> (TCP | SSL | UNIX)
97
121
 
98
- def on_error: (HTTPX::TimeoutError | Error | StandardError) -> void
122
+ def on_error: (HTTPX::TimeoutError | Error | StandardError error, ?Request? request) -> void
99
123
 
100
- def handle_error: (StandardError) -> void
124
+ def handle_error: (StandardError error, ?Request? request) -> void
101
125
 
102
126
  def purge_after_closed: () -> void
127
+
128
+ def set_request_timeouts: (Request request) -> void
129
+
130
+ def set_request_read_timeout: (Request request) -> void
131
+
132
+ def set_request_write_timeout: (Request request) -> void
133
+
134
+ def set_request_request_timeout: (Request request) -> void
135
+
136
+ def write_timeout_callback: (Request request, Numeric write_timeout) -> void
137
+
138
+ def read_timeout_callback: (Request request, Numeric read_timeout, ?singleton(RequestTimeoutError) error_type) -> void
139
+
140
+ def set_request_timeout: (Request request, Numeric timeout, Symbol start_event, Symbol | Array[Symbol] finish_events) { () -> void } -> void
141
+
142
+ def self.parser_type: (String protocol) -> (singleton(HTTP1) | singleton(HTTP2))
103
143
  end
104
144
  end
data/sig/errors.rbs CHANGED
@@ -2,6 +2,12 @@ module HTTPX
2
2
  class Error < StandardError
3
3
  end
4
4
 
5
+ class UnsupportedSchemeError < Error
6
+ end
7
+
8
+ class ConnectionError < Error
9
+ end
10
+
5
11
  class TimeoutError < Error
6
12
  attr_reader timeout: Numeric
7
13
 
@@ -11,9 +17,6 @@ module HTTPX
11
17
  def initialize: (Numeric timeout, String message) -> untyped
12
18
  end
13
19
 
14
- class TotalTimeoutError < TimeoutError
15
- end
16
-
17
20
  class ConnectTimeoutError < TimeoutError
18
21
  end
19
22
 
@@ -23,6 +26,19 @@ module HTTPX
23
26
  class ResolveTimeoutError < TimeoutError
24
27
  end
25
28
 
29
+ class RequestTimeoutError < TimeoutError
30
+ attr_reader request: Request
31
+ attr_reader response: response?
32
+
33
+ def initialize: (Request request, response? response, Numeric timeout) -> void
34
+ end
35
+
36
+ class ReadTimeoutError < RequestTimeoutError
37
+ end
38
+
39
+ class WriteTimeoutError < RequestTimeoutError
40
+ end
41
+
26
42
  class ResolveError < Error
27
43
  end
28
44
 
@@ -42,4 +58,7 @@ module HTTPX
42
58
 
43
59
  def initialize: (Connection connection, String hostname, ?String message) -> untyped
44
60
  end
61
+
62
+ class MisdirectedRequestError < HTTPError
63
+ end
45
64
  end
data/sig/httpx.rbs CHANGED
@@ -5,12 +5,13 @@ module HTTPX
5
5
 
6
6
  VERSION: String
7
7
 
8
- type uri = URI::HTTP | URI::HTTPS | string
8
+ type http_uri = URI::HTTP | URI::HTTPS
9
+ type uri = http_uri | string
9
10
  type generic_uri = String | URI::Generic
10
11
 
11
- type verb = :options | :get | :head | :post | :put | :delete | :trace | :connect |
12
- :propfind | :proppatch | :mkcol | :copy | :move | :lock | :unlock | :orderpatch |
13
- :acl | :report | :patch | :search
12
+ type verb = String
13
+
14
+ type request_params = Hash[Symbol, untyped]
14
15
 
15
16
  type ip_family = Integer #Socket::AF_INET6 | Socket::AF_INET
16
17
 
data/sig/io/ssl.rbs ADDED
@@ -0,0 +1,27 @@
1
+ module HTTPX
2
+
3
+ class TLSError < OpenSSL::SSL::SSLError
4
+ end
5
+
6
+ class SSL < TCP
7
+ TLS_OPTIONS: Hash[Symbol, untyped]
8
+
9
+ @ctx: OpenSSL::SSL::SSLContext
10
+ @verify_hostname: bool
11
+
12
+ attr_writer ssl_session: OpenSSL::SSL::Session?
13
+
14
+ # TODO: lift when https://github.com/ruby/rbs/issues/1497 fixed
15
+ # def initialize: (URI::Generic origin, Array[ipaddr]? addresses, options options) ?{ (self) -> void } -> void
16
+
17
+ def session_new_cb: { (OpenSSL::SSL::Session sess) -> void } -> void
18
+ def can_verify_peer?: () -> bool
19
+
20
+ def verify_hostname: (String host) -> bool
21
+
22
+ def ssl_session_expired?: () -> boolish
23
+
24
+ # :nocov:
25
+ def try_ssl_connect: () -> void
26
+ end
27
+ end
data/sig/io/tcp.rbs ADDED
@@ -0,0 +1,60 @@
1
+ module HTTPX
2
+ class TCP
3
+ include Loggable
4
+
5
+ attr_reader ip: ipaddr?
6
+
7
+ attr_reader port: Integer
8
+
9
+ attr_reader addresses: Array[ipaddr]
10
+
11
+ attr_reader state: Symbol
12
+
13
+ attr_reader interests: io_interests
14
+
15
+ alias host ip
16
+
17
+ # TODO: lift when https://github.com/ruby/rbs/issues/1497 fixed
18
+ def initialize: (URI::Generic origin, Array[ipaddr]? addresses, Options options) ?{ (instance) -> void } -> void
19
+
20
+ def add_addresses: (Array[ipaddr] addrs) -> void
21
+
22
+ def to_io: () -> ::IO
23
+
24
+ def protocol: () -> String
25
+
26
+ def connect: () -> void
27
+
28
+ private
29
+
30
+ # :nocov:
31
+ def try_connect: () -> void
32
+
33
+ public
34
+
35
+ def read: (Integer size, ?(Buffer | String) buffer) -> (0 | nil | untyped)
36
+
37
+ def write: (Buffer buffer) -> Integer?
38
+
39
+ def close: () -> void
40
+
41
+ def connected?: () -> bool
42
+
43
+ def expired?: () -> boolish
44
+
45
+ def closed?: () -> bool
46
+
47
+ # :nocov:
48
+ def inspect: () -> ::String
49
+
50
+ private
51
+
52
+ def build_socket: () -> Socket
53
+
54
+ def transition: (Symbol nextstate) -> void
55
+
56
+ def do_transition: (Symbol nextstate) -> void
57
+
58
+ def log_transition_state: (Symbol nextstate) -> void
59
+ end
60
+ end
data/sig/io/udp.rbs ADDED
@@ -0,0 +1,20 @@
1
+ module HTTPX
2
+ class UDP
3
+ include Loggable
4
+
5
+ def initialize: (String ip, Integer port, Options options) -> void
6
+
7
+ def to_io: () -> ::IO
8
+
9
+ def connect: () -> void
10
+
11
+ def connected?: () -> bool
12
+
13
+ # :nocov:
14
+ def close: () -> void
15
+
16
+ def read: (Integer size, ?(Buffer | String) buffer) -> Integer?
17
+
18
+ def write: (Buffer buffer) -> Integer?
19
+ end
20
+ end
data/sig/io/unix.rbs ADDED
@@ -0,0 +1,27 @@
1
+ module HTTPX
2
+ class UNIX < TCP
3
+
4
+ attr_reader path: String
5
+
6
+ alias host path
7
+
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
26
+ end
27
+ end
data/sig/io.rbs ADDED
@@ -0,0 +1,6 @@
1
+ module HTTPX
2
+ type io_type = "udp" | "tcp" | "ssl" | "unix"
3
+
4
+ module IO
5
+ end
6
+ end