wreq 1.3.2.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 +458 -17
- data/Cargo.toml +14 -9
- data/README.md +1 -1
- 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 +0 -1
- data/crates/wreq-util/src/emulate/profile/chrome/tls.rs +6 -39
- data/crates/wreq-util/src/emulate/profile/chrome.rs +0 -35
- data/crates/wreq-util/src/emulate/profile/firefox/http2.rs +1 -1
- data/crates/wreq-util/src/emulate/profile/okhttp.rs +2 -3
- data/crates/wreq-util/src/emulate/profile.rs +3 -5
- data/crates/wreq-util/src/emulate.rs +0 -1
- 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 +0 -10
- 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 +3 -1
- data/lib/wreq_ruby/http.rb +9 -2
- data/src/client.rs +8 -4
- data/src/emulate.rs +5 -1
- data/src/lib.rs +2 -2
- data/test/emulation_test.rb +0 -1
- data/test/option_validation_test.rb +13 -4
- data/wreq.gemspec +15 -3
- metadata +2 -4
- data/VERSION +0 -1
- data/crates/README.md +0 -5
data/Cargo.toml
CHANGED
|
@@ -5,8 +5,8 @@ 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.
|
|
9
|
-
rust-version = "1.
|
|
8
|
+
version = "1.3.3"
|
|
9
|
+
rust-version = "1.98"
|
|
10
10
|
|
|
11
11
|
[lib]
|
|
12
12
|
crate-type = ["cdylib"]
|
|
@@ -21,6 +21,7 @@ tokio = { version = "1.53.1", features = ["full"] }
|
|
|
21
21
|
wreq = { version = "0.16.1", default-features = false, features = [
|
|
22
22
|
"tokio-rt",
|
|
23
23
|
"http2",
|
|
24
|
+
"http3",
|
|
24
25
|
"chromium-roots",
|
|
25
26
|
"query",
|
|
26
27
|
"form",
|
|
@@ -68,11 +69,15 @@ opt-level = 3
|
|
|
68
69
|
strip = true
|
|
69
70
|
|
|
70
71
|
[patch.crates-io]
|
|
71
|
-
#
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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" }
|
|
78
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`, `Chrome157
|
|
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
|
@@ -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
|
|
@@ -232,47 +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
|
-
crate::Profile::Chrome157,
|
|
246
|
-
] {
|
|
247
|
-
let native = profile.into_emulation();
|
|
248
|
-
let cloned = native.clone();
|
|
249
|
-
let ids = native.tls_options.unwrap().trust_anchors.unwrap();
|
|
250
|
-
assert_eq!(ids.len(), CHROME_TRUST_ANCHORS.len());
|
|
251
|
-
assert_eq!(ids, cloned.tls_options.unwrap().trust_anchors.unwrap());
|
|
252
|
-
let decoded = decode_ids(&ids);
|
|
253
|
-
let mut expected = chromium_roots::trust_anchor_ids();
|
|
254
|
-
expected.sort_unstable();
|
|
255
|
-
if matches!(
|
|
256
|
-
profile,
|
|
257
|
-
crate::Profile::Chrome154
|
|
258
|
-
| crate::Profile::Chrome155
|
|
259
|
-
| crate::Profile::Chrome156
|
|
260
|
-
| crate::Profile::Chrome157
|
|
261
|
-
) {
|
|
262
|
-
assert_eq!(decoded, expected);
|
|
263
|
-
}
|
|
264
|
-
let mut actual = decoded;
|
|
265
|
-
actual.sort_unstable();
|
|
266
|
-
assert_eq!(actual, expected);
|
|
267
|
-
}
|
|
268
|
-
assert!(
|
|
269
|
-
crate::Profile::Chrome151
|
|
270
|
-
.into_emulation()
|
|
271
|
-
.tls_options
|
|
272
|
-
.unwrap()
|
|
273
|
-
.trust_anchors
|
|
274
|
-
.is_none()
|
|
275
|
-
);
|
|
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());
|
|
276
243
|
}
|
|
277
244
|
|
|
278
245
|
#[test]
|
|
@@ -2070,41 +2070,6 @@ mod_generator!(
|
|
|
2070
2070
|
]
|
|
2071
2071
|
);
|
|
2072
2072
|
|
|
2073
|
-
// Chrome 158 retains the Chrome 157 TLS, HTTP/2 and Accept presets.
|
|
2074
|
-
// https://chromium.googlesource.com/chromium/src/+/b8c2be851f62f6a394ec57955d7f31335d7cb6d4/components/embedder_support/user_agent_utils.cc
|
|
2075
|
-
mod_generator!(
|
|
2076
|
-
v158,
|
|
2077
|
-
v154::build_emulation,
|
|
2078
|
-
header_initializer_chrome155,
|
|
2079
|
-
[
|
|
2080
|
-
(
|
|
2081
|
-
MacOS,
|
|
2082
|
-
r#""Chromium";v="158", "Not.A/Brand";v="24", "Google Chrome";v="158""#,
|
|
2083
|
-
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"
|
|
2084
|
-
),
|
|
2085
|
-
(
|
|
2086
|
-
Linux,
|
|
2087
|
-
r#""Chromium";v="158", "Not.A/Brand";v="24", "Google Chrome";v="158""#,
|
|
2088
|
-
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"
|
|
2089
|
-
),
|
|
2090
|
-
(
|
|
2091
|
-
Android,
|
|
2092
|
-
r#""Chromium";v="158", "Not.A/Brand";v="24", "Google Chrome";v="158""#,
|
|
2093
|
-
"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Mobile Safari/537.36"
|
|
2094
|
-
),
|
|
2095
|
-
(
|
|
2096
|
-
Windows,
|
|
2097
|
-
r#""Chromium";v="158", "Not.A/Brand";v="24", "Google Chrome";v="158""#,
|
|
2098
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/158.0.0.0 Safari/537.36"
|
|
2099
|
-
),
|
|
2100
|
-
(
|
|
2101
|
-
IOS,
|
|
2102
|
-
r#""Chromium";v="158", "Not.A/Brand";v="24", "Google Chrome";v="158""#,
|
|
2103
|
-
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_7_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/158.0.8127.35 Mobile/15E148 Safari/604.1"
|
|
2104
|
-
)
|
|
2105
|
-
]
|
|
2106
|
-
);
|
|
2107
|
-
|
|
2108
2073
|
mod_generator!(
|
|
2109
2074
|
edge143,
|
|
2110
2075
|
v132::build_emulation,
|
|
@@ -3,7 +3,7 @@ macro_rules! headers_priority {
|
|
|
3
3
|
HeadersPriority::new(HeadersDependency::Root, 41, false)
|
|
4
4
|
};
|
|
5
5
|
(2) => {
|
|
6
|
-
HeadersPriority::new(HeadersDependency::Declared(
|
|
6
|
+
HeadersPriority::new(HeadersDependency::Declared(StreamId::from(13)), 41, false)
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -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!(
|
|
@@ -10,7 +10,6 @@ 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
15
|
HeadersDependency, HeadersPriority, Http2Options, Priorities, Priority, PseudoId,
|
|
@@ -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
|
}
|
|
@@ -68,7 +68,6 @@ define_enum!(
|
|
|
68
68
|
Chrome155 => ("chrome_155", v155::emulation),
|
|
69
69
|
Chrome156 => ("chrome_156", v156::emulation),
|
|
70
70
|
Chrome157 => ("chrome_157", v157::emulation),
|
|
71
|
-
Chrome158 => ("chrome_158", v158::emulation),
|
|
72
71
|
|
|
73
72
|
// Edge versions
|
|
74
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)
|
|
@@ -335,13 +335,3 @@ test_emulation!(
|
|
|
335
335
|
],
|
|
336
336
|
"52d84b11737d980aef856699f885ca86"
|
|
337
337
|
);
|
|
338
|
-
|
|
339
|
-
test_emulation!(
|
|
340
|
-
test_chrome158,
|
|
341
|
-
Emulation::Chrome158,
|
|
342
|
-
[
|
|
343
|
-
"t13d1517h2_8daaf6152771_cb7bf5808d99",
|
|
344
|
-
"t13d1518h2_8daaf6152771_e2d80978ab2e"
|
|
345
|
-
],
|
|
346
|
-
"52d84b11737d980aef856699f885ca86"
|
|
347
|
-
);
|
|
@@ -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()
|
data/lib/wreq_ruby/client.rb
CHANGED
|
@@ -5,7 +5,7 @@ unless defined?(Wreq)
|
|
|
5
5
|
# HTTP client with extensive configuration options.
|
|
6
6
|
#
|
|
7
7
|
# This class wraps a native Rust implementation providing high-performance
|
|
8
|
-
# HTTP/1.1 and HTTP/
|
|
8
|
+
# HTTP/1.1, HTTP/2 and HTTP/3 client functionality with support for connection pooling,
|
|
9
9
|
# compression, redirects, proxies, and fine-grained timeout controls.
|
|
10
10
|
#
|
|
11
11
|
# The client is thread-safe and maintains an internal connection pool for
|
|
@@ -110,25 +110,37 @@ unless defined?(Wreq)
|
|
|
110
110
|
# allowing the reuse of local addresses in TIME_WAIT state. Useful for
|
|
111
111
|
# reducing port exhaustion in high-throughput scenarios.
|
|
112
112
|
#
|
|
113
|
-
# @param pool_idle_timeout [Integer, nil]
|
|
114
|
-
#
|
|
115
|
-
#
|
|
113
|
+
# @param pool_idle_timeout [Integer, nil] Idle connection reuse timeout in
|
|
114
|
+
# seconds. Defaults to 90 when omitted or nil. Does not expire a busy
|
|
115
|
+
# HTTP/2 or HTTP/3 connection.
|
|
116
116
|
#
|
|
117
|
-
# @param pool_max_idle_per_host [Integer, nil] Maximum
|
|
118
|
-
# connections
|
|
119
|
-
#
|
|
117
|
+
# @param pool_max_idle_per_host [Integer, nil] Maximum idle HTTP/1
|
|
118
|
+
# connections retained per compatibility group, which includes the host
|
|
119
|
+
# and connection configuration. Defaults to unlimited when omitted or
|
|
120
|
+
# nil; 0 disables connection reuse. Does not limit active connections.
|
|
120
121
|
#
|
|
121
|
-
# @param pool_max_size [Integer, nil]
|
|
122
|
-
#
|
|
123
|
-
#
|
|
122
|
+
# @param pool_max_size [Integer, nil] Maximum compatibility groups retaining
|
|
123
|
+
# idle HTTP/1 or shared HTTP/2 and HTTP/3 connections. Defaults to unlimited
|
|
124
|
+
# when omitted, nil or 0. A full pool evicts the least recently used idle
|
|
125
|
+
# group; it does not make requests wait or limit physical connections.
|
|
124
126
|
#
|
|
125
127
|
# @param http1_only [Boolean, nil] Force the client to use HTTP/1.1 only,
|
|
126
128
|
# even if HTTP/2 is available. Useful for compatibility with servers
|
|
127
|
-
# that have problematic HTTP/2 implementations.
|
|
129
|
+
# that have problematic HTTP/2 implementations. Cannot be combined with
|
|
130
|
+
# http2_only or http3_only. An explicit request version overrides this
|
|
131
|
+
# preference.
|
|
128
132
|
#
|
|
129
133
|
# @param http2_only [Boolean, nil] Force the client to use HTTP/2 only.
|
|
130
134
|
# Requests to servers that don't support HTTP/2 will fail. Cannot be
|
|
131
|
-
# combined with http1_only.
|
|
135
|
+
# combined with http1_only or http3_only. An explicit request version
|
|
136
|
+
# overrides this preference, including HTTP/3 over QUIC.
|
|
137
|
+
#
|
|
138
|
+
# @param http3_only [Boolean, nil] Use HTTP/3 over QUIC without falling back
|
|
139
|
+
# to TCP. Defaults to false when omitted or nil. Requires HTTPS and UDP
|
|
140
|
+
# connectivity. Cannot be combined with http1_only or http2_only. An
|
|
141
|
+
# explicit HTTP/1 or HTTP/2 request version overrides this preference.
|
|
142
|
+
# HTTP/HTTPS proxies, including environment proxies, cannot carry HTTP/3;
|
|
143
|
+
# use no_proxy: true, a SOCKS5 UDP proxy, or a QUIC MASQUE proxy instead.
|
|
132
144
|
#
|
|
133
145
|
# @param https_only [Boolean, nil] Reject plain HTTP connections and
|
|
134
146
|
# only allow HTTPS. Provides an additional layer of security by
|
|
@@ -149,7 +161,9 @@ unless defined?(Wreq)
|
|
|
149
161
|
# environment.
|
|
150
162
|
#
|
|
151
163
|
# @param proxy [String, nil] Proxy server URI to use for all requests.
|
|
152
|
-
# Supports HTTP, HTTPS, and
|
|
164
|
+
# Supports HTTP, HTTPS, SOCKS and QUIC proxies. HTTP/3 can use SOCKS5 UDP
|
|
165
|
+
# ASSOCIATE or a `quic://` MASQUE proxy, but not HTTP CONNECT proxies.
|
|
166
|
+
# Format: "protocol://host:port"
|
|
153
167
|
# Example: "http://proxy.example.com:8080"
|
|
154
168
|
# @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable.
|
|
155
169
|
# @param interface [String, nil] Bind sockets to a network interface on
|
data/lib/wreq_ruby/emulate.rb
CHANGED
|
@@ -69,7 +69,6 @@ module Wreq
|
|
|
69
69
|
Chrome155 = nil
|
|
70
70
|
Chrome156 = nil
|
|
71
71
|
Chrome157 = nil
|
|
72
|
-
Chrome158 = nil
|
|
73
72
|
|
|
74
73
|
Edge101 = nil
|
|
75
74
|
Edge122 = nil
|
|
@@ -268,6 +267,9 @@ module Wreq
|
|
|
268
267
|
# for HTTP/2 and automatic default headers. The actual implementation is
|
|
269
268
|
# provided by Rust.
|
|
270
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
|
+
#
|
|
271
273
|
# Construction generates the native configuration once. For Chrome 152/153,
|
|
272
274
|
# the TLS trust_anchors extension's ID order is randomized at construction;
|
|
273
275
|
# Chrome 154 and later sort those IDs by their raw bytes instead. Reusing this object
|
data/lib/wreq_ruby/http.rb
CHANGED
|
@@ -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
|
-
|
|
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.
|