wreq 1.3.2 → 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 -41
- data/Cargo.toml +11 -3
- data/README.md +1 -1
- data/crates/wreq-util/Cargo.toml +1 -0
- 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 +0 -1
- data/crates/wreq-util/src/emulate/profile/chrome/http2.rs +3 -3
- data/crates/wreq-util/src/emulate/profile/chrome/tls.rs +6 -35
- data/crates/wreq-util/src/emulate/profile/chrome.rs +36 -0
- data/crates/wreq-util/src/emulate/profile/firefox/http2.rs +11 -11
- data/crates/wreq-util/src/emulate/profile/okhttp.rs +2 -3
- data/crates/wreq-util/src/emulate/profile/opera/http2.rs +3 -3
- data/crates/wreq-util/src/emulate/profile.rs +5 -7
- data/crates/wreq-util/src/emulate.rs +1 -0
- 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 +7 -3
- data/crates/wreq-util/tests/emulate_chrome.rs +10 -0
- data/crates/wreq-util/tests/emulate_firefox.rs +26 -21
- data/crates/wreq-util/tests/support/mod.rs +1 -1
- data/lib/wreq_ruby/client.rb +27 -13
- data/lib/wreq_ruby/emulate.rb +5 -1
- data/lib/wreq_ruby/http.rb +9 -2
- data/src/client.rs +8 -4
- data/src/emulate.rs +1 -0
- data/test/emulation_test.rb +2 -1
- data/test/option_validation_test.rb +13 -4
- metadata +1 -1
data/Cargo.toml
CHANGED
|
@@ -5,7 +5,7 @@ authors = ["SearchApi <support@searchapi.io>"]
|
|
|
5
5
|
homepage = "https://github.com/SearchApi/wreq-ruby"
|
|
6
6
|
repository = "https://github.com/SearchApi/wreq-ruby"
|
|
7
7
|
edition = "2024"
|
|
8
|
-
version = "1.3.
|
|
8
|
+
version = "1.3.3"
|
|
9
9
|
rust-version = "1.98"
|
|
10
10
|
|
|
11
11
|
[lib]
|
|
@@ -20,6 +20,8 @@ tokio = { version = "1.53.1", features = ["full"] }
|
|
|
20
20
|
# Keep the existing trust store independent of wreq's default feature selection.
|
|
21
21
|
wreq = { version = "0.16.1", default-features = false, features = [
|
|
22
22
|
"tokio-rt",
|
|
23
|
+
"http2",
|
|
24
|
+
"http3",
|
|
23
25
|
"chromium-roots",
|
|
24
26
|
"query",
|
|
25
27
|
"form",
|
|
@@ -67,9 +69,15 @@ opt-level = 3
|
|
|
67
69
|
strip = true
|
|
68
70
|
|
|
69
71
|
[patch.crates-io]
|
|
70
|
-
|
|
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" }
|
|
71
79
|
btls = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" }
|
|
72
80
|
btls-sys = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" }
|
|
73
81
|
tokio-btls = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" }
|
|
74
|
-
wreq = { git = "https://github.com/0x676e67/wreq", rev = "
|
|
82
|
+
wreq = { git = "https://github.com/0x676e67/wreq", rev = "10029bb86ff88d8ed88b8e10518fe6e1f7ff322c" }
|
|
75
83
|
wreq-util = { path = "crates/wreq-util" }
|
data/README.md
CHANGED
|
@@ -91,7 +91,7 @@ Most browser device models share identical TLS and HTTP/2 configurations, differ
|
|
|
91
91
|
|
|
92
92
|
| **Browser** | **Versions** |
|
|
93
93
|
| ----------- | ------------ |
|
|
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` |
|
|
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
95
|
| **Edge** | `Edge101`, `Edge122`, `Edge127`, `Edge131`, `Edge134`, `Edge135`, `Edge136`, `Edge137`, `Edge138`, `Edge139`, `Edge140`, `Edge141`, `Edge142`, `Edge143`, `Edge144`, `Edge145`, `Edge146`, `Edge147`, `Edge148` |
|
|
96
96
|
| **Firefox** | `Firefox109`, `Firefox117`, `Firefox128`, `Firefox133`, `Firefox135`, `FirefoxPrivate135`, `FirefoxAndroid135`, `Firefox136`, `FirefoxPrivate136`, `Firefox139`, `Firefox142`, `Firefox143`, `Firefox144`, `Firefox145`, `Firefox146`, `Firefox147`, `Firefox148`, `Firefox149`, `Firefox150`, `Firefox151`, `Firefox152` |
|
|
97
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` |
|
data/crates/wreq-util/Cargo.toml
CHANGED
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
macro_rules!
|
|
1
|
+
macro_rules! headers_priority {
|
|
2
2
|
() => {
|
|
3
|
-
|
|
3
|
+
HeadersPriority::new(HeadersDependency::Root, 255, true)
|
|
4
4
|
};
|
|
5
5
|
}
|
|
6
6
|
|
|
@@ -41,7 +41,7 @@ macro_rules! http2_options {
|
|
|
41
41
|
.initial_connection_window_size(15728640)
|
|
42
42
|
.max_header_list_size(262144)
|
|
43
43
|
.header_table_size(65536)
|
|
44
|
-
.
|
|
44
|
+
.headers_priority(headers_priority!())
|
|
45
45
|
.headers_pseudo_order(pseudo_order!())
|
|
46
46
|
.settings_order(settings_order!())
|
|
47
47
|
};
|
|
@@ -232,43 +232,14 @@ impl From<ChromeTlsConfig> for TlsOptions {
|
|
|
232
232
|
#[cfg(test)]
|
|
233
233
|
mod tests {
|
|
234
234
|
use super::*;
|
|
235
|
-
use wreq::IntoEmulation;
|
|
236
235
|
|
|
237
236
|
#[test]
|
|
238
|
-
fn
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
crate::Profile::Chrome156,
|
|
245
|
-
] {
|
|
246
|
-
let native = profile.into_emulation();
|
|
247
|
-
let cloned = native.clone();
|
|
248
|
-
let ids = native.tls_options.unwrap().trust_anchors.unwrap();
|
|
249
|
-
assert_eq!(ids.len(), CHROME_TRUST_ANCHORS.len());
|
|
250
|
-
assert_eq!(ids, cloned.tls_options.unwrap().trust_anchors.unwrap());
|
|
251
|
-
let decoded = decode_ids(&ids);
|
|
252
|
-
let mut expected = chromium_roots::trust_anchor_ids();
|
|
253
|
-
expected.sort_unstable();
|
|
254
|
-
if matches!(
|
|
255
|
-
profile,
|
|
256
|
-
crate::Profile::Chrome154 | crate::Profile::Chrome155 | crate::Profile::Chrome156
|
|
257
|
-
) {
|
|
258
|
-
assert_eq!(decoded, expected);
|
|
259
|
-
}
|
|
260
|
-
let mut actual = decoded;
|
|
261
|
-
actual.sort_unstable();
|
|
262
|
-
assert_eq!(actual, expected);
|
|
263
|
-
}
|
|
264
|
-
assert!(
|
|
265
|
-
crate::Profile::Chrome151
|
|
266
|
-
.into_emulation()
|
|
267
|
-
.tls_options
|
|
268
|
-
.unwrap()
|
|
269
|
-
.trust_anchors
|
|
270
|
-
.is_none()
|
|
271
|
-
);
|
|
237
|
+
fn sorted_trust_anchors_match_chromium_root_store() {
|
|
238
|
+
let encoded = sorted_trust_anchors();
|
|
239
|
+
let mut expected = chromium_roots::trust_anchor_ids();
|
|
240
|
+
expected.sort_unstable();
|
|
241
|
+
assert_eq!(decode_ids(&encoded), expected);
|
|
242
|
+
assert_eq!(encoded.len(), CHROME_TRUST_ANCHORS.len());
|
|
272
243
|
}
|
|
273
244
|
|
|
274
245
|
#[test]
|
|
@@ -2034,6 +2034,42 @@ mod_generator!(
|
|
|
2034
2034
|
]
|
|
2035
2035
|
);
|
|
2036
2036
|
|
|
2037
|
+
// Chrome 157 retains Chrome 156's TLS/HTTP2 and Accept configuration.
|
|
2038
|
+
// Its UA-CH order and GREASE brand are seeded by major version 157.
|
|
2039
|
+
// https://chromium.googlesource.com/chromium/src/+/653674df293788cf4932c40d914e9e15b41a2d31/components/embedder_support/user_agent_utils.cc
|
|
2040
|
+
mod_generator!(
|
|
2041
|
+
v157,
|
|
2042
|
+
v154::build_emulation,
|
|
2043
|
+
header_initializer_chrome155,
|
|
2044
|
+
[
|
|
2045
|
+
(
|
|
2046
|
+
MacOS,
|
|
2047
|
+
r#""Not-A.Brand";v="99", "Google Chrome";v="157", "Chromium";v="157""#,
|
|
2048
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36"
|
|
2049
|
+
),
|
|
2050
|
+
(
|
|
2051
|
+
Linux,
|
|
2052
|
+
r#""Not-A.Brand";v="99", "Google Chrome";v="157", "Chromium";v="157""#,
|
|
2053
|
+
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36"
|
|
2054
|
+
),
|
|
2055
|
+
(
|
|
2056
|
+
Android,
|
|
2057
|
+
r#""Not-A.Brand";v="99", "Google Chrome";v="157", "Chromium";v="157""#,
|
|
2058
|
+
"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Mobile Safari/537.36"
|
|
2059
|
+
),
|
|
2060
|
+
(
|
|
2061
|
+
Windows,
|
|
2062
|
+
r#""Not-A.Brand";v="99", "Google Chrome";v="157", "Chromium";v="157""#,
|
|
2063
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36"
|
|
2064
|
+
),
|
|
2065
|
+
(
|
|
2066
|
+
IOS,
|
|
2067
|
+
r#""Not-A.Brand";v="99", "Google Chrome";v="157", "Chromium";v="157""#,
|
|
2068
|
+
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/157.0.8103.37 Mobile/15E148 Safari/604.1"
|
|
2069
|
+
)
|
|
2070
|
+
]
|
|
2071
|
+
);
|
|
2072
|
+
|
|
2037
2073
|
mod_generator!(
|
|
2038
2074
|
edge143,
|
|
2039
2075
|
v132::build_emulation,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
macro_rules!
|
|
1
|
+
macro_rules! headers_priority {
|
|
2
2
|
(1) => {
|
|
3
|
-
|
|
3
|
+
HeadersPriority::new(HeadersDependency::Root, 41, false)
|
|
4
4
|
};
|
|
5
5
|
(2) => {
|
|
6
|
-
|
|
6
|
+
HeadersPriority::new(HeadersDependency::Declared(StreamId::from(13)), 41, false)
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -52,28 +52,28 @@ macro_rules! http2_options {
|
|
|
52
52
|
.initial_stream_id(3)
|
|
53
53
|
.header_table_size(65536)
|
|
54
54
|
.enable_push(false)
|
|
55
|
-
.
|
|
55
|
+
.headers_priority(headers_priority!(1))
|
|
56
56
|
.build()
|
|
57
57
|
};
|
|
58
58
|
(2) => {
|
|
59
59
|
http2_options!(@base Http2Options::builder())
|
|
60
60
|
.initial_stream_id(15)
|
|
61
61
|
.header_table_size(65536)
|
|
62
|
-
.
|
|
62
|
+
.headers_priority(headers_priority!(2))
|
|
63
63
|
.priorities(
|
|
64
64
|
Priorities::builder()
|
|
65
65
|
.extend([
|
|
66
66
|
Priority::new(
|
|
67
67
|
StreamId::from(3),
|
|
68
|
-
StreamDependency::new(StreamId::
|
|
68
|
+
StreamDependency::new(StreamId::from(0), 200, false),
|
|
69
69
|
),
|
|
70
70
|
Priority::new(
|
|
71
71
|
StreamId::from(5),
|
|
72
|
-
StreamDependency::new(StreamId::
|
|
72
|
+
StreamDependency::new(StreamId::from(0), 100, false),
|
|
73
73
|
),
|
|
74
74
|
Priority::new(
|
|
75
75
|
StreamId::from(7),
|
|
76
|
-
StreamDependency::new(StreamId::
|
|
76
|
+
StreamDependency::new(StreamId::from(0), 0, false),
|
|
77
77
|
),
|
|
78
78
|
Priority::new(
|
|
79
79
|
StreamId::from(9),
|
|
@@ -85,7 +85,7 @@ macro_rules! http2_options {
|
|
|
85
85
|
),
|
|
86
86
|
Priority::new(
|
|
87
87
|
StreamId::from(13),
|
|
88
|
-
StreamDependency::new(StreamId::
|
|
88
|
+
StreamDependency::new(StreamId::from(0), 240, false),
|
|
89
89
|
),
|
|
90
90
|
])
|
|
91
91
|
.build(),
|
|
@@ -98,7 +98,7 @@ macro_rules! http2_options {
|
|
|
98
98
|
.header_table_size(65536)
|
|
99
99
|
.enable_push(false)
|
|
100
100
|
.max_concurrent_streams(0)
|
|
101
|
-
.
|
|
101
|
+
.headers_priority(headers_priority!(1))
|
|
102
102
|
.build()
|
|
103
103
|
};
|
|
104
104
|
(4) => {
|
|
@@ -107,7 +107,7 @@ macro_rules! http2_options {
|
|
|
107
107
|
.header_table_size(4096)
|
|
108
108
|
.enable_push(false)
|
|
109
109
|
.initial_window_size(32768)
|
|
110
|
-
.
|
|
110
|
+
.headers_priority(headers_priority!(1))
|
|
111
111
|
.build()
|
|
112
112
|
};
|
|
113
113
|
}
|
|
@@ -69,14 +69,13 @@ macro_rules! mod_generator {
|
|
|
69
69
|
use super::*;
|
|
70
70
|
|
|
71
71
|
pub fn emulation(emulation: Emulation) -> wreq::Emulation {
|
|
72
|
-
build_emulation(
|
|
72
|
+
build_emulation(emulation, $cipher, $ua)
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
fn build_emulation(
|
|
79
|
-
group: &'static str,
|
|
80
79
|
emulation: Emulation,
|
|
81
80
|
cipher_list: &'static str,
|
|
82
81
|
user_agent: &'static str,
|
|
@@ -127,7 +126,7 @@ fn build_emulation(
|
|
|
127
126
|
headers
|
|
128
127
|
});
|
|
129
128
|
|
|
130
|
-
build_standard_emulation(
|
|
129
|
+
build_standard_emulation(tls_options, http2_options, headers)
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
mod_generator!(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
macro_rules!
|
|
1
|
+
macro_rules! headers_priority {
|
|
2
2
|
() => {
|
|
3
|
-
|
|
3
|
+
HeadersPriority::new(HeadersDependency::Root, 255, true)
|
|
4
4
|
};
|
|
5
5
|
}
|
|
6
6
|
|
|
@@ -42,7 +42,7 @@ macro_rules! http2_options {
|
|
|
42
42
|
.max_header_list_size(262144)
|
|
43
43
|
.header_table_size(65536)
|
|
44
44
|
.enable_push(false)
|
|
45
|
-
.
|
|
45
|
+
.headers_priority(headers_priority!())
|
|
46
46
|
.headers_pseudo_order(pseudo_order!())
|
|
47
47
|
.settings_order(settings_order!())
|
|
48
48
|
.build()
|
|
@@ -10,11 +10,10 @@ use typed_builder::TypedBuilder;
|
|
|
10
10
|
#[cfg(feature = "emulation-compression")]
|
|
11
11
|
use wreq::header::ACCEPT_ENCODING;
|
|
12
12
|
use wreq::{
|
|
13
|
-
Group,
|
|
14
13
|
header::{ACCEPT, ACCEPT_LANGUAGE, HeaderMap, HeaderName, HeaderValue, USER_AGENT},
|
|
15
14
|
http2::{
|
|
16
|
-
Http2Options, Priorities, Priority, PseudoId,
|
|
17
|
-
StreamDependency, StreamId,
|
|
15
|
+
HeadersDependency, HeadersPriority, Http2Options, Priorities, Priority, PseudoId,
|
|
16
|
+
PseudoOrder, SettingId, SettingsOrder, StreamDependency, StreamId,
|
|
18
17
|
},
|
|
19
18
|
tls::{
|
|
20
19
|
AlpnProtocol, AlpsProtocol, EchGrease, EchGreaseAead, ExtensionType, KeyShare, Tls13Cipher,
|
|
@@ -28,20 +27,19 @@ use super::{
|
|
|
28
27
|
};
|
|
29
28
|
|
|
30
29
|
fn build_standard_emulation(
|
|
31
|
-
group: &'static str,
|
|
32
30
|
tls_options: TlsOptions,
|
|
33
31
|
http2_options: Option<Http2Options>,
|
|
34
32
|
default_headers: Option<HeaderMap>,
|
|
35
33
|
) -> wreq::Emulation {
|
|
36
|
-
let mut builder = wreq::Emulation::builder().
|
|
34
|
+
let mut builder = wreq::Emulation::builder().config(tls_options);
|
|
37
35
|
|
|
38
36
|
if let Some(http2_options) = http2_options {
|
|
39
|
-
builder = builder.
|
|
37
|
+
builder = builder.config(http2_options);
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
if let Some(headers) = default_headers {
|
|
43
41
|
builder = builder.headers(headers);
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
builder.build(
|
|
44
|
+
builder.build()
|
|
47
45
|
}
|
|
@@ -67,6 +67,7 @@ define_enum!(
|
|
|
67
67
|
Chrome154 => ("chrome_154", v154::emulation),
|
|
68
68
|
Chrome155 => ("chrome_155", v155::emulation),
|
|
69
69
|
Chrome156 => ("chrome_156", v156::emulation),
|
|
70
|
+
Chrome157 => ("chrome_157", v157::emulation),
|
|
70
71
|
|
|
71
72
|
// Edge versions
|
|
72
73
|
Edge101 => ("edge_101", edge101::emulation),
|
|
@@ -29,10 +29,10 @@ pub struct DelayLayerWith<P> {
|
|
|
29
29
|
/// ```no_run
|
|
30
30
|
/// use std::time::Duration;
|
|
31
31
|
/// use wreq::Client;
|
|
32
|
-
/// use wreq_util::
|
|
32
|
+
/// use wreq_util::tower::delay::JitterDelayLayer;
|
|
33
33
|
///
|
|
34
34
|
/// // Creates delays in range [0.8s, 1.2s] (1s ± 20%)
|
|
35
|
-
/// let client = Client::
|
|
35
|
+
/// let client = Client::builder_tokio()
|
|
36
36
|
/// .layer(JitterDelayLayer::new(Duration::from_secs(1), 0.2))
|
|
37
37
|
/// .build()?;
|
|
38
38
|
/// # Ok::<(), wreq::Error>(())
|
|
@@ -71,7 +71,7 @@ impl DelayLayer {
|
|
|
71
71
|
/// ```ignore
|
|
72
72
|
/// use std::time::Duration;
|
|
73
73
|
/// use http::Request;
|
|
74
|
-
/// use wreq_util::
|
|
74
|
+
/// use wreq_util::tower::delay::DelayLayer;
|
|
75
75
|
///
|
|
76
76
|
/// // Only delay POST requests
|
|
77
77
|
/// let layer = DelayLayer::new(Duration::from_secs(1))
|
|
@@ -129,7 +129,7 @@ impl JitterDelayLayer {
|
|
|
129
129
|
///
|
|
130
130
|
/// ```
|
|
131
131
|
/// use std::time::Duration;
|
|
132
|
-
/// use wreq_util::
|
|
132
|
+
/// use wreq_util::tower::delay::JitterDelayLayer;
|
|
133
133
|
///
|
|
134
134
|
/// // Creates delays in range [800ms, 1200ms]
|
|
135
135
|
/// let layer = JitterDelayLayer::new(Duration::from_secs(1), 0.2);
|
|
@@ -151,7 +151,7 @@ impl JitterDelayLayer {
|
|
|
151
151
|
/// ```ignore
|
|
152
152
|
/// use std::time::Duration;
|
|
153
153
|
/// use http::Request;
|
|
154
|
-
/// use wreq_util::
|
|
154
|
+
/// use wreq_util::tower::delay::JitterDelayLayer;
|
|
155
155
|
///
|
|
156
156
|
/// // Only delay requests to paths starting with "/slow"
|
|
157
157
|
/// let layer = JitterDelayLayer::new(Duration::from_secs(1), 0.2)
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
//! ```no_run
|
|
11
11
|
//! use std::time::Duration;
|
|
12
12
|
//! use wreq::Client;
|
|
13
|
-
//! use wreq_util::
|
|
13
|
+
//! use wreq_util::tower::delay::DelayLayer;
|
|
14
14
|
//!
|
|
15
|
-
//! let client = Client::
|
|
15
|
+
//! let client = Client::builder_tokio()
|
|
16
16
|
//! .layer(DelayLayer::new(Duration::from_secs(1)))
|
|
17
17
|
//! .build()?;
|
|
18
18
|
//! # Ok::<(), wreq::Error>(())
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
//! ```no_run
|
|
24
24
|
//! use std::time::Duration;
|
|
25
25
|
//! use wreq::Client;
|
|
26
|
-
//! use wreq_util::
|
|
26
|
+
//! use wreq_util::tower::delay::JitterDelayLayer;
|
|
27
27
|
//!
|
|
28
|
-
//! let client = Client::
|
|
28
|
+
//! let client = Client::builder_tokio()
|
|
29
29
|
//! .layer(JitterDelayLayer::new(Duration::from_secs(1), 0.2))
|
|
30
30
|
//! .build()?;
|
|
31
31
|
//! # Ok::<(), wreq::Error>(())
|
|
@@ -80,7 +80,7 @@ async fn assert_emulation_headers(profile: Profile, expected: &'static [&'static
|
|
|
80
80
|
let server = server::low_level_with_response(move |request, stream| {
|
|
81
81
|
check_header_order(request, stream, expected)
|
|
82
82
|
});
|
|
83
|
-
let response = Client::
|
|
83
|
+
let response = Client::builder_tokio()
|
|
84
84
|
.emulation(profile)
|
|
85
85
|
.build()
|
|
86
86
|
.expect("client")
|
|
@@ -95,7 +95,11 @@ async fn assert_emulation_headers(profile: Profile, expected: &'static [&'static
|
|
|
95
95
|
#[tokio::test]
|
|
96
96
|
async fn test_client_emulation_device() {
|
|
97
97
|
let server = server::http(move |req| async move {
|
|
98
|
-
let header = |name|
|
|
98
|
+
let header = |name| {
|
|
99
|
+
req.headers()
|
|
100
|
+
.get(name)
|
|
101
|
+
.and_then(|value| value.to_str().ok())
|
|
102
|
+
};
|
|
99
103
|
|
|
100
104
|
assert_eq!(
|
|
101
105
|
header("user-agent"),
|
|
@@ -113,7 +117,7 @@ async fn test_client_emulation_device() {
|
|
|
113
117
|
});
|
|
114
118
|
|
|
115
119
|
let url = format!("http://{}/ua", server.addr());
|
|
116
|
-
let res = Client::
|
|
120
|
+
let res = Client::builder_tokio()
|
|
117
121
|
.emulation(
|
|
118
122
|
Emulation::builder()
|
|
119
123
|
.profile(Emulation::Chrome151)
|
|
@@ -325,3 +325,13 @@ test_emulation!(
|
|
|
325
325
|
],
|
|
326
326
|
"52d84b11737d980aef856699f885ca86"
|
|
327
327
|
);
|
|
328
|
+
|
|
329
|
+
test_emulation!(
|
|
330
|
+
test_chrome157,
|
|
331
|
+
Emulation::Chrome157,
|
|
332
|
+
[
|
|
333
|
+
"t13d1517h2_8daaf6152771_cb7bf5808d99",
|
|
334
|
+
"t13d1518h2_8daaf6152771_e2d80978ab2e"
|
|
335
|
+
],
|
|
336
|
+
"52d84b11737d980aef856699f885ca86"
|
|
337
|
+
);
|
|
@@ -118,9 +118,8 @@ test_emulation!(
|
|
|
118
118
|
///
|
|
119
119
|
/// Every profile is listed rather than a range, so adding one is a deliberate choice about
|
|
120
120
|
/// which side of 147 it falls on.
|
|
121
|
-
#[test]
|
|
122
|
-
fn firefox_accept_language_matches_the_profile_version() {
|
|
123
|
-
use wreq::IntoEmulation;
|
|
121
|
+
#[tokio::test]
|
|
122
|
+
async fn firefox_accept_language_matches_the_profile_version() {
|
|
124
123
|
use wreq_util::{Platform, Profile};
|
|
125
124
|
|
|
126
125
|
const PRE_147: &[(&str, Profile)] = &[
|
|
@@ -149,23 +148,29 @@ fn firefox_accept_language_matches_the_profile_version() {
|
|
|
149
148
|
("Firefox152", Emulation::Firefox152),
|
|
150
149
|
];
|
|
151
150
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
151
|
+
let server = support::server::http(|request| async move {
|
|
152
|
+
let mut response = http::Response::default();
|
|
153
|
+
response.headers_mut().insert(
|
|
154
|
+
"accept-language",
|
|
155
|
+
request.headers()["accept-language"].clone(),
|
|
156
|
+
);
|
|
157
|
+
response
|
|
158
|
+
});
|
|
159
|
+
let client = wreq::Client::builder_tokio().no_proxy().build().unwrap();
|
|
160
|
+
for (profiles, expected) in [(PRE_147, "en-US,en;q=0.5"), (POST_147, "en-US,en;q=0.9")] {
|
|
161
|
+
for (name, profile) in profiles {
|
|
162
|
+
let response = client
|
|
163
|
+
.get(format!("http://{}/", server.addr()))
|
|
164
|
+
.emulation(
|
|
165
|
+
Emulation::builder()
|
|
166
|
+
.profile(*profile)
|
|
167
|
+
.platform(Platform::Linux)
|
|
168
|
+
.build(),
|
|
169
|
+
)
|
|
170
|
+
.send()
|
|
171
|
+
.await
|
|
172
|
+
.unwrap();
|
|
173
|
+
assert_eq!(response.headers()["accept-language"], expected, "{name}");
|
|
174
|
+
}
|
|
170
175
|
}
|
|
171
176
|
}
|
|
@@ -14,7 +14,7 @@ pub static DEFAULT_USER_AGENT: &str =
|
|
|
14
14
|
pub static TEST_SEMAPHORE: LazyLock<Semaphore> = LazyLock::new(|| Semaphore::new(1));
|
|
15
15
|
|
|
16
16
|
pub static CLIENT: LazyLock<Client> = LazyLock::new(|| {
|
|
17
|
-
Client::
|
|
17
|
+
Client::builder_tokio()
|
|
18
18
|
.connect_timeout(Duration::from_secs(60))
|
|
19
19
|
.build()
|
|
20
20
|
.unwrap()
|