wreq 1.3.1 → 1.3.3

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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +495 -57
  3. data/Cargo.toml +18 -6
  4. data/README.md +1 -1
  5. data/crates/wreq-util/CHANGELOG.md +1 -0
  6. data/crates/wreq-util/Cargo.toml +3 -1
  7. data/crates/wreq-util/README.md +4 -2
  8. data/crates/wreq-util/examples/emulate.rs +7 -3
  9. data/crates/wreq-util/examples/tower_delay.rs +4 -4
  10. data/crates/wreq-util/src/emulate/macros.rs +0 -1
  11. data/crates/wreq-util/src/emulate/profile/chrome/http2.rs +3 -3
  12. data/crates/wreq-util/src/emulate/profile/chrome/tls.rs +17 -39
  13. data/crates/wreq-util/src/emulate/profile/chrome.rs +71 -0
  14. data/crates/wreq-util/src/emulate/profile/firefox/http2.rs +11 -11
  15. data/crates/wreq-util/src/emulate/profile/firefox/tls.rs +9 -14
  16. data/crates/wreq-util/src/emulate/profile/okhttp.rs +9 -15
  17. data/crates/wreq-util/src/emulate/profile/opera/http2.rs +3 -3
  18. data/crates/wreq-util/src/emulate/profile/opera/tls.rs +11 -5
  19. data/crates/wreq-util/src/emulate/profile/safari/tls.rs +14 -15
  20. data/crates/wreq-util/src/emulate/profile.rs +7 -9
  21. data/crates/wreq-util/src/emulate.rs +3 -1
  22. data/crates/wreq-util/src/tower/delay/layer.rs +5 -5
  23. data/crates/wreq-util/src/tower/delay.rs +4 -4
  24. data/crates/wreq-util/tests/client.rs +7 -3
  25. data/crates/wreq-util/tests/emulate_chrome.rs +20 -0
  26. data/crates/wreq-util/tests/emulate_firefox.rs +26 -21
  27. data/crates/wreq-util/tests/emulate_safari.rs +1 -1
  28. data/crates/wreq-util/tests/support/mod.rs +16 -13
  29. data/lib/wreq.rb +9 -9
  30. data/lib/wreq_ruby/client.rb +39 -25
  31. data/lib/wreq_ruby/emulate.rb +7 -2
  32. data/lib/wreq_ruby/http.rb +9 -2
  33. data/src/client.rs +8 -4
  34. data/src/emulate.rs +2 -0
  35. data/test/emulation_test.rb +3 -1
  36. data/test/option_validation_test.rb +13 -4
  37. metadata +1 -1
@@ -67,6 +67,8 @@ module Wreq
67
67
  Chrome153 = nil
68
68
  Chrome154 = nil
69
69
  Chrome155 = nil
70
+ Chrome156 = nil
71
+ Chrome157 = nil
70
72
 
71
73
  Edge101 = nil
72
74
  Edge122 = nil
@@ -265,9 +267,12 @@ module Wreq
265
267
  # for HTTP/2 and automatic default headers. The actual implementation is
266
268
  # provided by Rust.
267
269
  #
270
+ # Profiles configure TLS over TCP, HTTP/2 and request headers. They do not
271
+ # configure HTTP/3 or QUIC fingerprints; HTTP/3 uses the backend defaults.
272
+ #
268
273
  # Construction generates the native configuration once. For Chrome 152/153,
269
274
  # the TLS trust_anchors extension's ID order is randomized at construction;
270
- # Chrome 154/155 sort those IDs by their raw bytes instead. Reusing this object
275
+ # Chrome 154 and later sort those IDs by their raw bytes instead. Reusing this object
271
276
  # across clients or requests retains that order. Creating a new object generates
272
277
  # a new configuration, including a fresh shuffle for Chrome 152/153.
273
278
  # This does not freeze other per-handshake randomness or force a new handshake
@@ -299,7 +304,7 @@ module Wreq
299
304
  # This stub is for documentation only.
300
305
  unless singleton_methods(false).include?(:new)
301
306
  # Generates a reusable native configuration. Chrome 152/153 Trust Anchor ID
302
- # order is chosen here and retained when this object is reused; Chrome 154/155
307
+ # order is chosen here and retained when this object is reused; Chrome 154–156
303
308
  # use raw-byte sorted order. See {Emulation} for connection semantics.
304
309
  #
305
310
  # @param profile [Wreq::Profile, nil] Fingerprint profile to emulate
@@ -42,7 +42,7 @@ module Wreq
42
42
 
43
43
  # Value-based equality. Returns true when both represent the same HTTP method.
44
44
  # @param other [Object]
45
- # @return [Boolean]
45
+ # @return [Boolean]
46
46
  unless method_defined?(:==)
47
47
  def ==(other)
48
48
  end
@@ -77,7 +77,14 @@ module Wreq
77
77
  HTTP_10 = nil # @return [Wreq::Version] HTTP/1.0
78
78
  HTTP_11 = nil # @return [Wreq::Version] HTTP/1.1
79
79
  HTTP_2 = nil # @return [Wreq::Version] HTTP/2
80
- HTTP_3 = nil # @return [Wreq::Version] HTTP/3
80
+ # Select HTTP/3 over QUIC with `version: Wreq::Version::HTTP_3` on a request.
81
+ # To use it by default, construct a client with `http3_only: true` instead.
82
+ # Requires an HTTPS URL and a reachable UDP endpoint. There is no automatic
83
+ # Alt-Svc discovery or fallback to HTTP/1.1 or HTTP/2.
84
+ # HTTP CONNECT proxies cannot carry these requests; use a direct connection,
85
+ # a SOCKS5 UDP relay or a `quic://` MASQUE proxy.
86
+ # @return [Wreq::Version] HTTP/3
87
+ HTTP_3 = nil
81
88
  end
82
89
 
83
90
  # Returns a string representation of the HTTP version.
data/src/client.rs CHANGED
@@ -76,11 +76,11 @@ struct Builder {
76
76
  tcp_reuse_address: Option<bool>,
77
77
 
78
78
  // ========= Connection pool options =========
79
- /// Set an optional timeout for idle sockets being kept-alive. (in seconds)
79
+ /// Idle connection reuse timeout, in seconds.
80
80
  pool_idle_timeout: Option<u64>,
81
- /// Sets the maximum idle connection per host allowed in the pool.
81
+ /// Maximum idle HTTP/1 connections retained per compatibility group.
82
82
  pool_max_idle_per_host: Option<usize>,
83
- /// Sets the maximum number of connections in the pool.
83
+ /// Maximum compatibility groups retaining reusable connections; zero is unlimited.
84
84
  pool_max_size: Option<usize>,
85
85
 
86
86
  // ========= Protocol options =========
@@ -88,6 +88,8 @@ struct Builder {
88
88
  http1_only: Option<bool>,
89
89
  /// Whether to use the HTTP/2 protocol only.
90
90
  http2_only: Option<bool>,
91
+ /// Whether to use HTTP/3 over QUIC without falling back to TCP.
92
+ http3_only: Option<bool>,
91
93
  /// Whether to use HTTPS only.
92
94
  https_only: Option<bool>,
93
95
 
@@ -147,6 +149,7 @@ impl Builder {
147
149
  .reject_conflicts([
148
150
  (stringify!(http1_only), builder.http1_only == Some(true)),
149
151
  (stringify!(http2_only), builder.http2_only == Some(true)),
152
+ (stringify!(http3_only), builder.http3_only == Some(true)),
150
153
  ])
151
154
  .reject_conflicts([
152
155
  (stringify!(proxy), options.is_non_nil(stringify!(proxy))),
@@ -222,7 +225,7 @@ impl Client {
222
225
  .map(|jar| jar.clone_store(ruby))
223
226
  .transpose()?;
224
227
  let result = gvl::nogvl(|| {
225
- let mut builder = wreq::Client::builder();
228
+ let mut builder = wreq::Client::builder_tokio();
226
229
 
227
230
  // Emulation options.
228
231
  apply_option!(set_if_some_inner, builder, params.emulation, emulation);
@@ -345,6 +348,7 @@ impl Client {
345
348
  // Protocol options.
346
349
  apply_option!(set_if_true, builder, params.http1_only, http1_only, false);
347
350
  apply_option!(set_if_true, builder, params.http2_only, http2_only, false);
351
+ apply_option!(set_if_true, builder, params.http3_only, http3_only, false);
348
352
  apply_option!(set_if_some, builder, params.https_only, https_only);
349
353
 
350
354
  // TLS options.
data/src/emulate.rs CHANGED
@@ -93,6 +93,8 @@ define_ruby_enum!(
93
93
  Chrome153,
94
94
  Chrome154,
95
95
  Chrome155,
96
+ Chrome156,
97
+ Chrome157,
96
98
 
97
99
  Edge101,
98
100
  Edge122,
@@ -7,7 +7,7 @@ require "timeout"
7
7
 
8
8
  class EmulationTest < Minitest::Test
9
9
  def test_reused_emulation_retains_trust_anchors_across_clients_and_requests
10
- [Wreq::Profile::Chrome152, Wreq::Profile::Chrome153, Wreq::Profile::Chrome154, Wreq::Profile::Chrome155].each do |profile|
10
+ [Wreq::Profile::Chrome152, Wreq::Profile::Chrome153, Wreq::Profile::Chrome154, Wreq::Profile::Chrome155, Wreq::Profile::Chrome156, Wreq::Profile::Chrome157].each do |profile|
11
11
  emulation = Wreq::Emulation.new(profile: profile)
12
12
  client = Wreq::Client.new(emulation: emulation, no_proxy: true)
13
13
  expected = capture_trust_anchors { |url| client.get(url, timeout: 5) }
@@ -44,6 +44,8 @@ class EmulationTest < Minitest::Test
44
44
  Wreq::Profile::Chrome153 => "Chrome153",
45
45
  Wreq::Profile::Chrome154 => "Chrome154",
46
46
  Wreq::Profile::Chrome155 => "Chrome155",
47
+ Wreq::Profile::Chrome156 => "Chrome156",
48
+ Wreq::Profile::Chrome157 => "Chrome157",
47
49
  Wreq::Profile::Firefox152 => "Firefox152"
48
50
  }.each do |profile, name|
49
51
  assert_equal name, profile.to_s
@@ -227,12 +227,21 @@ class OptionValidationTest < Minitest::Test
227
227
  end
228
228
 
229
229
  def test_protocol_only_options_are_mutually_exclusive
230
- error = assert_raises(ArgumentError) do
231
- Wreq::Client.new(http1_only: true, http2_only: true)
230
+ [:http1_only, :http2_only, :http3_only].combination(2) do |first, second|
231
+ error = assert_raises(ArgumentError) do
232
+ Wreq::Client.new(**{first => true, second => true})
233
+ end
234
+
235
+ assert_includes error.message, ":#{first}"
236
+ assert_includes error.message, ":#{second}"
232
237
  end
233
238
 
234
- assert_includes error.message, ":http1_only"
235
- assert_includes error.message, ":http2_only"
239
+ assert_instance_of Wreq::Client,
240
+ Wreq::Client.new(http3_only: true, http1_only: false, http2_only: nil)
241
+ assert_instance_of Wreq::Client,
242
+ Wreq::Client.new(http1_only: true, http3_only: false)
243
+ assert_instance_of Wreq::Client,
244
+ Wreq::Client.new(http2_only: true, http3_only: nil)
236
245
  end
237
246
 
238
247
  def test_validation_reports_the_first_failed_rule
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wreq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - SearchApi