wreq 1.3.2.4 → 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.
- checksums.yaml +4 -4
- data/Cargo.lock +470 -50
- data/Cargo.toml +19 -16
- data/README.md +5 -12
- data/Rakefile +3 -9
- data/crates/wreq-util/Cargo.toml +1 -1
- data/crates/wreq-util/README.md +4 -2
- data/crates/wreq-util/examples/emulate.rs +7 -3
- data/crates/wreq-util/examples/tower_delay.rs +4 -4
- data/crates/wreq-util/src/emulate/macros.rs +197 -32
- data/crates/wreq-util/src/emulate/profile/chrome/header.rs +116 -0
- data/crates/wreq-util/src/emulate/profile/chrome/http2.rs +65 -0
- data/crates/wreq-util/src/emulate/profile/chrome/tls.rs +268 -0
- data/crates/wreq-util/src/emulate/profile/chrome.rs +2269 -0
- data/crates/wreq-util/src/emulate/profile/firefox/header.rs +54 -48
- data/crates/wreq-util/src/emulate/profile/firefox/http2.rs +102 -92
- data/crates/wreq-util/src/emulate/profile/firefox/tls.rs +146 -155
- data/crates/wreq-util/src/emulate/profile/firefox.rs +440 -312
- data/crates/wreq-util/src/emulate/profile/okhttp.rs +2 -3
- data/crates/wreq-util/src/emulate/profile/opera/header.rs +29 -0
- data/crates/wreq-util/src/emulate/profile/opera/http2.rs +50 -0
- data/crates/wreq-util/src/emulate/profile/opera/tls.rs +103 -0
- data/crates/wreq-util/src/emulate/profile/opera.rs +299 -0
- data/crates/wreq-util/src/emulate/profile.rs +10 -10
- data/crates/wreq-util/src/emulate.rs +1 -34
- data/crates/wreq-util/src/tower/delay/layer.rs +5 -5
- data/crates/wreq-util/src/tower/delay.rs +4 -4
- data/crates/wreq-util/tests/client.rs +50 -187
- data/crates/wreq-util/tests/emulate_chrome.rs +0 -17
- data/crates/wreq-util/tests/emulate_firefox.rs +26 -36
- data/crates/wreq-util/tests/emulate_opera.rs +0 -24
- data/crates/wreq-util/tests/support/mod.rs +1 -1
- data/lib/wreq_ruby/client.rb +27 -13
- data/lib/wreq_ruby/emulate.rb +3 -28
- data/lib/wreq_ruby/http.rb +9 -2
- data/src/client/body/json.rs +1 -2
- data/src/client/resp.rs +1 -1
- data/src/client.rs +8 -4
- data/src/emulate.rs +5 -28
- data/src/error.rs +23 -3
- data/src/lib.rs +3 -2
- data/src/options.rs +17 -19
- data/{crates/serde-magnus/src → src/serde}/de/array_deserializer.rs +2 -2
- data/{crates/serde-magnus/src → src/serde}/de/array_enumerator.rs +1 -1
- data/{crates/serde-magnus/src → src/serde}/de/deserializer.rs +31 -25
- data/{crates/serde-magnus/src → src/serde}/de/enum_deserializer.rs +3 -3
- data/{crates/serde-magnus/src → src/serde}/de/hash_deserializer.rs +2 -2
- data/{crates/serde-magnus/src → src/serde}/de/number_deserializer.rs +2 -2
- data/{crates/serde-magnus/src → src/serde}/de/variant_deserializer.rs +20 -11
- data/src/serde/de.rs +33 -0
- data/src/serde/error.rs +146 -0
- data/src/serde/ser/enums.rs +14 -0
- data/{crates/serde-magnus/src → src/serde}/ser/map_serializer.rs +2 -2
- data/src/serde/ser/seq_serializer.rs +71 -0
- data/src/serde/ser/serializer.rs +194 -0
- data/{crates/serde-magnus/src → src/serde}/ser/struct_serializer.rs +4 -4
- data/src/serde/ser/struct_variant_serializer.rs +44 -0
- data/src/serde/ser/tuple_variant_serializer.rs +41 -0
- data/src/serde/ser.rs +18 -0
- data/{crates/serde-magnus/src → src/serde}/tests.rs +68 -19
- data/src/serde.rs +202 -0
- data/test/emulation_test.rb +104 -21
- data/test/option_validation_test.rb +13 -4
- data/wreq.gemspec +15 -3
- metadata +29 -35
- data/VERSION +0 -1
- data/crates/README.md +0 -6
- data/crates/serde-magnus/Cargo.toml +0 -29
- data/crates/serde-magnus/LICENSE +0 -19
- data/crates/serde-magnus/README.md +0 -147
- data/crates/serde-magnus/src/de/mod.rs +0 -554
- data/crates/serde-magnus/src/error.rs +0 -84
- data/crates/serde-magnus/src/lib.rs +0 -137
- data/crates/serde-magnus/src/options.rs +0 -151
- data/crates/serde-magnus/src/ser/enums.rs +0 -11
- data/crates/serde-magnus/src/ser/mod.rs +0 -428
- data/crates/serde-magnus/src/ser/seq_serializer.rs +0 -68
- data/crates/serde-magnus/src/ser/serializer.rs +0 -220
- data/crates/serde-magnus/src/ser/struct_variant_serializer.rs +0 -45
- data/crates/serde-magnus/src/ser/tuple_variant_serializer.rs +0 -38
- data/crates/wreq-util/src/emulate/profile/chromium/chrome.rs +0 -731
- data/crates/wreq-util/src/emulate/profile/chromium/edge.rs +0 -418
- data/crates/wreq-util/src/emulate/profile/chromium/header.rs +0 -74
- data/crates/wreq-util/src/emulate/profile/chromium/http2.rs +0 -59
- data/crates/wreq-util/src/emulate/profile/chromium/opera.rs +0 -312
- data/crates/wreq-util/src/emulate/profile/chromium/tls.rs +0 -310
- data/crates/wreq-util/src/emulate/profile/chromium.rs +0 -9
- data/test/emulation_client_hello_test.rb +0 -142
data/Cargo.toml
CHANGED
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
name = "wreq-ruby"
|
|
3
3
|
description = "Ruby bindings for Wreq, HTTP client library in Rust."
|
|
4
4
|
authors = ["SearchApi <support@searchapi.io>"]
|
|
5
|
+
homepage = "https://github.com/SearchApi/wreq-ruby"
|
|
5
6
|
repository = "https://github.com/SearchApi/wreq-ruby"
|
|
6
7
|
edition = "2024"
|
|
7
|
-
version = "1.3.
|
|
8
|
-
rust-version = "1.
|
|
9
|
-
|
|
10
|
-
[workspace]
|
|
11
|
-
members = ["crates/serde-magnus"]
|
|
12
|
-
exclude = ["crates/wreq-util"]
|
|
8
|
+
version = "1.3.3"
|
|
9
|
+
rust-version = "1.98"
|
|
13
10
|
|
|
14
11
|
[lib]
|
|
15
12
|
crate-type = ["cdylib"]
|
|
@@ -17,13 +14,14 @@ doc = false
|
|
|
17
14
|
name = "wreq_ruby"
|
|
18
15
|
|
|
19
16
|
[dependencies]
|
|
20
|
-
magnus = { version = "0.
|
|
17
|
+
magnus = { version = "0.8.2", features = ["bytes"] }
|
|
21
18
|
rb-sys = { version = "0.9.128", default-features = false }
|
|
22
19
|
tokio = { version = "1.53.1", features = ["full"] }
|
|
23
20
|
# Keep the existing trust store independent of wreq's default feature selection.
|
|
24
21
|
wreq = { version = "0.16.1", default-features = false, features = [
|
|
25
22
|
"tokio-rt",
|
|
26
23
|
"http2",
|
|
24
|
+
"http3",
|
|
27
25
|
"chromium-roots",
|
|
28
26
|
"query",
|
|
29
27
|
"form",
|
|
@@ -39,11 +37,12 @@ wreq = { version = "0.16.1", default-features = false, features = [
|
|
|
39
37
|
] }
|
|
40
38
|
wreq-util = { version = "3.0.0-rc", features = ["emulation-compression"] }
|
|
41
39
|
serde = { version = "1.0.229", features = ["derive"] }
|
|
42
|
-
|
|
40
|
+
serde_ignored = "0.1.14"
|
|
43
41
|
serde_json = { version = "1.0.151", features = [
|
|
44
42
|
"arbitrary_precision",
|
|
45
43
|
"preserve_order",
|
|
46
44
|
] }
|
|
45
|
+
serde_path_to_error = "0.1.20"
|
|
47
46
|
indexmap = { version = "2.14.0", features = ["serde"] }
|
|
48
47
|
cookie = "0.18.1"
|
|
49
48
|
bytes = "1.12.1"
|
|
@@ -56,7 +55,7 @@ futures-util = { version = "0.3.33", default-features = false }
|
|
|
56
55
|
forkguard = { version = "0.1.3", features = ["atfork"] }
|
|
57
56
|
|
|
58
57
|
[dev-dependencies]
|
|
59
|
-
magnus = { version = "0.
|
|
58
|
+
magnus = { version = "0.8.2", features = ["embed"] }
|
|
60
59
|
|
|
61
60
|
[build-dependencies]
|
|
62
61
|
rb-sys-env = "0.2.2"
|
|
@@ -70,11 +69,15 @@ opt-level = 3
|
|
|
70
69
|
strip = true
|
|
71
70
|
|
|
72
71
|
[patch.crates-io]
|
|
73
|
-
#
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
# Keep transport patches aligned with wreq's demo/brave-galileo-ac7w3r branch.
|
|
73
|
+
http2 = { git = "https://github.com/0x676e67/http2", rev = "ce505e52ce9c25fb055412cb39b1caaa7a1f70a8" }
|
|
74
|
+
http3 = { git = "https://github.com/0x676e67/http3", rev = "5bd394f3dfb8bc63591627a229c34c02caadc3af" }
|
|
75
|
+
http3-datagram = { git = "https://github.com/0x676e67/http3", rev = "5bd394f3dfb8bc63591627a229c34c02caadc3af" }
|
|
76
|
+
http3-quic = { git = "https://github.com/0x676e67/http3", rev = "5bd394f3dfb8bc63591627a229c34c02caadc3af" }
|
|
77
|
+
quic = { git = "https://github.com/0x676e67/quic", rev = "b3d74044e874c5e785f462e3032faaf021cb6958" }
|
|
78
|
+
netty = { git = "https://github.com/0x676e67/netty", rev = "0e1e53c0d9e500b253361cf6997559c44d7717b5" }
|
|
79
|
+
btls = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" }
|
|
80
|
+
btls-sys = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" }
|
|
81
|
+
tokio-btls = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" }
|
|
82
|
+
wreq = { git = "https://github.com/0x676e67/wreq", rev = "10029bb86ff88d8ed88b8e10518fe6e1f7ff322c" }
|
|
80
83
|
wreq-util = { path = "crates/wreq-util" }
|
data/README.md
CHANGED
|
@@ -89,21 +89,14 @@ Most browser device models share identical TLS and HTTP/2 configurations, differ
|
|
|
89
89
|
- <details>
|
|
90
90
|
<summary>Available browser emulations</summary>
|
|
91
91
|
|
|
92
|
-
Edge 149–158 provide request-header presets for Windows, macOS, Linux, Android, and iOS.
|
|
93
|
-
Firefox 153–160 provide Android and iPhone presets for `User-Agent` and `Accept-Language`.
|
|
94
|
-
Both use the same TLS and HTTP/2 settings as the corresponding desktop Firefox preset.
|
|
95
|
-
Opera 116–140 provide desktop request-header presets for Windows, macOS, and Linux.
|
|
96
|
-
|
|
97
92
|
| **Browser** | **Versions** |
|
|
98
93
|
| ----------- | ------------ |
|
|
99
|
-
| **Chrome** | `Chrome100`, `Chrome101`, `Chrome104`, `Chrome105`, `Chrome106`, `Chrome107`, `Chrome108`, `Chrome109`, `Chrome110`, `Chrome114`, `Chrome116`, `Chrome117`, `Chrome118`, `Chrome119`, `Chrome120`, `Chrome123`, `Chrome124`, `Chrome126`, `Chrome127`, `Chrome128`, `Chrome129`, `Chrome130`, `Chrome131`, `Chrome132`, `Chrome133`, `Chrome134`, `Chrome135`, `Chrome136`, `Chrome137`, `Chrome138`, `Chrome139`, `Chrome140`, `Chrome141`, `Chrome142`, `Chrome143`, `Chrome144`, `Chrome145`, `Chrome146`, `Chrome147`, `Chrome148`, `Chrome149`, `Chrome150`, `Chrome151`, `Chrome152`, `Chrome153`, `Chrome154`, `Chrome155`, `Chrome156`, `Chrome157
|
|
100
|
-
| **Edge** | `Edge101`, `Edge122`, `Edge127`, `Edge131`, `Edge134
|
|
101
|
-
| **Firefox** | `Firefox109`, `Firefox117`, `Firefox128`, `Firefox133`, `Firefox135`, `FirefoxPrivate135`, `FirefoxAndroid135`, `Firefox136`, `FirefoxPrivate136`, `Firefox139`, `Firefox142`, `Firefox143`, `Firefox144`, `Firefox145`, `Firefox146`, `Firefox147`, `Firefox148`, `Firefox149`, `Firefox150`, `Firefox151`, `Firefox152
|
|
94
|
+
| **Chrome** | `Chrome100`, `Chrome101`, `Chrome104`, `Chrome105`, `Chrome106`, `Chrome107`, `Chrome108`, `Chrome109`, `Chrome110`, `Chrome114`, `Chrome116`, `Chrome117`, `Chrome118`, `Chrome119`, `Chrome120`, `Chrome123`, `Chrome124`, `Chrome126`, `Chrome127`, `Chrome128`, `Chrome129`, `Chrome130`, `Chrome131`, `Chrome132`, `Chrome133`, `Chrome134`, `Chrome135`, `Chrome136`, `Chrome137`, `Chrome138`, `Chrome139`, `Chrome140`, `Chrome141`, `Chrome142`, `Chrome143`, `Chrome144`, `Chrome145`, `Chrome146`, `Chrome147`, `Chrome148`, `Chrome149`, `Chrome150`, `Chrome151`, `Chrome152`, `Chrome153`, `Chrome154`, `Chrome155`, `Chrome156`, `Chrome157` |
|
|
95
|
+
| **Edge** | `Edge101`, `Edge122`, `Edge127`, `Edge131`, `Edge134`, `Edge135`, `Edge136`, `Edge137`, `Edge138`, `Edge139`, `Edge140`, `Edge141`, `Edge142`, `Edge143`, `Edge144`, `Edge145`, `Edge146`, `Edge147`, `Edge148` |
|
|
96
|
+
| **Firefox** | `Firefox109`, `Firefox117`, `Firefox128`, `Firefox133`, `Firefox135`, `FirefoxPrivate135`, `FirefoxAndroid135`, `Firefox136`, `FirefoxPrivate136`, `Firefox139`, `Firefox142`, `Firefox143`, `Firefox144`, `Firefox145`, `Firefox146`, `Firefox147`, `Firefox148`, `Firefox149`, `Firefox150`, `Firefox151`, `Firefox152` |
|
|
102
97
|
| **Safari** | `Safari15_3`, `Safari15_5`, `Safari15_6_1`, `Safari16`, `Safari16_5`, `Safari17_0`, `Safari17_2_1`, `Safari17_4_1`, `Safari17_5`, `Safari17_6`, `Safari18`, `Safari18_2`, `Safari18_3`, `Safari18_3_1`, `Safari18_5`, `Safari26`, `Safari26_1`, `Safari26_2`, `SafariIos16_5`, `SafariIos17_2`, `SafariIos17_4_1`, `SafariIos18_1_1`, `SafariIos26`, `SafariIos26_2`, `SafariIPad18`, `SafariIPad26`, `SafariIpad26_2` |
|
|
103
|
-
| **OkHttp** | `
|
|
104
|
-
| **Opera** | `Opera116
|
|
105
|
-
|
|
106
|
-
Opera 132–140 use the corresponding Chromium desktop TLS and HTTP/2 defaults with Opera-branded request headers.
|
|
98
|
+
| **OkHttp** | `Opera116`, `Opera117`, `Opera118`, `Opera119`, `Opera120`, `Opera121`, `Opera122`, `Opera123`, `Opera124`, `Opera125`, `Opera126`, `Opera127`, `Opera128`, `Opera129`, `Opera130` |
|
|
99
|
+
| **Opera** | `Opera116`, `Opera117`, `Opera118`, `Opera119` |
|
|
107
100
|
|
|
108
101
|
</details>
|
|
109
102
|
|
data/Rakefile
CHANGED
|
@@ -44,23 +44,17 @@ end
|
|
|
44
44
|
|
|
45
45
|
desc "Run Rust tests"
|
|
46
46
|
task :cargo_test do
|
|
47
|
-
|
|
48
|
-
if RbConfig::CONFIG.fetch("host_os").start_with?("linux")
|
|
49
|
-
# Embedded Ruby tests need the active Ruby's shared library at startup.
|
|
50
|
-
test_env["LD_LIBRARY_PATH"] = [RbConfig::CONFIG.fetch("libdir"), ENV["LD_LIBRARY_PATH"]]
|
|
51
|
-
.compact.reject(&:empty?).join(File::PATH_SEPARATOR)
|
|
52
|
-
end
|
|
53
|
-
sh test_env, "cargo", "test", "--workspace", "--locked"
|
|
47
|
+
sh "cargo test"
|
|
54
48
|
end
|
|
55
49
|
|
|
56
50
|
desc "Format Rust code"
|
|
57
51
|
task :fmt do
|
|
58
|
-
sh "cargo fmt
|
|
52
|
+
sh "cargo fmt"
|
|
59
53
|
end
|
|
60
54
|
|
|
61
55
|
desc "Run Clippy linter"
|
|
62
56
|
task :lint do
|
|
63
|
-
sh "cargo clippy --
|
|
57
|
+
sh "cargo clippy -- -D warnings"
|
|
64
58
|
end
|
|
65
59
|
|
|
66
60
|
desc "Build native gem for platform (e.g., rake 'native[x86_64-linux]')"
|
data/crates/wreq-util/Cargo.toml
CHANGED
|
@@ -23,13 +23,13 @@ tokio-rt = ["wreq/tokio-rt"]
|
|
|
23
23
|
compio-rt = ["wreq/compio-rt"]
|
|
24
24
|
|
|
25
25
|
emulation = [
|
|
26
|
+
"wreq/http2",
|
|
26
27
|
"dep:typed-builder",
|
|
27
28
|
"dep:brotli",
|
|
28
29
|
"dep:flate2",
|
|
29
30
|
"dep:zstd",
|
|
30
31
|
"dep:chromium-roots",
|
|
31
32
|
"wreq/chromium-roots",
|
|
32
|
-
"wreq/http2",
|
|
33
33
|
]
|
|
34
34
|
emulation-serde = ["dep:serde"]
|
|
35
35
|
emulation-compression = []
|
data/crates/wreq-util/README.md
CHANGED
|
@@ -20,12 +20,14 @@ See the [crate documentation](https://docs.rs/wreq-util/latest/wreq_util) for mo
|
|
|
20
20
|
|
|
21
21
|
## Example
|
|
22
22
|
|
|
23
|
+
This vendored copy uses the development wreq revision pinned in the [root Cargo.toml](../../Cargo.toml). Building it independently requires the same Git patches.
|
|
24
|
+
|
|
23
25
|
The following example uses the [Tokio](https://tokio.rs) runtime with optional features enabled by adding this to your `Cargo.toml`:
|
|
24
26
|
|
|
25
27
|
```toml
|
|
26
28
|
[dependencies]
|
|
27
29
|
tokio = { version = "1", features = ["full"] }
|
|
28
|
-
wreq = "
|
|
30
|
+
wreq = "0.16.1"
|
|
29
31
|
wreq-util = "3.0.0-rc"
|
|
30
32
|
```
|
|
31
33
|
|
|
@@ -38,7 +40,7 @@ use wreq_util::Emulation;
|
|
|
38
40
|
#[tokio::main]
|
|
39
41
|
async fn main() -> wreq::Result<()> {
|
|
40
42
|
// Build a client
|
|
41
|
-
let client = Client::
|
|
43
|
+
let client = Client::builder_tokio()
|
|
42
44
|
.emulation(Emulation::Chrome147)
|
|
43
45
|
.build()?;
|
|
44
46
|
|
|
@@ -2,8 +2,10 @@ use wreq_util::{Emulation, Platform, Profile};
|
|
|
2
2
|
|
|
3
3
|
#[tokio::main]
|
|
4
4
|
async fn main() -> Result<(), wreq::Error> {
|
|
5
|
+
let client = wreq::Client::builder_tokio().build()?;
|
|
5
6
|
// Example 1: Basic emulation - Safari26
|
|
6
|
-
let text =
|
|
7
|
+
let text = client
|
|
8
|
+
.get("https://pingly.us.kg/api/all")
|
|
7
9
|
.emulation(Emulation::Safari26)
|
|
8
10
|
.send()
|
|
9
11
|
.await?
|
|
@@ -12,7 +14,8 @@ async fn main() -> Result<(), wreq::Error> {
|
|
|
12
14
|
println!("{}\n", text);
|
|
13
15
|
|
|
14
16
|
// Example 2: Advanced emulation with options - OkHttp5
|
|
15
|
-
let text =
|
|
17
|
+
let text = client
|
|
18
|
+
.get("https://pingly.us.kg/api/all")
|
|
16
19
|
.emulation(
|
|
17
20
|
Emulation::builder()
|
|
18
21
|
.profile(Profile::OkHttp5)
|
|
@@ -27,7 +30,8 @@ async fn main() -> Result<(), wreq::Error> {
|
|
|
27
30
|
println!("{}\n", text);
|
|
28
31
|
|
|
29
32
|
// Example 3: Random device emulation
|
|
30
|
-
let text =
|
|
33
|
+
let text = client
|
|
34
|
+
.get("https://pingly.us.kg/api/all")
|
|
31
35
|
.emulation(Emulation::random())
|
|
32
36
|
.send()
|
|
33
37
|
.await?
|
|
@@ -5,7 +5,7 @@ use wreq_util::tower::delay::{DelayLayer, JitterDelayLayer};
|
|
|
5
5
|
#[tokio::main]
|
|
6
6
|
async fn main() -> Result<(), wreq::Error> {
|
|
7
7
|
// Build a client with a 1 second delay between requests
|
|
8
|
-
let client = Client::
|
|
8
|
+
let client = Client::builder_tokio()
|
|
9
9
|
.layer(DelayLayer::new(Duration::from_secs(1)))
|
|
10
10
|
.tls_cert_verification(false)
|
|
11
11
|
.build()?;
|
|
@@ -52,7 +52,7 @@ async fn basic_jitter_delay() -> Result<(), wreq::Error> {
|
|
|
52
52
|
println!("=== Basic Jittered Delay ===\n");
|
|
53
53
|
|
|
54
54
|
// Build a client with jittered delay: base 1s ± 50% (range: 0.5s to 1.5s)
|
|
55
|
-
let client = Client::
|
|
55
|
+
let client = Client::builder_tokio()
|
|
56
56
|
.layer(JitterDelayLayer::new(Duration::from_secs(1), 0.5))
|
|
57
57
|
.tls_cert_verification(false)
|
|
58
58
|
.build()?;
|
|
@@ -100,7 +100,7 @@ async fn basic_jitter_delay() -> Result<(), wreq::Error> {
|
|
|
100
100
|
async fn conditional_jitter_delay() -> Result<(), wreq::Error> {
|
|
101
101
|
println!("=== Conditional Jittered Delay (using `JitterDelayLayer::when`) ===\n");
|
|
102
102
|
|
|
103
|
-
let client = Client::
|
|
103
|
+
let client = Client::builder_tokio()
|
|
104
104
|
.layer(JitterDelayLayer::new(Duration::from_millis(800), 0.3).when(
|
|
105
105
|
|req: &http::Request<_>| {
|
|
106
106
|
// Only apply delay to POST requests
|
|
@@ -149,7 +149,7 @@ async fn conditional_fixed_delay() -> Result<(), wreq::Error> {
|
|
|
149
149
|
println!("=== Conditional Fixed Delay (using `DelayLayer::when`) ===\n");
|
|
150
150
|
|
|
151
151
|
// Build a client that only delays requests to specific paths
|
|
152
|
-
let client = Client::
|
|
152
|
+
let client = Client::builder_tokio()
|
|
153
153
|
.layer(
|
|
154
154
|
DelayLayer::new(Duration::from_secs(1)).when(|req: &http::Request<_>| {
|
|
155
155
|
// Only apply delay to /delay/* endpoints
|
|
@@ -84,6 +84,103 @@ macro_rules! define_enum {
|
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
macro_rules! header_chrome_sec_ch_ua {
|
|
88
|
+
($headers:expr, $ua:expr, $platform:expr, $is_mobile:expr) => {
|
|
89
|
+
let mobile = if $is_mobile { "?1" } else { "?0" };
|
|
90
|
+
$headers.insert("sec-ch-ua", HeaderValue::from_static($ua));
|
|
91
|
+
$headers.insert("sec-ch-ua-mobile", HeaderValue::from_static(mobile));
|
|
92
|
+
$headers.insert("sec-ch-ua-platform", HeaderValue::from_static($platform));
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
macro_rules! header_chrome_sec_fetch {
|
|
97
|
+
($headers:expr) => {
|
|
98
|
+
$headers.insert("sec-fetch-site", HeaderValue::from_static("none"));
|
|
99
|
+
$headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate"));
|
|
100
|
+
$headers.insert("sec-fetch-user", HeaderValue::from_static("?1"));
|
|
101
|
+
$headers.insert("sec-fetch-dest", HeaderValue::from_static("document"));
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
macro_rules! header_chrome_ua {
|
|
106
|
+
($headers:expr, $ua:expr) => {
|
|
107
|
+
$headers.insert(USER_AGENT, HeaderValue::from_static($ua));
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
macro_rules! header_chrome_accept {
|
|
112
|
+
($headers:expr) => {
|
|
113
|
+
$headers.insert(ACCEPT, HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"));
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
macro_rules! header_chrome_accept_encoding {
|
|
118
|
+
($headers:expr) => {
|
|
119
|
+
#[cfg(feature = "emulation-compression")]
|
|
120
|
+
$headers.insert(
|
|
121
|
+
ACCEPT_ENCODING,
|
|
122
|
+
HeaderValue::from_static("gzip, deflate, br"),
|
|
123
|
+
);
|
|
124
|
+
$headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9"));
|
|
125
|
+
};
|
|
126
|
+
(zstd, $headers:expr) => {
|
|
127
|
+
#[cfg(feature = "emulation-compression")]
|
|
128
|
+
$headers.insert(
|
|
129
|
+
ACCEPT_ENCODING,
|
|
130
|
+
HeaderValue::from_static("gzip, deflate, br, zstd"),
|
|
131
|
+
);
|
|
132
|
+
$headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9"));
|
|
133
|
+
};
|
|
134
|
+
(zstd_only, $headers:expr) => {
|
|
135
|
+
#[cfg(feature = "emulation-compression")]
|
|
136
|
+
$headers.insert(
|
|
137
|
+
ACCEPT_ENCODING,
|
|
138
|
+
HeaderValue::from_static("gzip, deflate, br, zstd"),
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
macro_rules! header_firefox_sec_fetch {
|
|
144
|
+
($headers:expr) => {
|
|
145
|
+
$headers.insert("sec-fetch-dest", HeaderValue::from_static("document"));
|
|
146
|
+
$headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate"));
|
|
147
|
+
$headers.insert("sec-fetch-site", HeaderValue::from_static("none"));
|
|
148
|
+
$headers.insert("sec-fetch-user", HeaderValue::from_static("?1"));
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
macro_rules! header_firefox_accept {
|
|
153
|
+
($headers:expr) => {
|
|
154
|
+
header_firefox_accept!(@build $headers, "en-US,en;q=0.5", "gzip, deflate, br");
|
|
155
|
+
};
|
|
156
|
+
(zstd, $headers:expr) => {
|
|
157
|
+
header_firefox_accept!(@build $headers, "en-US,en;q=0.5", "gzip, deflate, br, zstd");
|
|
158
|
+
};
|
|
159
|
+
// Firefox 147 changed the generated q-value from dividing 1.0 across the list to
|
|
160
|
+
// decrementing by 0.1 per entry, so a two-entry list became q=0.9 (Bugzilla 2000765,
|
|
161
|
+
// landed in 0e050ae5116d).
|
|
162
|
+
(zstd_q09, $headers:expr) => {
|
|
163
|
+
header_firefox_accept!(@build $headers, "en-US,en;q=0.9", "gzip, deflate, br, zstd");
|
|
164
|
+
};
|
|
165
|
+
(@build $headers:expr, $accept_language:expr, $accept_encoding:expr) => {
|
|
166
|
+
$headers.insert(
|
|
167
|
+
ACCEPT,
|
|
168
|
+
HeaderValue::from_static(
|
|
169
|
+
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
170
|
+
),
|
|
171
|
+
);
|
|
172
|
+
$headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static($accept_language));
|
|
173
|
+
#[cfg(feature = "emulation-compression")]
|
|
174
|
+
$headers.insert(ACCEPT_ENCODING, HeaderValue::from_static($accept_encoding));
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
macro_rules! header_firefox_ua {
|
|
179
|
+
($headers:expr, $ua:expr) => {
|
|
180
|
+
$headers.insert(USER_AGENT, HeaderValue::from_static($ua));
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
87
184
|
macro_rules! join {
|
|
88
185
|
($sep:expr, $first:expr $(, $rest:expr)*) => {
|
|
89
186
|
concat!($first $(, $sep, $rest)*)
|
|
@@ -105,7 +202,6 @@ macro_rules! standard_mod_generator {
|
|
|
105
202
|
default_headers: Option<HeaderMap>,
|
|
106
203
|
) -> wreq::Emulation {
|
|
107
204
|
build_standard_emulation(
|
|
108
|
-
stringify!($mod_name),
|
|
109
205
|
$tls_options,
|
|
110
206
|
http2.then(|| $http2_options),
|
|
111
207
|
default_headers,
|
|
@@ -134,22 +230,84 @@ macro_rules! fixed_headers {
|
|
|
134
230
|
macro_rules! platform_headers {
|
|
135
231
|
(
|
|
136
232
|
$emulation:expr,
|
|
137
|
-
$
|
|
138
|
-
$
|
|
139
|
-
[($default_os:ident, $default_ua:literal) $(, ($other_os:ident, $other_ua:literal))* $(,)?]
|
|
233
|
+
$header_initializer:ident,
|
|
234
|
+
[($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*]
|
|
140
235
|
) => {{
|
|
141
236
|
#[allow(unreachable_patterns)]
|
|
142
237
|
$emulation.headers.then(|| {
|
|
143
|
-
|
|
144
|
-
$(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
238
|
+
match $emulation.platform {
|
|
239
|
+
$(
|
|
240
|
+
Platform::$other_os => $header_initializer(
|
|
241
|
+
$other_sec_ch_ua,
|
|
242
|
+
$other_ua,
|
|
243
|
+
$emulation.platform,
|
|
244
|
+
),
|
|
245
|
+
)*
|
|
246
|
+
_ => $header_initializer(
|
|
247
|
+
$default_sec_ch_ua,
|
|
248
|
+
$default_ua,
|
|
249
|
+
Platform::$default_os,
|
|
250
|
+
),
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
}};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
macro_rules! firefox_platform_headers {
|
|
257
|
+
($emulation:expr, $header_initializer:ident, [($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*]) => {{
|
|
258
|
+
#[allow(unreachable_patterns)]
|
|
259
|
+
$emulation.headers.then(|| {
|
|
260
|
+
match $emulation.platform {
|
|
261
|
+
$(
|
|
262
|
+
Platform::$other_os => $header_initializer($other_ua),
|
|
263
|
+
)*
|
|
264
|
+
_ => $header_initializer($default_ua),
|
|
265
|
+
}
|
|
148
266
|
})
|
|
149
267
|
}};
|
|
150
268
|
}
|
|
151
269
|
|
|
152
270
|
macro_rules! mod_generator {
|
|
271
|
+
(
|
|
272
|
+
$mod_name:ident,
|
|
273
|
+
$tls_options:expr,
|
|
274
|
+
$http2_options:expr,
|
|
275
|
+
$header_initializer:ident,
|
|
276
|
+
[($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*]
|
|
277
|
+
) => {
|
|
278
|
+
standard_mod_generator!(
|
|
279
|
+
$mod_name,
|
|
280
|
+
$tls_options,
|
|
281
|
+
$http2_options,
|
|
282
|
+
|emulation: &Emulation| {
|
|
283
|
+
platform_headers!(
|
|
284
|
+
emulation,
|
|
285
|
+
$header_initializer,
|
|
286
|
+
[($default_os, $default_sec_ch_ua, $default_ua) $(, ($other_os, $other_sec_ch_ua, $other_ua))*]
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
(
|
|
292
|
+
$mod_name:ident,
|
|
293
|
+
$tls_options:expr,
|
|
294
|
+
$http2_options:expr,
|
|
295
|
+
$header_initializer:ident,
|
|
296
|
+
[($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*]
|
|
297
|
+
) => {
|
|
298
|
+
standard_mod_generator!(
|
|
299
|
+
$mod_name,
|
|
300
|
+
$tls_options,
|
|
301
|
+
$http2_options,
|
|
302
|
+
|emulation: &Emulation| {
|
|
303
|
+
firefox_platform_headers!(
|
|
304
|
+
emulation,
|
|
305
|
+
$header_initializer,
|
|
306
|
+
[($default_os, $default_ua) $(, ($other_os, $other_ua))*]
|
|
307
|
+
)
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
};
|
|
153
311
|
(
|
|
154
312
|
$mod_name:ident,
|
|
155
313
|
$tls_options:expr,
|
|
@@ -168,41 +326,48 @@ macro_rules! mod_generator {
|
|
|
168
326
|
$mod_name:ident,
|
|
169
327
|
$build_emulation:expr,
|
|
170
328
|
$header_initializer:ident,
|
|
171
|
-
$
|
|
329
|
+
[($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*]
|
|
172
330
|
) => {
|
|
173
331
|
standard_mod_generator!(
|
|
174
332
|
$mod_name,
|
|
175
333
|
$build_emulation,
|
|
176
|
-
|emulation: &Emulation|
|
|
334
|
+
|emulation: &Emulation| {
|
|
335
|
+
platform_headers!(
|
|
336
|
+
emulation,
|
|
337
|
+
$header_initializer,
|
|
338
|
+
[($default_os, $default_sec_ch_ua, $default_ua) $(, ($other_os, $other_sec_ch_ua, $other_ua))*]
|
|
339
|
+
)
|
|
340
|
+
}
|
|
177
341
|
);
|
|
178
342
|
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
macro_rules! chromium_profile {
|
|
182
343
|
(
|
|
183
|
-
$
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
brands: $brands:literal,
|
|
188
|
-
$platforms:tt $(,)?
|
|
344
|
+
$mod_name:ident,
|
|
345
|
+
$build_emulation:expr,
|
|
346
|
+
$header_initializer:ident,
|
|
347
|
+
[($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*]
|
|
189
348
|
) => {
|
|
190
349
|
standard_mod_generator!(
|
|
191
|
-
$
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
350
|
+
$mod_name,
|
|
351
|
+
$build_emulation,
|
|
352
|
+
|emulation: &Emulation| {
|
|
353
|
+
firefox_platform_headers!(
|
|
354
|
+
emulation,
|
|
355
|
+
$header_initializer,
|
|
356
|
+
[($default_os, $default_ua) $(, ($other_os, $other_ua))*]
|
|
357
|
+
)
|
|
358
|
+
}
|
|
195
359
|
);
|
|
196
360
|
};
|
|
197
361
|
(
|
|
198
|
-
$
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
$platforms:tt $(,)?
|
|
362
|
+
$mod_name:ident,
|
|
363
|
+
$build_emulation:expr,
|
|
364
|
+
$header_initializer:ident,
|
|
365
|
+
$ua:expr
|
|
203
366
|
) => {
|
|
204
|
-
standard_mod_generator!(
|
|
205
|
-
|
|
206
|
-
|
|
367
|
+
standard_mod_generator!(
|
|
368
|
+
$mod_name,
|
|
369
|
+
$build_emulation,
|
|
370
|
+
|emulation: &Emulation| fixed_headers!(emulation, $header_initializer, $ua)
|
|
371
|
+
);
|
|
207
372
|
};
|
|
208
373
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
use super::*;
|
|
2
|
+
|
|
3
|
+
pub fn header_initializer(
|
|
4
|
+
sec_ch_ua: &'static str,
|
|
5
|
+
ua: &'static str,
|
|
6
|
+
emulation_os: Platform,
|
|
7
|
+
) -> HeaderMap {
|
|
8
|
+
let mut headers = HeaderMap::new();
|
|
9
|
+
header_chrome_sec_ch_ua!(
|
|
10
|
+
headers,
|
|
11
|
+
sec_ch_ua,
|
|
12
|
+
emulation_os.platform(),
|
|
13
|
+
emulation_os.is_mobile()
|
|
14
|
+
);
|
|
15
|
+
headers.insert(
|
|
16
|
+
HeaderName::from_static("upgrade-insecure-requests"),
|
|
17
|
+
HeaderValue::from_static("1"),
|
|
18
|
+
);
|
|
19
|
+
header_chrome_ua!(headers, ua);
|
|
20
|
+
header_chrome_accept!(headers);
|
|
21
|
+
header_chrome_sec_fetch!(headers);
|
|
22
|
+
header_chrome_accept_encoding!(headers);
|
|
23
|
+
headers
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
pub fn header_initializer_with_zstd(
|
|
27
|
+
sec_ch_ua: &'static str,
|
|
28
|
+
ua: &'static str,
|
|
29
|
+
emulation_os: Platform,
|
|
30
|
+
) -> HeaderMap {
|
|
31
|
+
let mut headers = HeaderMap::new();
|
|
32
|
+
header_chrome_sec_ch_ua!(
|
|
33
|
+
headers,
|
|
34
|
+
sec_ch_ua,
|
|
35
|
+
emulation_os.platform(),
|
|
36
|
+
emulation_os.is_mobile()
|
|
37
|
+
);
|
|
38
|
+
headers.insert(
|
|
39
|
+
HeaderName::from_static("upgrade-insecure-requests"),
|
|
40
|
+
HeaderValue::from_static("1"),
|
|
41
|
+
);
|
|
42
|
+
header_chrome_ua!(headers, ua);
|
|
43
|
+
header_chrome_accept!(headers);
|
|
44
|
+
header_chrome_sec_fetch!(headers);
|
|
45
|
+
header_chrome_accept_encoding!(zstd, headers);
|
|
46
|
+
headers
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
pub fn header_initializer_with_zstd_priority(
|
|
50
|
+
sec_ch_ua: &'static str,
|
|
51
|
+
ua: &'static str,
|
|
52
|
+
emulation_os: Platform,
|
|
53
|
+
) -> HeaderMap {
|
|
54
|
+
let mut headers = HeaderMap::new();
|
|
55
|
+
header_chrome_sec_ch_ua!(
|
|
56
|
+
headers,
|
|
57
|
+
sec_ch_ua,
|
|
58
|
+
emulation_os.platform(),
|
|
59
|
+
emulation_os.is_mobile()
|
|
60
|
+
);
|
|
61
|
+
headers.insert(
|
|
62
|
+
HeaderName::from_static("upgrade-insecure-requests"),
|
|
63
|
+
HeaderValue::from_static("1"),
|
|
64
|
+
);
|
|
65
|
+
header_chrome_ua!(headers, ua);
|
|
66
|
+
header_chrome_accept!(headers);
|
|
67
|
+
header_chrome_sec_fetch!(headers);
|
|
68
|
+
header_chrome_accept_encoding!(zstd, headers);
|
|
69
|
+
headers.insert(
|
|
70
|
+
HeaderName::from_static("priority"),
|
|
71
|
+
HeaderValue::from_static("u=0, i"),
|
|
72
|
+
);
|
|
73
|
+
headers
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
pub fn header_initializer_chrome155(
|
|
77
|
+
sec_ch_ua: &'static str,
|
|
78
|
+
ua: &'static str,
|
|
79
|
+
emulation_os: Platform,
|
|
80
|
+
) -> HeaderMap {
|
|
81
|
+
let mut headers = header_initializer_with_zstd_priority(sec_ch_ua, ua, emulation_os);
|
|
82
|
+
// Chrome 155 enables JPEG XL in Blink; the iOS profile keeps its WebKit headers.
|
|
83
|
+
// https://chromium.googlesource.com/chromium/src/+/cfaadc5a132d78e1828635aa8405a499f3e14864/content/common/content_constants_internal.h
|
|
84
|
+
if !matches!(emulation_os, Platform::IOS) {
|
|
85
|
+
headers.insert(ACCEPT, HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"));
|
|
86
|
+
}
|
|
87
|
+
headers
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
pub fn header_initializer_chrome152(
|
|
91
|
+
sec_ch_ua: &'static str,
|
|
92
|
+
ua: &'static str,
|
|
93
|
+
emulation_os: Platform,
|
|
94
|
+
) -> HeaderMap {
|
|
95
|
+
let mut headers = HeaderMap::new();
|
|
96
|
+
header_chrome_sec_ch_ua!(
|
|
97
|
+
headers,
|
|
98
|
+
sec_ch_ua,
|
|
99
|
+
emulation_os.platform(),
|
|
100
|
+
emulation_os.is_mobile()
|
|
101
|
+
);
|
|
102
|
+
headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9"));
|
|
103
|
+
headers.insert(
|
|
104
|
+
HeaderName::from_static("upgrade-insecure-requests"),
|
|
105
|
+
HeaderValue::from_static("1"),
|
|
106
|
+
);
|
|
107
|
+
header_chrome_ua!(headers, ua);
|
|
108
|
+
header_chrome_accept!(headers);
|
|
109
|
+
header_chrome_sec_fetch!(headers);
|
|
110
|
+
header_chrome_accept_encoding!(zstd_only, headers);
|
|
111
|
+
headers.insert(
|
|
112
|
+
HeaderName::from_static("priority"),
|
|
113
|
+
HeaderValue::from_static("u=0, i"),
|
|
114
|
+
);
|
|
115
|
+
headers
|
|
116
|
+
}
|