httpx 0.9.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +48 -0
  3. data/README.md +13 -3
  4. data/doc/release_notes/0_10_0.md +66 -0
  5. data/doc/release_notes/0_10_1.md +37 -0
  6. data/doc/release_notes/0_10_2.md +5 -0
  7. data/doc/release_notes/0_11_0.md +76 -0
  8. data/doc/release_notes/0_11_1.md +1 -0
  9. data/lib/httpx.rb +2 -0
  10. data/lib/httpx/adapters/datadog.rb +205 -0
  11. data/lib/httpx/adapters/faraday.rb +1 -3
  12. data/lib/httpx/adapters/webmock.rb +123 -0
  13. data/lib/httpx/chainable.rb +10 -9
  14. data/lib/httpx/connection.rb +7 -24
  15. data/lib/httpx/connection/http1.rb +15 -2
  16. data/lib/httpx/connection/http2.rb +15 -16
  17. data/lib/httpx/domain_name.rb +438 -0
  18. data/lib/httpx/errors.rb +4 -1
  19. data/lib/httpx/extensions.rb +21 -1
  20. data/lib/httpx/headers.rb +1 -0
  21. data/lib/httpx/io/ssl.rb +4 -9
  22. data/lib/httpx/io/tcp.rb +6 -5
  23. data/lib/httpx/io/udp.rb +8 -4
  24. data/lib/httpx/options.rb +2 -0
  25. data/lib/httpx/parser/http1.rb +14 -17
  26. data/lib/httpx/plugins/compression.rb +28 -63
  27. data/lib/httpx/plugins/compression/brotli.rb +10 -14
  28. data/lib/httpx/plugins/compression/deflate.rb +7 -6
  29. data/lib/httpx/plugins/compression/gzip.rb +23 -5
  30. data/lib/httpx/plugins/cookies.rb +21 -60
  31. data/lib/httpx/plugins/cookies/cookie.rb +173 -0
  32. data/lib/httpx/plugins/cookies/jar.rb +74 -0
  33. data/lib/httpx/plugins/cookies/set_cookie_parser.rb +142 -0
  34. data/lib/httpx/plugins/expect.rb +34 -11
  35. data/lib/httpx/plugins/follow_redirects.rb +20 -2
  36. data/lib/httpx/plugins/h2c.rb +1 -1
  37. data/lib/httpx/plugins/multipart.rb +41 -30
  38. data/lib/httpx/plugins/multipart/encoder.rb +115 -0
  39. data/lib/httpx/plugins/multipart/mime_type_detector.rb +64 -0
  40. data/lib/httpx/plugins/multipart/part.rb +34 -0
  41. data/lib/httpx/plugins/persistent.rb +6 -1
  42. data/lib/httpx/plugins/proxy.rb +16 -2
  43. data/lib/httpx/plugins/proxy/socks4.rb +14 -14
  44. data/lib/httpx/plugins/proxy/socks5.rb +3 -2
  45. data/lib/httpx/plugins/push_promise.rb +2 -2
  46. data/lib/httpx/plugins/rate_limiter.rb +51 -0
  47. data/lib/httpx/plugins/retries.rb +3 -2
  48. data/lib/httpx/plugins/stream.rb +109 -13
  49. data/lib/httpx/pool.rb +14 -20
  50. data/lib/httpx/request.rb +29 -31
  51. data/lib/httpx/resolver.rb +7 -6
  52. data/lib/httpx/resolver/https.rb +25 -25
  53. data/lib/httpx/resolver/native.rb +29 -22
  54. data/lib/httpx/resolver/resolver_mixin.rb +4 -2
  55. data/lib/httpx/resolver/system.rb +3 -3
  56. data/lib/httpx/response.rb +16 -23
  57. data/lib/httpx/selector.rb +11 -17
  58. data/lib/httpx/session.rb +39 -30
  59. data/lib/httpx/transcoder.rb +20 -0
  60. data/lib/httpx/transcoder/chunker.rb +0 -2
  61. data/lib/httpx/transcoder/form.rb +9 -7
  62. data/lib/httpx/transcoder/json.rb +0 -4
  63. data/lib/httpx/utils.rb +45 -0
  64. data/lib/httpx/version.rb +1 -1
  65. data/sig/buffer.rbs +24 -0
  66. data/sig/callbacks.rbs +14 -0
  67. data/sig/chainable.rbs +37 -0
  68. data/sig/connection.rbs +85 -0
  69. data/sig/connection/http1.rbs +66 -0
  70. data/sig/connection/http2.rbs +77 -0
  71. data/sig/domain_name.rbs +17 -0
  72. data/sig/errors.rbs +3 -0
  73. data/sig/headers.rbs +45 -0
  74. data/sig/httpx.rbs +15 -0
  75. data/sig/loggable.rbs +11 -0
  76. data/sig/options.rbs +118 -0
  77. data/sig/parser/http1.rbs +50 -0
  78. data/sig/plugins/authentication.rbs +11 -0
  79. data/sig/plugins/basic_authentication.rbs +13 -0
  80. data/sig/plugins/compression.rbs +55 -0
  81. data/sig/plugins/compression/brotli.rbs +21 -0
  82. data/sig/plugins/compression/deflate.rbs +17 -0
  83. data/sig/plugins/compression/gzip.rbs +29 -0
  84. data/sig/plugins/cookies.rbs +26 -0
  85. data/sig/plugins/cookies/cookie.rbs +50 -0
  86. data/sig/plugins/cookies/jar.rbs +27 -0
  87. data/sig/plugins/digest_authentication.rbs +33 -0
  88. data/sig/plugins/expect.rbs +19 -0
  89. data/sig/plugins/follow_redirects.rbs +37 -0
  90. data/sig/plugins/h2c.rbs +26 -0
  91. data/sig/plugins/multipart.rbs +44 -0
  92. data/sig/plugins/persistent.rbs +17 -0
  93. data/sig/plugins/proxy.rbs +47 -0
  94. data/sig/plugins/proxy/http.rbs +14 -0
  95. data/sig/plugins/proxy/socks4.rbs +33 -0
  96. data/sig/plugins/proxy/socks5.rbs +36 -0
  97. data/sig/plugins/proxy/ssh.rbs +18 -0
  98. data/sig/plugins/push_promise.rbs +22 -0
  99. data/sig/plugins/rate_limiter.rbs +11 -0
  100. data/sig/plugins/retries.rbs +48 -0
  101. data/sig/plugins/stream.rbs +39 -0
  102. data/sig/pool.rbs +36 -0
  103. data/sig/registry.rbs +9 -0
  104. data/sig/request.rbs +61 -0
  105. data/sig/resolver.rbs +26 -0
  106. data/sig/resolver/https.rbs +51 -0
  107. data/sig/resolver/native.rbs +60 -0
  108. data/sig/resolver/resolver_mixin.rbs +27 -0
  109. data/sig/resolver/system.rbs +17 -0
  110. data/sig/response.rbs +87 -0
  111. data/sig/selector.rbs +20 -0
  112. data/sig/session.rbs +49 -0
  113. data/sig/timeout.rbs +29 -0
  114. data/sig/transcoder.rbs +18 -0
  115. data/sig/transcoder/body.rbs +20 -0
  116. data/sig/transcoder/chunker.rbs +32 -0
  117. data/sig/transcoder/form.rbs +22 -0
  118. data/sig/transcoder/json.rbs +16 -0
  119. metadata +99 -59
  120. data/lib/httpx/resolver/options.rb +0 -25
@@ -0,0 +1,14 @@
1
+ module HTTPX
2
+ interface _Callable
3
+ def call: (*untyped) -> void
4
+ end
5
+
6
+ module Callbacks
7
+ def on: (Symbol) { (*untyped) -> void } -> void
8
+ def once: (Symbol) { (*untyped) -> void } -> void
9
+ def emit: (Symbol, *untyped) -> void
10
+
11
+ def callbacks: () -> Hash[Symbol, Array[_Callable]]
12
+ | (Symbol) -> Array[_Callable]
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ module HTTPX
2
+ module Chainable
3
+ def request: (*untyped, **untyped) -> (response | Array[response])
4
+ def accept: (String) -> Session
5
+ def wrap: () { (Session) -> void } -> void
6
+ | () -> void
7
+
8
+ def with: (options) -> Session
9
+ | (options) { (Session) -> Session} -> Session
10
+
11
+
12
+
13
+
14
+ def plugin: (:authentication) -> Plugins::sessionAuthentication
15
+ | (:basic_authentication) -> Plugins::sessionBasicAuthentication
16
+ | (:digest_authentication) -> Plugins::sessionDigestAuthentication
17
+ | (:compression) -> Session
18
+ | (:cookies) -> Plugins::sessionCookies
19
+ | (:expect) -> Session
20
+ | (:follow_redirects) -> Plugins::sessionFollowRedirects
21
+ | (:h2c) -> Plugins::sessionH2C
22
+ | (:multipart) -> Session
23
+ | (:persistent) -> Plugins::sessionPersistent
24
+ | (:proxy) -> Plugins::sessionProxy
25
+ | (:push_promise) -> Plugins::sessionPushPromise
26
+ | (:retries) -> Plugins::sessionRetries
27
+ | (:stream) -> Plugins::sessionStream
28
+ | (Symbol | Module, ?options?) { (Class) -> void } -> Session
29
+ | (Symbol | Module, ?options?) -> Session
30
+
31
+ private
32
+
33
+ def default_options: () -> Options
34
+ def branch: (options) -> Session
35
+ | (options) { (Session) -> Session } -> Session
36
+ end
37
+ end
@@ -0,0 +1,85 @@
1
+ module HTTPX
2
+ class Connection
3
+ interface _Parser
4
+
5
+ def on: (Symbol) { (*untyped) -> void } -> void
6
+ def empty?: () -> bool
7
+ def close: () -> void
8
+ def consume: () -> void
9
+ def <<: (string) -> void
10
+ end
11
+
12
+ include Loggable
13
+ include Callbacks
14
+ extend HTTPX::Registry[String, Class]
15
+
16
+ attr_reader origin: generic_uri
17
+ attr_reader state: Symbol
18
+ attr_reader pending: Array[Request]
19
+ attr_reader options: options
20
+
21
+ def addresses: () -> Array[ipaddr]?
22
+
23
+ def addresses=: (Array[ipaddr]) -> void
24
+
25
+ def match?: (generic_uri, options) -> bool
26
+
27
+ def mergeable?: (Connection) -> bool
28
+
29
+ def coalescable?: (Connection) -> bool
30
+
31
+ def create_idle: (options) -> Connection
32
+ | () -> Connection
33
+
34
+ def merge: (Connection) -> void
35
+
36
+ def purge_pending: () { (Request) -> void } -> void
37
+
38
+ def match_altsvcs?: (generic_uri) -> bool
39
+
40
+ def connecting?: () -> bool
41
+ def inflight?: () -> boolish
42
+
43
+ def interests: () -> io_interests?
44
+
45
+ def to_io: () -> _ToIO
46
+
47
+ def call: () -> void
48
+
49
+ def close: () -> void
50
+ def reset: () -> void
51
+
52
+ def send: (Request) -> void
53
+
54
+ def timeout: () -> Numeric?
55
+
56
+ private
57
+
58
+ def initialize: (String, generic_uri, options) -> untyped
59
+
60
+ def connect: () -> void
61
+
62
+ def exhausted?: () -> boolish
63
+
64
+ def consume: () -> void
65
+
66
+ def send_pending: () -> void
67
+
68
+ def parser: () -> _Parser
69
+
70
+ def build_parser: () -> _Parser
71
+ | (String) -> _Parser
72
+
73
+ def set_parser_callbacks: (_Parser) -> void
74
+
75
+ def transition: (Symbol) -> void
76
+
77
+ def handle_response: () -> void
78
+
79
+ def on_error: (StandardError) -> void
80
+
81
+ def handle_error: (StandardError) -> void
82
+
83
+ def total_timeout: () -> Timers::Timer?
84
+ end
85
+ end
@@ -0,0 +1,66 @@
1
+ module HTTPX
2
+ class Connection::HTTP1
3
+ include Callbacks
4
+ include Loggable
5
+
6
+ attr_reader pending: Array[Request]
7
+
8
+ @options: Options
9
+ @max_concurrent_requests: Integer
10
+ @max_requests: Integer
11
+ @parser: HTTP1
12
+ @buffer: Buffer
13
+
14
+ def interests: () -> io_interests?
15
+
16
+ def reset: () -> void
17
+
18
+ def close: () -> void
19
+
20
+ def empty?: () -> bool
21
+
22
+ def exhausted?: () -> bool
23
+
24
+ def <<: (String) -> void
25
+
26
+ def send: (Request) -> void
27
+
28
+ def consume: () -> void
29
+
30
+ def handle_error: (StandardError ex) -> void
31
+
32
+ def on_headers: (Hash[String, Array[String]] headers) -> void
33
+
34
+ def on_trailers: (Array[String, String] headers) -> void
35
+
36
+ def on_data: (string chunk) -> void
37
+
38
+ def on_complete: () -> void
39
+
40
+ def dispatch: () -> void
41
+
42
+ def ping: () -> void
43
+
44
+ private
45
+
46
+ def initialize: (Buffer, options) -> untyped
47
+
48
+ def manage_connection: (Response) -> void
49
+
50
+ def disable: () -> void
51
+
52
+ def disable_pipelining: () -> void
53
+
54
+ def set_request_headers: (Request) -> void
55
+
56
+ def headline_uri: (Request) -> String
57
+
58
+ def handle: (Request request) -> void
59
+
60
+ def join_headers: (Request request) -> void
61
+
62
+ def join_body: (Request request) -> void
63
+
64
+ def capitalized: (String field) -> String
65
+ end
66
+ end
@@ -0,0 +1,77 @@
1
+ module HTTPX
2
+ class Connection::HTTP2
3
+ include Callbacks
4
+ include Loggable
5
+
6
+ attr_reader streams: Hash[HTTP2Next::Stream, Response]
7
+ attr_reader pending: Array[Request]
8
+
9
+ @options: Options
10
+ @max_concurrent_requests: Integer
11
+ @max_requests: Integer
12
+ @drains: Hash[Request, String]
13
+ @pings: Array[String]
14
+ @buffer: Buffer
15
+
16
+ def interests: () -> io_interests
17
+
18
+ def close: () -> void
19
+
20
+ def empty?: () -> bool
21
+
22
+ def exhausted?: () -> bool
23
+
24
+ def <<: (String) -> void
25
+
26
+ def send: (Request) -> void
27
+
28
+ def consume: () -> void
29
+
30
+ def handle_error: (StandardError ex) -> void
31
+
32
+ def ping: () -> void
33
+
34
+ alias reset init_connection
35
+
36
+ private
37
+
38
+ def initialize: (Buffer, options) -> untyped
39
+
40
+ def send_pending: () -> void
41
+
42
+ def headline_uri: (Request) -> String
43
+
44
+ def set_request_headers: (Request) -> void
45
+
46
+ def handle: (Request request, HTTP2Next::Stream stream) -> void
47
+
48
+ def init_connection: () -> void
49
+
50
+ def handle_stream: (HTTP2Next::Stream stream, Request request) -> void
51
+
52
+ def join_headers: (HTTP2Next::Stream stream, Request request) -> void
53
+
54
+ def join_body: (HTTP2Next::Stream stream, Request request) -> void
55
+
56
+ def on_stream_headers: (HTTP2Next::Stream stream, Request request, Array[[String, String]] headers) -> void
57
+
58
+ def on_stream_data: (HTTP2Next::Stream stream, Request request, string data) -> void
59
+
60
+ def on_stream_close: (HTTP2Next::Stream stream, Request request, Symbol? error) -> void
61
+
62
+ def on_frame: (string bytes) -> void
63
+
64
+ def on_settings: (*untyped) -> void
65
+
66
+ def on_close: (Integer last_frame, Symbol? error, String? payload) -> void
67
+
68
+ def on_frame_sent: (HTTP2Next::frame) -> void
69
+ def on_frame_received: (HTTP2Next::frame) -> void
70
+
71
+ def on_promise: (HTTP2Next::Stream) -> void
72
+
73
+ def on_origin: (String) -> void
74
+
75
+ def on_pong: (string ping) -> void
76
+ end
77
+ end
@@ -0,0 +1,17 @@
1
+ module HTTPX
2
+ class DomainName
3
+ type domain = string | DomainName
4
+
5
+ include Comparable
6
+
7
+ def normalize: (String) -> String
8
+
9
+ def cookie_domain?: (domain, ?bool?) -> bool
10
+
11
+ def self.new: (domain) -> untyped
12
+
13
+ private
14
+
15
+ def initialize: (string) -> untyped
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module HTTPX
2
+ Error: singleton(StandardError)
3
+ end
@@ -0,0 +1,45 @@
1
+ module HTTPX
2
+ class Headers
3
+ include _ToS
4
+
5
+ @headers: headers_hash
6
+
7
+ def self.new: (?untyped headers) -> Headers
8
+
9
+ def ==: (untyped other) -> bool
10
+
11
+ def []: (headers_key field) -> _ToS?
12
+ def []=: (headers_key field, headers_value value) -> void
13
+
14
+ def add: (headers_key field, string value) -> void
15
+ def delete: (headers_key field) -> void
16
+
17
+ def each: () { (headers_key, String) -> void } -> void
18
+ | () -> Enumerable[[headers_key, String], void]
19
+
20
+ def get: (headers_key field) -> Array[String]
21
+ def key?: (headers_key downcased_key) -> bool
22
+
23
+ def merge: (_Each[headers_key, headers_value] other) -> Headers
24
+
25
+ def same_headers?: (untyped headers) -> bool
26
+
27
+ def to_a: () -> Array[[headers_key, String]]
28
+ def to_hash: () -> Hash[headers_key, String]
29
+ alias to_h to_hash
30
+
31
+ def inspect: () -> String
32
+
33
+ private
34
+
35
+ def initialize: (headers?) -> untyped
36
+ def array_value: (headers_value) -> Array[String]
37
+ def downcased: (headers_key) -> String
38
+ end
39
+
40
+ type headers_key = String | Symbol
41
+ type headers_value = _ToS | Array[_ToS]
42
+ type headers_hash = Hash[headers_key, headers_value]
43
+ type headers_input = headers_hash | Array[[headers_key, string]]
44
+ type headers = Headers | headers_input
45
+ end
@@ -0,0 +1,15 @@
1
+ module HTTPX
2
+ extend Chainable
3
+
4
+ VERSION: String
5
+
6
+ type uri = URI::HTTP | URI::HTTPS | string
7
+ type generic_uri = uri | URI::Generic
8
+
9
+ type verb = :options | :get | :head | :post | :put | :delete | :trace | :connect |
10
+ :propfind | :proppatch | :mkcol | :copy | :move | :lock | :unlock | :orderpatch |
11
+ :acl | :report | :patch | :search
12
+
13
+ module Plugins
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module HTTPX
2
+ interface _IOLogger
3
+ def <<: (string?) -> void
4
+ end
5
+
6
+ module Loggable
7
+ def log: (?level: Integer?, ?color: Symbol?) { () -> String } -> void
8
+
9
+ def log_exception: (StandardError, **untyped) -> void
10
+ end
11
+ end
@@ -0,0 +1,118 @@
1
+ module HTTPX
2
+ class Options
3
+ # include _ToHash
4
+
5
+ WINDOW_SIZE: Integer
6
+ MAX_BODY_THRESHOLD_SIZE: Integer
7
+
8
+ def self.new: (options) -> instance
9
+ | () -> instance
10
+
11
+ # headers
12
+ attr_reader headers: Headers?
13
+ def headers=: (headers) -> void
14
+ def with_headers: (headers) -> instance
15
+
16
+ # timeout
17
+ attr_reader timeout: Timeout?
18
+ def timeout=: (Hash[Symbol, untyped] | Timeout) -> void
19
+ def with_timeout: (Hash[Symbol, untyped] | Timeout) -> instance
20
+
21
+ # max_concurrent_requests
22
+ attr_reader max_concurrent_requests: Integer?
23
+ def max_concurrent_requests=: (Integer) -> void
24
+ def with_max_concurrent_requests: (Integer) -> instance
25
+
26
+ # max_requests
27
+ attr_reader max_requests: Integer?
28
+ def max_requests=: (Integer) -> void
29
+ def with_max_requests: (Integer) -> instance
30
+
31
+ # window_size
32
+ attr_reader window_size: int?
33
+ def window_size=: (int) -> void
34
+ def with_window_size: (int) -> instance
35
+
36
+ # body_threshold_size
37
+ attr_reader body_threshold_size: int?
38
+ def body_threshold_size=: (int) -> void
39
+ def with_body_threshold_size: (int) -> instance
40
+
41
+ # transport
42
+ attr_reader transport: _ToS?
43
+ def transport=: (_ToS) -> void
44
+ def with_transport: (_ToS) -> instance
45
+
46
+ # transport_options
47
+ attr_reader transport_options: Hash[untyped, untyped]?
48
+ def transport_options=: (Hash[untyped, untyped]) -> void
49
+ def with_transport_options: (Hash[untyped, untyped]) -> instance
50
+
51
+ # params
52
+ attr_reader params: Transcoder::urlencoded_input?
53
+ def params=: (Transcoder::urlencoded_input) -> void
54
+ def with_params: (Transcoder::urlencoded_input) -> instance
55
+
56
+ # form
57
+ attr_reader form: Transcoder::urlencoded_input?
58
+ def form=: (Transcoder::urlencoded_input) -> void
59
+ def with_form: (Transcoder::urlencoded_input) -> instance
60
+
61
+ # json
62
+ attr_reader json: _ToJson?
63
+ def json=: (_ToJson) -> void
64
+ def with_json: (_ToJson) -> instance
65
+
66
+ # body
67
+ attr_reader body: bodyIO?
68
+ def body=: (bodyIO) -> void
69
+ def with_body: (bodyIO) -> instance
70
+
71
+ # ssl
72
+
73
+ # http2_settings
74
+
75
+ # request_class response_class headers_class request_body_class
76
+ # response_body_class connection_class
77
+ # resolver_class resolver_options
78
+
79
+ # request_class
80
+ attr_reader request_class: singleton(Request)
81
+ def request_class=: (singleton(Request)) -> void
82
+ def with_request_class: (singleton(Request)) -> instance
83
+
84
+ # io
85
+ attr_reader io: _ToIO?
86
+ def io=: (_ToIO) -> void
87
+ def with_io: (_ToIO) -> instance
88
+
89
+ # fallback_protocol
90
+ attr_reader fallback_protocol: String?
91
+ def fallback_protocol=: (String) -> void
92
+ def with_fallback_protocol: (String) -> instance
93
+
94
+ # debug
95
+ attr_reader debug: _IOLogger?
96
+ def debug=: (_IOLogger) -> void
97
+ def with_debug: (_IOLogger) -> instance
98
+
99
+ # debug_level
100
+ attr_reader debug_level: Integer?
101
+ def debug_level=: (Integer) -> void
102
+ def with_debug_level: (Integer) -> instance
103
+
104
+ # persistent
105
+ attr_reader persistent: bool?
106
+ def persistent=: (bool) -> void
107
+ def with_persistent: (bool) -> instance
108
+
109
+ def ==: (untyped other) -> bool
110
+ def merge: (_ToHash other) -> instance
111
+
112
+ private
113
+
114
+ def initialize: (options) -> untyped
115
+ end
116
+
117
+ type options = Options | Hash[Symbol | String, untyped]
118
+ end