httpx 1.7.0 → 1.7.2

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes/1_7_1.md +21 -0
  3. data/doc/release_notes/1_7_2.md +6 -0
  4. data/lib/httpx/adapters/webmock.rb +18 -9
  5. data/lib/httpx/altsvc.rb +1 -1
  6. data/lib/httpx/connection/http1.rb +4 -3
  7. data/lib/httpx/connection.rb +4 -1
  8. data/lib/httpx/io/tcp.rb +1 -1
  9. data/lib/httpx/options.rb +78 -5
  10. data/lib/httpx/parser/http1.rb +1 -0
  11. data/lib/httpx/plugins/auth.rb +49 -4
  12. data/lib/httpx/plugins/ntlm_auth.rb +1 -1
  13. data/lib/httpx/plugins/oauth.rb +11 -18
  14. data/lib/httpx/plugins/persistent.rb +3 -5
  15. data/lib/httpx/plugins/proxy/http.rb +0 -4
  16. data/lib/httpx/plugins/proxy.rb +3 -1
  17. data/lib/httpx/plugins/query.rb +1 -1
  18. data/lib/httpx/plugins/rate_limiter.rb +20 -15
  19. data/lib/httpx/plugins/retries.rb +8 -11
  20. data/lib/httpx/plugins/stream.rb +2 -2
  21. data/lib/httpx/plugins/stream_bidi.rb +24 -2
  22. data/lib/httpx/pool.rb +0 -1
  23. data/lib/httpx/request/body.rb +1 -1
  24. data/lib/httpx/resolver/cache/base.rb +136 -0
  25. data/lib/httpx/resolver/cache/memory.rb +42 -0
  26. data/lib/httpx/resolver/cache.rb +18 -0
  27. data/lib/httpx/resolver/https.rb +7 -3
  28. data/lib/httpx/resolver/multi.rb +7 -3
  29. data/lib/httpx/resolver/native.rb +6 -2
  30. data/lib/httpx/resolver/resolver.rb +1 -1
  31. data/lib/httpx/resolver.rb +3 -149
  32. data/lib/httpx/response/body.rb +3 -3
  33. data/lib/httpx/selector.rb +5 -3
  34. data/lib/httpx/session.rb +1 -1
  35. data/lib/httpx/timers.rb +6 -12
  36. data/lib/httpx/transcoder/gzip.rb +7 -2
  37. data/lib/httpx/transcoder/multipart/decoder.rb +1 -1
  38. data/lib/httpx/transcoder/multipart.rb +1 -1
  39. data/lib/httpx/utils.rb +13 -0
  40. data/lib/httpx/version.rb +1 -1
  41. data/sig/altsvc.rbs +7 -4
  42. data/sig/loggable.rbs +1 -1
  43. data/sig/options.rbs +11 -3
  44. data/sig/plugins/auth.rbs +16 -1
  45. data/sig/plugins/oauth.rbs +0 -2
  46. data/sig/plugins/rate_limiter.rbs +4 -2
  47. data/sig/plugins/retries.rbs +4 -2
  48. data/sig/plugins/stream_bidi.rbs +3 -0
  49. data/sig/resolver/cache/base.rbs +28 -0
  50. data/sig/resolver/cache/memory.rbs +13 -0
  51. data/sig/resolver/cache.rbs +16 -0
  52. data/sig/resolver/https.rbs +19 -0
  53. data/sig/resolver/multi.rbs +6 -0
  54. data/sig/resolver.rbs +0 -24
  55. data/sig/timers.rbs +1 -1
  56. data/sig/utils.rbs +2 -0
  57. metadata +11 -1
@@ -12,7 +12,6 @@ module HTTPX
12
12
  def initialize(filename, content_type)
13
13
  @original_filename = filename
14
14
  @content_type = content_type
15
- @current = nil
16
15
  @file = Tempfile.new("httpx", encoding: Encoding::BINARY, mode: File::RDWR)
17
16
  super(@file)
18
17
  end
@@ -39,6 +38,7 @@ module HTTPX
39
38
  @parts = {}
40
39
  @intermediate_boundary = "--#{@boundary}"
41
40
  @state = :idle
41
+ @current = nil
42
42
  end
43
43
 
44
44
  def call(response, *)
@@ -19,7 +19,7 @@ module HTTPX::Transcoder
19
19
 
20
20
  def multipart_value?(value)
21
21
  value.respond_to?(:read) ||
22
- (value.respond_to?(:to_hash) &&
22
+ (value.is_a?(Hash) &&
23
23
  value.key?(:body) &&
24
24
  (value.key?(:filename) || value.key?(:content_type)))
25
25
  end
data/lib/httpx/utils.rb CHANGED
@@ -71,5 +71,18 @@ module HTTPX
71
71
  uri.non_ascii_hostname = non_ascii_hostname
72
72
  uri
73
73
  end
74
+
75
+ if defined?(Ractor) &&
76
+ # no ractor support for 3.0
77
+ RUBY_VERSION >= "3.1.0"
78
+
79
+ def in_ractor?
80
+ Ractor.main != Ractor.current
81
+ end
82
+ else
83
+ def in_ractor?
84
+ false
85
+ end
86
+ end
74
87
  end
75
88
  end
data/lib/httpx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPX
4
- VERSION = "1.7.0"
4
+ VERSION = "1.7.2"
5
5
  end
data/sig/altsvc.rbs CHANGED
@@ -5,19 +5,22 @@ module HTTPX
5
5
 
6
6
  def send: (Request request) -> void
7
7
 
8
- def match?: (URI::Generic uri, Options options) -> bool
8
+ def match?: (http_uri uri, Options options) -> bool
9
9
 
10
10
  private
11
11
 
12
- def match_altsvcs?: (URI::Generic uri) -> bool
12
+ def match_altsvcs?: (http_uri uri) -> bool
13
13
 
14
- def match_altsvc_options?: (URI::Generic uri, Options options) -> bool
14
+ def match_altsvc_options?: (http_uri uri, Options options) -> bool
15
15
 
16
- def altsvc_match?: (uri uri, uri other_uri) -> bool
16
+ def altsvc_match?: (http_uri uri, uri other_uri) -> bool
17
17
  end
18
18
 
19
19
  type altsvc_params = Hash[String, untyped]
20
20
 
21
+ self.@altsvc_mutex: Thread::Mutex
22
+ self.@altsvcs: Hash[String, Array[altsvc_params]]
23
+
21
24
  def self?.cached_altsvc: (String origin) -> Array[altsvc_params]
22
25
 
23
26
  def self?.cached_altsvc_set: (String origin, altsvc_params) -> void
data/sig/loggable.rbs CHANGED
@@ -4,7 +4,7 @@ module HTTPX
4
4
  end
5
5
 
6
6
  module Loggable
7
- USE_DEBUG_LOGS: bool
7
+ USE_DEBUG_LOG: bool
8
8
 
9
9
  COLORS: Hash[Symbol, Integer]
10
10
 
data/sig/options.rbs CHANGED
@@ -17,11 +17,13 @@ module HTTPX
17
17
 
18
18
  DEFAULT_OPTIONS: Hash[Symbol, untyped]
19
19
  REQUEST_BODY_IVARS: Array[Symbol]
20
+ RESOLVER_TYPES: Array[Symbol]
20
21
  USER_AGENT: String
21
22
 
22
23
  type timeout_type = :connect_timeout | :settings_timeout | :close_handshake_timeout | :operation_timeout | :keep_alive_timeout | :read_timeout | :write_timeout | :request_timeout
23
24
  type timeout = Hash[timeout_type, Numeric?]
24
25
  type redact_value = :headers | :body | bool
26
+ type resolver_cache_option = :memory | :file | (Object & Resolver::_Cache)
25
27
 
26
28
  def self.new: (?options) -> instance
27
29
 
@@ -102,8 +104,6 @@ module HTTPX
102
104
 
103
105
  attr_reader options_class: singleton(Options)
104
106
 
105
- attr_reader resolver_class: Symbol | singleton(Resolver::Resolver)
106
-
107
107
  attr_reader ssl: Hash[Symbol, untyped]
108
108
 
109
109
  # io
@@ -134,6 +134,12 @@ module HTTPX
134
134
  # ip_families
135
135
  attr_reader ip_families: Array[ip_family]?
136
136
 
137
+ @resolver_cache: resolver_cache_option
138
+
139
+ def resolver_class: () -> singleton(Resolver::Resolver)
140
+
141
+ def resolver_cache: () -> (Object & Resolver::_Cache)
142
+
137
143
  def ==: (Options other) -> bool
138
144
 
139
145
  def options_equals?: (Options other, ?Array[Symbol] ignore_ivars) -> bool
@@ -148,7 +154,7 @@ module HTTPX
148
154
 
149
155
  def initialize: (?options options) -> void
150
156
 
151
- def do_initialize: (?options options) -> void
157
+ def do_initialize: () -> void
152
158
 
153
159
  def access_option: (Hash[Symbol, untyped] | Object | nil obj, Symbol k, Hash[Symbol, Symbol]? ivar_map) -> untyped
154
160
 
@@ -185,6 +191,8 @@ module HTTPX
185
191
  def option_persistent: (bool value) -> bool
186
192
  def option_close_on_fork: (bool value) -> bool
187
193
 
194
+ def option_resolver_cache: (resolver_cache_option value) -> resolver_cache_option
195
+
188
196
  def option_origin: (http_uri | String value) -> http_uri
189
197
 
190
198
  def option_base_path: (_ToStr value) -> String
data/sig/plugins/auth.rbs CHANGED
@@ -1,8 +1,10 @@
1
1
  module HTTPX
2
2
  module Plugins
3
3
  module Auth
4
+ type auth_header_value_type = String | ^(Request request) -> string
5
+
4
6
  interface _AuthOptions
5
- def auth_header_value: () -> (String | ^(Request request) -> string)?
7
+ def auth_header_value: () -> auth_header_value_type?
6
8
 
7
9
  def auth_header_type: () -> String?
8
10
  end
@@ -22,13 +24,26 @@ module HTTPX
22
24
  private
23
25
 
24
26
  def generate_auth_token: () -> String?
27
+
28
+ def dynamic_auth_token?: (auth_header_value_type auth_header_value) -> boolish
25
29
  end
26
30
 
27
31
  module RequestMethods
32
+ @auth_token_value: String?
33
+
34
+ def authorized?: () -> bool
35
+
36
+ def unauthorize!: () -> void
37
+
28
38
  def authorize: (String auth_value) -> void
29
39
  end
30
40
 
31
41
  module AuthRetries
42
+ module InstanceMethods
43
+ private
44
+
45
+ def auth_error?: (response response, Options options) -> boolish
46
+ end
32
47
  end
33
48
  end
34
49
 
@@ -87,8 +87,6 @@ module HTTPX
87
87
  end
88
88
 
89
89
  module OAuthRetries
90
- def self?.response_oauth_error?: (response res) -> bool
91
-
92
90
  module InstanceMethods
93
91
  end
94
92
  end
@@ -5,9 +5,11 @@ module HTTPX
5
5
 
6
6
  def self.load_dependencies: (singleton(Session)) -> void
7
7
 
8
- def self.retry_on_rate_limited_response?: (_Response) -> bool
9
-
10
8
  def self.retry_after_rate_limit: (untyped, response) -> Numeric?
9
+
10
+ module InstanceMethods
11
+ def rate_limit_error?: (response response) -> bool
12
+ end
11
13
  end
12
14
  end
13
15
  end
@@ -37,9 +37,11 @@ module HTTPX
37
37
 
38
38
  def fetch_response: (retriesRequest request, Selector selector, retriesOptions options) -> (retriesResponse | ErrorResponse)?
39
39
 
40
- def repeatable_request?: (retriesRequest request, retriesOptions options) -> boolish
40
+ def retryable_request?: (retriesRequest request, response response, retriesOptions options) -> boolish
41
41
 
42
- def retryable_error?: (_Exception error) -> bool
42
+ def retryable_response?: (response response, retriesOptions options) -> boolish
43
+
44
+ def retryable_error?: (_Exception error, Options options) -> boolish
43
45
 
44
46
  def try_partial_retry: (retriesRequest request, (retriesResponse | ErrorResponse) response) -> void
45
47
 
@@ -47,8 +47,11 @@ module HTTPX
47
47
  attr_accessor headers_sent: bool
48
48
 
49
49
  @closed: bool
50
+ @flush_buffer_on_body_cb: ^() -> void | nil
50
51
  @mutex: Thread::Mutex
51
52
 
53
+ def flush_buffer_on_body: { () -> void } -> void
54
+
52
55
  def closed?: () -> bool
53
56
  end
54
57
 
@@ -0,0 +1,28 @@
1
+ module HTTPX
2
+ module Resolver
3
+ class Cache::Base
4
+ include _Cache
5
+
6
+ MAX_CACHE_SIZE: Integer
7
+
8
+ CACHE_MUTEX: Thread::Mutex
9
+ HOSTS: Resolv::Hosts
10
+
11
+ self.@cache: instance?
12
+
13
+ def self.cache: (Symbol label) -> instance
14
+
15
+ private
16
+
17
+ def ip_resolve: (String hostname) -> Array[Entry]?
18
+
19
+ def hosts_resolve: (String hostname) -> Array[Entry]?
20
+
21
+ def _get: (String hostname, Hash[String, Array[dns_result]] lookups, Array[String] hostnames, Numeric ttl) -> Array[Entry]?
22
+
23
+ def _set: (String hostname, ip_family family, Array[dns_result] entries, Hash[String, Array[dns_result]] lookups, Array[String] hostnames) -> void
24
+
25
+ def _evict: (String hostname, String ip, Hash[String, Array[dns_result]] lookups, Array[String] hostnames) -> void
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ module HTTPX::Resolver
2
+ module Cache
3
+ class Memory < Base
4
+ @lookup_mutex: Thread::Mutex
5
+ @hostnames: Array[String]
6
+ @lookups: Hash[String, Array[dns_result]]
7
+
8
+ private
9
+
10
+ def synchronize: [U] () { (Hash[String, Array[dns_result]] lookups, Array[String] hostnames) -> U } -> U
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module HTTPX
2
+ module Resolver
3
+ module Cache
4
+ end
5
+
6
+ interface _Cache
7
+ def resolve: (String hostname) -> Array[Entry]?
8
+
9
+ def get: (String hostname) -> Array[Entry]?
10
+
11
+ def set: (String hostname, ip_family family, Array[dns_result] addresses) -> void
12
+
13
+ def evict: (String hostname, _ToS ip) -> void
14
+ end
15
+ end
16
+ end
@@ -26,6 +26,25 @@ module HTTPX
26
26
 
27
27
  def <<: (Connection) -> void
28
28
 
29
+ # delegated to resolver connection
30
+ def connecting?: () -> bool
31
+
32
+ def to_io: () -> IO
33
+
34
+ def call: () -> void
35
+
36
+ def close: () -> void
37
+
38
+ # def closed?: () -> bool
39
+
40
+ def deactivate: () -> void
41
+
42
+ def terminate: () -> void
43
+
44
+ def inflight?: () -> bool
45
+
46
+ def handle_socket_timeout: (Numeric interval) -> void
47
+
29
48
  private
30
49
 
31
50
  def initialize: (ip_family family, options options) -> void
@@ -20,6 +20,12 @@ module HTTPX
20
20
  def early_resolve: (Connection connection) -> bool
21
21
 
22
22
  def lazy_resolve: (Connection connection) -> void
23
+
24
+ private
25
+
26
+ def nolookup_resolve: (String hostname, Options options) -> Array[Entry]?
27
+
28
+ def initialize: (singleton(Native) | singleton(HTTPS) resolver_type, Options options) -> void
23
29
  end
24
30
  end
25
31
  end
data/sig/resolver.rbs CHANGED
@@ -8,11 +8,7 @@ module HTTPX
8
8
  | { "name" => String, "TTL" => Numeric, "data" => String }
9
9
 
10
10
  RESOLVE_TIMEOUT: Array[Integer]
11
- MAX_CACHE_SIZE: Integer
12
11
 
13
- self.@lookup_mutex: Thread::Mutex
14
- self.@hostnames: Array[String]
15
- self.@lookups: Hash[String, Array[dns_result]]
16
12
  self.@identifier_mutex: Thread::Mutex
17
13
  self.@identifier: Integer
18
14
  self.@hosts_resolver: Resolv::Hosts
@@ -20,24 +16,8 @@ module HTTPX
20
16
 
21
17
  type dns_decoding_response = [:ok, Array[dns_result]] | [:decode_error, Resolv::DNS::DecodeError] | [:retriable_error | :dns_error, Integer] | Symbol
22
18
 
23
- def self?.nolookup_resolve: (String hostname) -> Array[Entry]?
24
-
25
- def self?.ip_resolve: (String hostname) -> Array[Entry]?
26
-
27
- def self?.hosts_resolve: (String hostname) -> Array[Entry]?
28
-
29
19
  def self?.supported_ip_families: () -> Array[ip_family]
30
20
 
31
- def self?.resolver_for: (Symbol | singleton(Resolver) resolver_type, Options options) -> singleton(Resolver)
32
-
33
- def self?.cached_lookup: (String hostname) -> Array[Entry]?
34
-
35
- def self?.cached_lookup_set: (String hostname, ip_family family, Array[dns_result] addresses) -> void
36
-
37
- def self?.cached_lookup_evict: (String hostname, _ToS ip) -> void
38
-
39
- def self?.lookup: (String hostname, Hash[String, Array[dns_result]] lookups, Array[String] hostnames, Numeric ttl) -> Array[Entry]?
40
-
41
21
  def self?.generate_id: () -> Integer
42
22
 
43
23
  def self?.encode_dns_query: (String hostname, ?type: dns_resource, ?message_id: Integer) -> String
@@ -46,12 +26,8 @@ module HTTPX
46
26
 
47
27
  private
48
28
 
49
- def self?.lookup_synchronize: [U] () { (Hash[String, Array[dns_result]] lookups, Array[String] hostnames) -> U } -> U
50
-
51
29
  def self?.id_synchronize: () { () -> void } -> void
52
30
 
53
- def in_ractor?: () -> bool
54
-
55
31
  def find_supported_ip_families: () -> Array[Integer]
56
32
  end
57
33
  end
data/sig/timers.rbs CHANGED
@@ -16,7 +16,7 @@ module HTTPX
16
16
 
17
17
  private
18
18
 
19
- def drop_elapsed!: (?Numeric elapsed_time) -> void
19
+ def drop_elapsed!: (Numeric elapsed_time) -> void
20
20
 
21
21
  class Interval
22
22
  include Comparable
data/sig/utils.rbs CHANGED
@@ -15,5 +15,7 @@ module HTTPX
15
15
  def self?.to_uri: (generic_uri uri) -> URI::Generic
16
16
 
17
17
  def self?.get_filename: (String header) -> String?
18
+
19
+ def self?.in_ractor?: () -> bool
18
20
  end
19
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
@@ -160,6 +160,8 @@ extra_rdoc_files:
160
160
  - doc/release_notes/1_6_2.md
161
161
  - doc/release_notes/1_6_3.md
162
162
  - doc/release_notes/1_7_0.md
163
+ - doc/release_notes/1_7_1.md
164
+ - doc/release_notes/1_7_2.md
163
165
  files:
164
166
  - LICENSE.txt
165
167
  - README.md
@@ -292,6 +294,8 @@ files:
292
294
  - doc/release_notes/1_6_2.md
293
295
  - doc/release_notes/1_6_3.md
294
296
  - doc/release_notes/1_7_0.md
297
+ - doc/release_notes/1_7_1.md
298
+ - doc/release_notes/1_7_2.md
295
299
  - lib/httpx.rb
296
300
  - lib/httpx/adapters/datadog.rb
297
301
  - lib/httpx/adapters/faraday.rb
@@ -373,6 +377,9 @@ files:
373
377
  - lib/httpx/request.rb
374
378
  - lib/httpx/request/body.rb
375
379
  - lib/httpx/resolver.rb
380
+ - lib/httpx/resolver/cache.rb
381
+ - lib/httpx/resolver/cache/base.rb
382
+ - lib/httpx/resolver/cache/memory.rb
376
383
  - lib/httpx/resolver/entry.rb
377
384
  - lib/httpx/resolver/https.rb
378
385
  - lib/httpx/resolver/multi.rb
@@ -474,6 +481,9 @@ files:
474
481
  - sig/request.rbs
475
482
  - sig/request/body.rbs
476
483
  - sig/resolver.rbs
484
+ - sig/resolver/cache.rbs
485
+ - sig/resolver/cache/base.rbs
486
+ - sig/resolver/cache/memory.rbs
477
487
  - sig/resolver/entry.rbs
478
488
  - sig/resolver/https.rbs
479
489
  - sig/resolver/multi.rbs