httpx 0.9.0 → 0.10.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 (96) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +48 -0
  3. data/README.md +2 -0
  4. data/doc/release_notes/0_10_0.md +66 -0
  5. data/lib/httpx.rb +2 -0
  6. data/lib/httpx/adapters/faraday.rb +1 -1
  7. data/lib/httpx/chainable.rb +2 -2
  8. data/lib/httpx/connection.rb +3 -9
  9. data/lib/httpx/connection/http1.rb +1 -1
  10. data/lib/httpx/domain_name.rb +440 -0
  11. data/lib/httpx/errors.rb +1 -0
  12. data/lib/httpx/extensions.rb +21 -1
  13. data/lib/httpx/io/ssl.rb +0 -1
  14. data/lib/httpx/io/tcp.rb +6 -5
  15. data/lib/httpx/io/udp.rb +4 -1
  16. data/lib/httpx/options.rb +2 -0
  17. data/lib/httpx/parser/http1.rb +14 -17
  18. data/lib/httpx/plugins/compression.rb +28 -63
  19. data/lib/httpx/plugins/compression/brotli.rb +10 -14
  20. data/lib/httpx/plugins/compression/deflate.rb +7 -6
  21. data/lib/httpx/plugins/compression/gzip.rb +23 -5
  22. data/lib/httpx/plugins/cookies.rb +21 -60
  23. data/lib/httpx/plugins/cookies/cookie.rb +173 -0
  24. data/lib/httpx/plugins/cookies/jar.rb +74 -0
  25. data/lib/httpx/plugins/cookies/set_cookie_parser.rb +142 -0
  26. data/lib/httpx/plugins/expect.rb +3 -5
  27. data/lib/httpx/plugins/follow_redirects.rb +20 -2
  28. data/lib/httpx/plugins/h2c.rb +1 -1
  29. data/lib/httpx/plugins/multipart.rb +0 -8
  30. data/lib/httpx/plugins/persistent.rb +6 -1
  31. data/lib/httpx/plugins/proxy/socks4.rb +3 -1
  32. data/lib/httpx/plugins/rate_limiter.rb +51 -0
  33. data/lib/httpx/plugins/retries.rb +3 -2
  34. data/lib/httpx/plugins/stream.rb +109 -13
  35. data/lib/httpx/pool.rb +6 -6
  36. data/lib/httpx/request.rb +7 -19
  37. data/lib/httpx/resolver/https.rb +7 -2
  38. data/lib/httpx/resolver/native.rb +7 -3
  39. data/lib/httpx/response.rb +16 -23
  40. data/lib/httpx/selector.rb +2 -4
  41. data/lib/httpx/session.rb +17 -11
  42. data/lib/httpx/transcoder/chunker.rb +0 -2
  43. data/lib/httpx/transcoder/form.rb +0 -6
  44. data/lib/httpx/transcoder/json.rb +0 -4
  45. data/lib/httpx/utils.rb +45 -0
  46. data/lib/httpx/version.rb +1 -1
  47. data/sig/buffer.rbs +24 -0
  48. data/sig/callbacks.rbs +14 -0
  49. data/sig/chainable.rbs +37 -0
  50. data/sig/connection.rbs +2 -0
  51. data/sig/connection/http2.rbs +4 -0
  52. data/sig/domain_name.rbs +17 -0
  53. data/sig/errors.rbs +3 -0
  54. data/sig/headers.rbs +42 -0
  55. data/sig/httpx.rbs +14 -0
  56. data/sig/loggable.rbs +11 -0
  57. data/sig/missing.rbs +12 -0
  58. data/sig/options.rbs +118 -0
  59. data/sig/parser/http1.rbs +50 -0
  60. data/sig/plugins/authentication.rbs +11 -0
  61. data/sig/plugins/basic_authentication.rbs +13 -0
  62. data/sig/plugins/compression.rbs +55 -0
  63. data/sig/plugins/compression/brotli.rbs +21 -0
  64. data/sig/plugins/compression/deflate.rbs +17 -0
  65. data/sig/plugins/compression/gzip.rbs +29 -0
  66. data/sig/plugins/cookies.rbs +26 -0
  67. data/sig/plugins/cookies/cookie.rbs +50 -0
  68. data/sig/plugins/cookies/jar.rbs +27 -0
  69. data/sig/plugins/digest_authentication.rbs +33 -0
  70. data/sig/plugins/expect.rbs +19 -0
  71. data/sig/plugins/follow_redirects.rbs +37 -0
  72. data/sig/plugins/h2c.rbs +26 -0
  73. data/sig/plugins/multipart.rbs +19 -0
  74. data/sig/plugins/persistent.rbs +17 -0
  75. data/sig/plugins/proxy.rbs +47 -0
  76. data/sig/plugins/proxy/http.rbs +14 -0
  77. data/sig/plugins/proxy/socks4.rbs +33 -0
  78. data/sig/plugins/proxy/socks5.rbs +36 -0
  79. data/sig/plugins/proxy/ssh.rbs +18 -0
  80. data/sig/plugins/push_promise.rbs +22 -0
  81. data/sig/plugins/rate_limiter.rbs +11 -0
  82. data/sig/plugins/retries.rbs +48 -0
  83. data/sig/plugins/stream.rbs +39 -0
  84. data/sig/pool.rbs +2 -0
  85. data/sig/registry.rbs +9 -0
  86. data/sig/request.rbs +61 -0
  87. data/sig/response.rbs +87 -0
  88. data/sig/session.rbs +49 -0
  89. data/sig/test.rbs +9 -0
  90. data/sig/timeout.rbs +29 -0
  91. data/sig/transcoder.rbs +16 -0
  92. data/sig/transcoder/body.rbs +18 -0
  93. data/sig/transcoder/chunker.rbs +32 -0
  94. data/sig/transcoder/form.rbs +16 -0
  95. data/sig/transcoder/json.rbs +14 -0
  96. metadata +60 -17
@@ -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,12 @@
1
+ # defining these here, as I don't think there's hope of http-cookie to ever become type-friendly
2
+ module HTTP
3
+ class Cookie
4
+ end
5
+ class CookieJar
6
+ end
7
+ end
8
+
9
+ module HTTP2Next
10
+ class Stream
11
+ end
12
+ 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
@@ -0,0 +1,50 @@
1
+ module HTTPX
2
+ module Parser
3
+ type parsed_headers = Hash[String, Array[String]]
4
+
5
+ interface _HTTP1Events
6
+
7
+ def on_start: () -> void
8
+ def on_headers: (parsed_headers) -> void
9
+ def on_trailers: (parsed_headers) -> void
10
+ def on_data: (String) -> void
11
+ def on_complete: () -> void
12
+ end
13
+
14
+ class HTTP1
15
+ VERSIONS: Array[String]
16
+
17
+ def <<: (String chunk) -> void
18
+
19
+ def headers: () -> parsed_headers
20
+
21
+ def http_version: () -> Array[1 | 0]
22
+
23
+ def reset!: () -> void
24
+
25
+ def status_code: () -> Integer
26
+
27
+ def upgrade?: () -> bool
28
+
29
+ def upgrade_data: () -> String
30
+
31
+ private
32
+
33
+ def initialize: (_HTTP1Events observer) -> untyped
34
+
35
+ def nextstate: (Symbol state) -> void
36
+
37
+ def no_more_data?: () -> bool
38
+
39
+ def parse: () -> void
40
+
41
+ def parse_data: () -> void
42
+
43
+ def parse_headers: () -> void
44
+
45
+ def parse_headline: () -> void
46
+
47
+ def prepare_data: (parsed_headers headers) -> void
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ module HTTPX
2
+ module Plugins
3
+ module Authentication
4
+ module InstanceMethods
5
+ def authentication: (string token) -> instance
6
+ end
7
+ end
8
+
9
+ type sessionAuthentication = Session & Plugins::Authentication::InstanceMethods
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module HTTPX
2
+ module Plugins
3
+ module BasicAuthentication
4
+ # def self.load_dependencies: (singleton(Session)) -> void
5
+
6
+ module InstanceMethods
7
+ def basic_authentication: (string user, string password) -> instance
8
+ end
9
+ end
10
+
11
+ type sessionBasicAuthentication = Plugins::sessionAuthentication & Plugins::Authentication::InstanceMethods
12
+ end
13
+ end
@@ -0,0 +1,55 @@
1
+ module HTTPX
2
+ module Plugins
3
+ module Compression
4
+ extend Registry[Symbol, Class]
5
+
6
+ type deflatable = _Reader | _ToS
7
+
8
+ interface _Deflater
9
+ def deflate: (deflatable, _Writer, chunk_size: Integer) -> void
10
+ | (deflatable, _Writer, chunk_size: Integer) { (String) -> void } -> void
11
+ end
12
+
13
+ interface _Inflater
14
+ def inflate: (string) -> String
15
+
16
+ def initialize: (Numeric bytesize) -> untyped
17
+ end
18
+
19
+ # def self.load_dependencies: (singleton(Session)) -> void
20
+
21
+ interface _CompressionOptions
22
+ def compression_threshold_size: () -> _Integer?
23
+ def compression_threshold_size=: (int) -> int
24
+ def with_compression_threshold_size: (int) -> instance
25
+ end
26
+
27
+ def self.extra_options: (Options) -> (Options & _CompressionOptions)
28
+
29
+
30
+ module ResponseBodyMethods
31
+ @encodings: Array[String]
32
+ @_deflaters: Array[_Decoder]
33
+
34
+ private
35
+
36
+ def decompress: (string) -> String
37
+ end
38
+
39
+ class Encoder
40
+ include Transcoder::_Encoder
41
+ include _ToS
42
+ include _Each[String]
43
+
44
+ def close: () -> void
45
+
46
+ private
47
+
48
+ def initialize: (deflatable body, _Deflater deflater) -> untyped
49
+ def deflate: () -> void
50
+ | () { (String) -> void } -> void
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ module HTTPX
2
+ module Plugins
3
+ module Compression
4
+ module Brotli
5
+ # def self.load_dependencies: (singleton(Session)) -> void
6
+ def self.configure: (*untyped) -> void
7
+
8
+ def self?.deflater: () -> _Deflater
9
+ def self?.decoder: (Numeric bytesize) -> Inflater
10
+
11
+ module Deflater
12
+ extend _Deflater
13
+ end
14
+
15
+ class Inflater
16
+ include _Inflater
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module HTTPX
2
+ module Plugins
3
+ module Compression
4
+ module Deflate
5
+ # def self.load_dependencies: (singleton(Session)) -> void
6
+ def self.configure: (*untyped) -> void
7
+
8
+ def self?.deflater: () -> _Deflater
9
+ def self?.inflater: (Numeric bytesize) -> GZIP::Inflater
10
+
11
+ module Deflater
12
+ extend _Deflater
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ module HTTPX
2
+ module Plugins
3
+ module Compression
4
+ module GZIP
5
+ # def self.load_dependencies: (singleton(Session)) -> void
6
+ def self.configure: (*untyped) -> void
7
+
8
+ def self?.deflater: () -> _Deflater
9
+ def self?.inflater: (Numeric bytesize) -> Inflater
10
+
11
+ class Deflater
12
+ include _Deflater
13
+
14
+ @compressed_chunk: String
15
+
16
+ private
17
+
18
+ def initialize: () -> untyped
19
+ def write: (string) -> void
20
+ def compressed_chunk: () -> String
21
+ end
22
+
23
+ class Inflater
24
+ include _Inflater
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ module HTTPX
2
+ module Plugins
3
+ module Cookies
4
+ type jar = Jar | _Each[cookies]
5
+
6
+ interface _CookieOptions
7
+ def cookies: () -> Jar?
8
+ def cookies=: (jar) -> Jar
9
+ def with_cookies: (jar) -> instance
10
+ end
11
+
12
+ def self.extra_options: (Options) -> (Options & _CookieOptions)
13
+
14
+ module InstanceMethods
15
+ def cookies: () -> Jar
16
+ end
17
+
18
+ module HeadersMethods
19
+ def set_cookie: (Array[Cookie]) -> void
20
+ end
21
+ end
22
+
23
+ type sessionCookies = Session & Plugins::Cookies::InstanceMethods
24
+ type headersCookies = Headers & Plugins::Cookies::HeadersMethods
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ module HTTPX
2
+ module Plugins::Cookies
3
+ type cookie_attributes = Hash[Symbol | String, top]
4
+
5
+ class Cookie
6
+ include Comparable
7
+
8
+ MAX_LENGTH: Integer
9
+
10
+ attr_reader domain: DomainName?
11
+
12
+ attr_reader path: String
13
+
14
+ attr_reader name: String
15
+
16
+ attr_reader value: String?
17
+
18
+ attr_reader created_at: Time
19
+
20
+ def path=: (string) -> void
21
+
22
+ def domain=: (string) -> void
23
+
24
+ def expires: () -> Time?
25
+
26
+ def expired?: () -> bool
27
+ | (Time) -> bool
28
+
29
+ def cookie_value: () -> String
30
+ alias to_s cookie_value
31
+
32
+ def valid_for_uri?: (uri) -> bool
33
+
34
+ def self.new: (Cookie) -> untyped
35
+ | (cookie_attributes) -> untyped
36
+ | (String, String) -> untyped
37
+ | (String, String, cookie_attributes) -> untyped
38
+
39
+ def self.path_match?: (String, String) -> bool
40
+
41
+ private
42
+
43
+ def initialize: (cookie_attributes) -> untyped
44
+ | (String, String) -> untyped
45
+ | (String, String, cookie_attributes?) -> untyped
46
+
47
+ def acceptable_from_uri?: (uri) -> bool
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,27 @@
1
+ module HTTPX
2
+ module Plugins::Cookies
3
+ class Jar
4
+ type cookie = Cookie | Array[String, String, cookie_attributes] | Array[String, String] | cookie_attributes
5
+
6
+ include Enumerable[Cookie]
7
+
8
+ @cookies: Array[Cookie]
9
+
10
+ def parse: (String) -> void
11
+
12
+ def add: (Cookie) -> void
13
+ | (Cookie, String) -> void
14
+
15
+ def []: (uri) -> Array[Cookie]
16
+
17
+ def each: (uri) { (Cookie) -> void } -> void
18
+ | (uri) -> Enumerable[Cookie]
19
+ | () { (Cookie) -> void } -> void
20
+ | () -> Enumerable[Cookie]
21
+ private
22
+
23
+ def initialize: () -> void
24
+ | (_Each[cookie]) -> untyped
25
+ end
26
+ end
27
+ end