wreq 1.2.4 → 1.2.6

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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +22 -19
  3. data/Cargo.toml +15 -2
  4. data/crates/wreq-util/.github/FUNDING.yml +15 -0
  5. data/crates/wreq-util/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  6. data/crates/wreq-util/.github/ISSUE_TEMPLATE/custom.md +10 -0
  7. data/crates/wreq-util/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. data/crates/wreq-util/.github/dependabot.yml +22 -0
  9. data/crates/wreq-util/.github/workflows/ci.yml +82 -0
  10. data/crates/wreq-util/.github/workflows/release-plz.yml +52 -0
  11. data/crates/wreq-util/.gitignore +24 -0
  12. data/crates/wreq-util/CHANGELOG.md +74 -0
  13. data/crates/wreq-util/Cargo.toml +94 -0
  14. data/crates/wreq-util/LICENSE +201 -0
  15. data/crates/wreq-util/README.md +62 -0
  16. data/crates/wreq-util/examples/emulate.rs +39 -0
  17. data/crates/wreq-util/examples/tower_delay.rs +191 -0
  18. data/crates/wreq-util/release-plz.toml +2 -0
  19. data/crates/wreq-util/rustfmt.toml +5 -0
  20. data/crates/wreq-util/src/emulate/compress.rs +85 -0
  21. data/crates/wreq-util/src/emulate/macros.rs +372 -0
  22. data/crates/wreq-util/src/emulate/profile/chrome/header.rs +74 -0
  23. data/crates/wreq-util/src/emulate/profile/chrome/http2.rs +65 -0
  24. data/crates/wreq-util/src/emulate/profile/chrome/tls.rs +153 -0
  25. data/crates/wreq-util/src/emulate/profile/chrome.rs +2028 -0
  26. data/crates/wreq-util/src/emulate/profile/firefox/header.rs +37 -0
  27. data/crates/wreq-util/src/emulate/profile/firefox/http2.rs +113 -0
  28. data/crates/wreq-util/src/emulate/profile/firefox/tls.rs +253 -0
  29. data/crates/wreq-util/src/emulate/profile/firefox.rs +518 -0
  30. data/crates/wreq-util/src/emulate/profile/okhttp.rs +241 -0
  31. data/crates/wreq-util/src/emulate/profile/opera/header.rs +29 -0
  32. data/crates/wreq-util/src/emulate/profile/opera/http2.rs +50 -0
  33. data/crates/wreq-util/src/emulate/profile/opera/tls.rs +97 -0
  34. data/crates/wreq-util/src/emulate/profile/opera.rs +299 -0
  35. data/crates/wreq-util/src/emulate/profile/safari/header.rs +59 -0
  36. data/crates/wreq-util/src/emulate/profile/safari/http2.rs +116 -0
  37. data/crates/wreq-util/src/emulate/profile/safari/tls.rs +177 -0
  38. data/crates/wreq-util/src/emulate/profile/safari.rs +222 -0
  39. data/crates/wreq-util/src/emulate/profile.rs +47 -0
  40. data/crates/wreq-util/src/emulate.rs +369 -0
  41. data/crates/wreq-util/src/lib.rs +14 -0
  42. data/crates/wreq-util/src/rand.rs +24 -0
  43. data/crates/wreq-util/src/tower/delay/future.rs +43 -0
  44. data/crates/wreq-util/src/tower/delay/layer.rs +201 -0
  45. data/crates/wreq-util/src/tower/delay/service.rs +190 -0
  46. data/crates/wreq-util/src/tower/delay.rs +98 -0
  47. data/crates/wreq-util/src/tower.rs +7 -0
  48. data/crates/wreq-util/tests/client.rs +153 -0
  49. data/crates/wreq-util/tests/emulate_chrome.rs +270 -0
  50. data/crates/wreq-util/tests/emulate_firefox.rs +92 -0
  51. data/crates/wreq-util/tests/emulate_okhttp.rs +46 -0
  52. data/crates/wreq-util/tests/emulate_opera.rs +113 -0
  53. data/crates/wreq-util/tests/emulate_safari.rs +151 -0
  54. data/crates/wreq-util/tests/support/mod.rs +55 -0
  55. data/crates/wreq-util/tests/support/server.rs +232 -0
  56. data/examples/emulate_request.rb +1 -1
  57. data/lib/wreq.rb +72 -45
  58. data/lib/wreq_ruby/body.rb +30 -9
  59. data/lib/wreq_ruby/client.rb +88 -55
  60. data/lib/wreq_ruby/cookie.rb +81 -21
  61. data/lib/wreq_ruby/emulate.rb +77 -7
  62. data/lib/wreq_ruby/error.rb +5 -7
  63. data/lib/wreq_ruby/header.rb +205 -114
  64. data/lib/wreq_ruby/http.rb +74 -0
  65. data/lib/wreq_ruby/response.rb +31 -3
  66. data/script/build_windows_gnu.ps1 +6 -0
  67. data/src/arch.rs +22 -0
  68. data/src/client/body/form.rs +2 -0
  69. data/src/client/body/json.rs +47 -14
  70. data/src/client/body/stream.rs +147 -43
  71. data/src/client/body.rs +11 -15
  72. data/src/client/param.rs +7 -7
  73. data/src/client/req.rs +87 -47
  74. data/src/client/resp.rs +23 -24
  75. data/src/client.rs +310 -230
  76. data/src/cookie.rs +280 -87
  77. data/src/emulate.rs +86 -50
  78. data/src/error.rs +198 -45
  79. data/src/extractor.rs +16 -76
  80. data/src/header.rs +318 -130
  81. data/src/http.rs +62 -33
  82. data/src/lib.rs +26 -20
  83. data/src/macros.rs +71 -46
  84. data/src/options.rs +284 -0
  85. data/src/rt.rs +22 -11
  86. data/src/serde/de/array_deserializer.rs +48 -0
  87. data/src/serde/de/array_enumerator.rs +59 -0
  88. data/src/serde/de/deserializer.rs +307 -0
  89. data/src/serde/de/enum_deserializer.rs +47 -0
  90. data/src/serde/de/hash_deserializer.rs +89 -0
  91. data/src/serde/de/number_deserializer.rs +51 -0
  92. data/src/serde/de/variant_deserializer.rs +101 -0
  93. data/src/serde/de.rs +33 -0
  94. data/src/serde/error.rs +146 -0
  95. data/src/serde/ser/enums.rs +14 -0
  96. data/src/serde/ser/map_serializer.rs +56 -0
  97. data/src/serde/ser/seq_serializer.rs +71 -0
  98. data/src/serde/ser/serializer.rs +194 -0
  99. data/src/serde/ser/struct_serializer.rs +106 -0
  100. data/src/serde/ser/struct_variant_serializer.rs +44 -0
  101. data/src/serde/ser/tuple_variant_serializer.rs +41 -0
  102. data/src/serde/ser.rs +18 -0
  103. data/src/serde/tests.rs +237 -0
  104. data/src/serde.rs +202 -0
  105. data/test/body_sender_test.rb +246 -0
  106. data/test/cookie_test.rb +211 -10
  107. data/test/header_test.rb +228 -192
  108. data/test/json_precision_test.rb +209 -0
  109. data/test/option_validation_test.rb +311 -0
  110. data/test/stream_test.rb +36 -0
  111. data/test/value_semantics_test.rb +238 -0
  112. metadata +77 -1
@@ -0,0 +1,372 @@
1
+ macro_rules! define_enum {
2
+ (
3
+ $(#[$meta:meta])*
4
+ dispatch,
5
+ $name:ident, $default_variant:ident,
6
+ $const_target:ident,
7
+ $(
8
+ $variant:ident => ($rename:expr, $emulation_fn:path)
9
+ ),* $(,)?
10
+ ) => {
11
+ $(#[$meta])*
12
+ #[non_exhaustive]
13
+ #[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
14
+ #[cfg_attr(feature = "emulation-serde", derive(Deserialize, Serialize))]
15
+ pub enum $name {
16
+ $(
17
+ #[cfg_attr(feature = "emulation-serde", serde(rename = $rename))]
18
+ $variant,
19
+ )*
20
+ }
21
+
22
+ impl $name {
23
+ pub const VARIANTS: &[$name] = &[
24
+ $(
25
+ $name::$variant,
26
+ )*
27
+ ];
28
+
29
+ pub fn match_emulation(self, opt: $const_target) -> wreq::Emulation {
30
+ match self {
31
+ $(
32
+ $name::$variant => $emulation_fn(opt),
33
+ )*
34
+ }
35
+ }
36
+ }
37
+
38
+ impl Default for $name {
39
+ fn default() -> Self {
40
+ $name::$default_variant
41
+ }
42
+ }
43
+
44
+ #[allow(non_upper_case_globals)]
45
+ impl $const_target {
46
+ $(
47
+ pub const $variant: $name = $name::$variant;
48
+ )*
49
+ }
50
+ };
51
+
52
+ (
53
+ $(#[$meta:meta])*
54
+ plain,
55
+ $name:ident, $default_variant:ident,
56
+ $(
57
+ $variant:ident => $rename:expr
58
+ ),* $(,)?
59
+ ) => {
60
+ $(#[$meta])*
61
+ #[non_exhaustive]
62
+ #[derive(Clone, Copy, Hash, Debug, PartialEq, Eq)]
63
+ #[cfg_attr(feature = "emulation-serde", derive(Deserialize, Serialize))]
64
+ pub enum $name {
65
+ $(
66
+ #[cfg_attr(feature = "emulation-serde", serde(rename = $rename))]
67
+ $variant,
68
+ )*
69
+ }
70
+
71
+ impl $name {
72
+ pub const VARIANTS: &[$name] = &[
73
+ $(
74
+ $name::$variant,
75
+ )*
76
+ ];
77
+ }
78
+
79
+ impl Default for $name {
80
+ fn default() -> Self {
81
+ $name::$default_variant
82
+ }
83
+ }
84
+ };
85
+ }
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.9"));
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
+ }
135
+
136
+ macro_rules! header_firefox_sec_fetch {
137
+ ($headers:expr) => {
138
+ $headers.insert("sec-fetch-dest", HeaderValue::from_static("document"));
139
+ $headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate"));
140
+ $headers.insert("sec-fetch-site", HeaderValue::from_static("none"));
141
+ $headers.insert("sec-fetch-user", HeaderValue::from_static("?1"));
142
+ };
143
+ }
144
+
145
+ macro_rules! header_firefox_accept {
146
+ ($headers:expr) => {
147
+ $headers.insert(
148
+ ACCEPT,
149
+ HeaderValue::from_static(
150
+ "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
151
+ ),
152
+ );
153
+ $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.5"));
154
+ #[cfg(feature = "emulation-compression")]
155
+ $headers.insert(
156
+ ACCEPT_ENCODING,
157
+ HeaderValue::from_static("gzip, deflate, br"),
158
+ );
159
+ };
160
+ (zstd, $headers:expr) => {
161
+ $headers.insert(
162
+ ACCEPT,
163
+ HeaderValue::from_static(
164
+ "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
165
+ ),
166
+ );
167
+ $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.5"));
168
+ #[cfg(feature = "emulation-compression")]
169
+ $headers.insert(
170
+ ACCEPT_ENCODING,
171
+ HeaderValue::from_static("gzip, deflate, br, zstd"),
172
+ );
173
+ };
174
+ }
175
+
176
+ macro_rules! header_firefox_ua {
177
+ ($headers:expr, $ua:expr) => {
178
+ $headers.insert(USER_AGENT, HeaderValue::from_static($ua));
179
+ };
180
+ }
181
+
182
+ macro_rules! join {
183
+ ($sep:expr, $first:expr $(, $rest:expr)*) => {
184
+ concat!($first $(, $sep, $rest)*)
185
+ };
186
+ }
187
+
188
+ macro_rules! standard_mod_generator {
189
+ ($mod_name:ident, $tls_options:expr, $http2_options:expr, $headers:expr) => {
190
+ pub(crate) mod $mod_name {
191
+ use super::*;
192
+
193
+ #[inline]
194
+ pub fn emulation(emulation: Emulation) -> wreq::Emulation {
195
+ build_emulation(emulation.http2, ($headers)(&emulation))
196
+ }
197
+
198
+ pub fn build_emulation(
199
+ http2: bool,
200
+ default_headers: Option<HeaderMap>,
201
+ ) -> wreq::Emulation {
202
+ build_standard_emulation(
203
+ stringify!($mod_name),
204
+ $tls_options,
205
+ http2.then(|| $http2_options),
206
+ default_headers,
207
+ )
208
+ }
209
+ }
210
+ };
211
+ ($mod_name:ident, $build_emulation:expr, $headers:expr) => {
212
+ pub(crate) mod $mod_name {
213
+ use super::*;
214
+
215
+ #[inline]
216
+ pub fn emulation(emulation: Emulation) -> wreq::Emulation {
217
+ $build_emulation(emulation.http2, ($headers)(&emulation))
218
+ }
219
+ }
220
+ };
221
+ }
222
+
223
+ macro_rules! fixed_headers {
224
+ ($emulation:expr, $header_initializer:ident, $ua:expr) => {
225
+ $emulation.headers.then(|| $header_initializer($ua))
226
+ };
227
+ }
228
+
229
+ macro_rules! platform_headers {
230
+ (
231
+ $emulation:expr,
232
+ $header_initializer:ident,
233
+ [($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*]
234
+ ) => {{
235
+ #[allow(unreachable_patterns)]
236
+ $emulation.headers.then(|| {
237
+ match $emulation.platform {
238
+ $(
239
+ Platform::$other_os => $header_initializer(
240
+ $other_sec_ch_ua,
241
+ $other_ua,
242
+ $emulation.platform,
243
+ ),
244
+ )*
245
+ _ => $header_initializer(
246
+ $default_sec_ch_ua,
247
+ $default_ua,
248
+ Platform::$default_os,
249
+ ),
250
+ }
251
+ })
252
+ }};
253
+ }
254
+
255
+ macro_rules! firefox_platform_headers {
256
+ ($emulation:expr, $header_initializer:ident, [($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*]) => {{
257
+ #[allow(unreachable_patterns)]
258
+ $emulation.headers.then(|| {
259
+ match $emulation.platform {
260
+ $(
261
+ Platform::$other_os => $header_initializer($other_ua),
262
+ )*
263
+ _ => $header_initializer($default_ua),
264
+ }
265
+ })
266
+ }};
267
+ }
268
+
269
+ macro_rules! mod_generator {
270
+ (
271
+ $mod_name:ident,
272
+ $tls_options:expr,
273
+ $http2_options:expr,
274
+ $header_initializer:ident,
275
+ [($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*]
276
+ ) => {
277
+ standard_mod_generator!(
278
+ $mod_name,
279
+ $tls_options,
280
+ $http2_options,
281
+ |emulation: &Emulation| {
282
+ platform_headers!(
283
+ emulation,
284
+ $header_initializer,
285
+ [($default_os, $default_sec_ch_ua, $default_ua) $(, ($other_os, $other_sec_ch_ua, $other_ua))*]
286
+ )
287
+ }
288
+ );
289
+ };
290
+ (
291
+ $mod_name:ident,
292
+ $tls_options:expr,
293
+ $http2_options:expr,
294
+ $header_initializer:ident,
295
+ [($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*]
296
+ ) => {
297
+ standard_mod_generator!(
298
+ $mod_name,
299
+ $tls_options,
300
+ $http2_options,
301
+ |emulation: &Emulation| {
302
+ firefox_platform_headers!(
303
+ emulation,
304
+ $header_initializer,
305
+ [($default_os, $default_ua) $(, ($other_os, $other_ua))*]
306
+ )
307
+ }
308
+ );
309
+ };
310
+ (
311
+ $mod_name:ident,
312
+ $tls_options:expr,
313
+ $http2_options:expr,
314
+ $header_initializer:ident,
315
+ $ua:expr
316
+ ) => {
317
+ standard_mod_generator!(
318
+ $mod_name,
319
+ $tls_options,
320
+ $http2_options,
321
+ |emulation: &Emulation| fixed_headers!(emulation, $header_initializer, $ua)
322
+ );
323
+ };
324
+ (
325
+ $mod_name:ident,
326
+ $build_emulation:expr,
327
+ $header_initializer:ident,
328
+ [($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*]
329
+ ) => {
330
+ standard_mod_generator!(
331
+ $mod_name,
332
+ $build_emulation,
333
+ |emulation: &Emulation| {
334
+ platform_headers!(
335
+ emulation,
336
+ $header_initializer,
337
+ [($default_os, $default_sec_ch_ua, $default_ua) $(, ($other_os, $other_sec_ch_ua, $other_ua))*]
338
+ )
339
+ }
340
+ );
341
+ };
342
+ (
343
+ $mod_name:ident,
344
+ $build_emulation:expr,
345
+ $header_initializer:ident,
346
+ [($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*]
347
+ ) => {
348
+ standard_mod_generator!(
349
+ $mod_name,
350
+ $build_emulation,
351
+ |emulation: &Emulation| {
352
+ firefox_platform_headers!(
353
+ emulation,
354
+ $header_initializer,
355
+ [($default_os, $default_ua) $(, ($other_os, $other_ua))*]
356
+ )
357
+ }
358
+ );
359
+ };
360
+ (
361
+ $mod_name:ident,
362
+ $build_emulation:expr,
363
+ $header_initializer:ident,
364
+ $ua:expr
365
+ ) => {
366
+ standard_mod_generator!(
367
+ $mod_name,
368
+ $build_emulation,
369
+ |emulation: &Emulation| fixed_headers!(emulation, $header_initializer, $ua)
370
+ );
371
+ };
372
+ }
@@ -0,0 +1,74 @@
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
+ }
@@ -0,0 +1,65 @@
1
+ macro_rules! headers_stream_dependency {
2
+ () => {
3
+ StreamDependency::new(StreamId::zero(), 219, true)
4
+ };
5
+ }
6
+
7
+ macro_rules! pseudo_order {
8
+ () => {
9
+ PseudoOrder::builder()
10
+ .extend([
11
+ PseudoId::Method,
12
+ PseudoId::Authority,
13
+ PseudoId::Scheme,
14
+ PseudoId::Path,
15
+ ])
16
+ .build()
17
+ };
18
+ }
19
+
20
+ macro_rules! settings_order {
21
+ () => {
22
+ SettingsOrder::builder()
23
+ .extend([
24
+ SettingId::HeaderTableSize,
25
+ SettingId::EnablePush,
26
+ SettingId::MaxConcurrentStreams,
27
+ SettingId::InitialWindowSize,
28
+ SettingId::MaxFrameSize,
29
+ SettingId::MaxHeaderListSize,
30
+ SettingId::EnableConnectProtocol,
31
+ SettingId::NoRfc7540Priorities,
32
+ ])
33
+ .build()
34
+ };
35
+ }
36
+
37
+ macro_rules! http2_options {
38
+ (@base $builder:expr) => {
39
+ $builder
40
+ .initial_window_size(6291456)
41
+ .initial_connection_window_size(15728640)
42
+ .max_header_list_size(262144)
43
+ .header_table_size(65536)
44
+ .headers_stream_dependency(headers_stream_dependency!())
45
+ .headers_pseudo_order(pseudo_order!())
46
+ .settings_order(settings_order!())
47
+ };
48
+
49
+ (1) => {
50
+ http2_options!(@base Http2Options::builder())
51
+ .max_concurrent_streams(1000)
52
+ .build()
53
+ };
54
+ (2) => {
55
+ http2_options!(@base Http2Options::builder())
56
+ .max_concurrent_streams(1000)
57
+ .enable_push(false)
58
+ .build()
59
+ };
60
+ (3) => {
61
+ http2_options!(@base Http2Options::builder())
62
+ .enable_push(false)
63
+ .build()
64
+ };
65
+ }
@@ -0,0 +1,153 @@
1
+ use super::*;
2
+
3
+ macro_rules! tls_options {
4
+ (@build $builder:expr) => {
5
+ $builder.build().into()
6
+ };
7
+
8
+ (1) => {
9
+ tls_options!(@build ChromeTlsConfig::builder())
10
+ };
11
+ (2) => {
12
+ tls_options!(@build ChromeTlsConfig::builder().enable_ech_grease(true))
13
+ };
14
+ (3) => {
15
+ tls_options!(@build ChromeTlsConfig::builder().permute_extensions(true))
16
+ };
17
+ (4) => {
18
+ tls_options!(@build ChromeTlsConfig::builder()
19
+ .permute_extensions(true)
20
+ .enable_ech_grease(true))
21
+ };
22
+ (5) => {
23
+ tls_options!(@build ChromeTlsConfig::builder()
24
+ .permute_extensions(true)
25
+ .enable_ech_grease(true)
26
+ .pre_shared_key(true))
27
+ };
28
+ (6, $curves:expr) => {
29
+ tls_options!(@build ChromeTlsConfig::builder()
30
+ .permute_extensions(true)
31
+ .enable_ech_grease(true)
32
+ .pre_shared_key(true)
33
+ .curves($curves))
34
+ };
35
+ (7, $curves:expr) => {
36
+ tls_options!(@build ChromeTlsConfig::builder()
37
+ .permute_extensions(true)
38
+ .enable_ech_grease(true)
39
+ .pre_shared_key(true)
40
+ .curves($curves)
41
+ .alps_use_new_codepoint(true))
42
+ };
43
+ (8, $curves:expr, $sigalgs:expr) => {
44
+ tls_options!(@build ChromeTlsConfig::builder()
45
+ .permute_extensions(true)
46
+ .enable_ech_grease(true)
47
+ .pre_shared_key(true)
48
+ .curves($curves)
49
+ .sigalgs_list($sigalgs)
50
+ .alps_use_new_codepoint(true))
51
+ };
52
+ }
53
+
54
+ pub const CURVES_1: &str = join!(":", "X25519", "P-256", "P-384");
55
+ pub const CURVES_2: &str = join!(":", "X25519Kyber768Draft00", "X25519", "P-256", "P-384");
56
+ pub const CURVES_3: &str = join!(":", "X25519MLKEM768", "X25519", "P-256", "P-384");
57
+
58
+ pub const CIPHER_LIST: &str = join!(
59
+ ":",
60
+ "TLS_AES_128_GCM_SHA256",
61
+ "TLS_AES_256_GCM_SHA384",
62
+ "TLS_CHACHA20_POLY1305_SHA256",
63
+ "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
64
+ "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
65
+ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
66
+ "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
67
+ "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
68
+ "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
69
+ "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
70
+ "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
71
+ "TLS_RSA_WITH_AES_128_GCM_SHA256",
72
+ "TLS_RSA_WITH_AES_256_GCM_SHA384",
73
+ "TLS_RSA_WITH_AES_128_CBC_SHA",
74
+ "TLS_RSA_WITH_AES_256_CBC_SHA"
75
+ );
76
+
77
+ pub const SIGALGS_LIST: &str = join!(
78
+ ":",
79
+ "ecdsa_secp256r1_sha256",
80
+ "rsa_pss_rsae_sha256",
81
+ "rsa_pkcs1_sha256",
82
+ "ecdsa_secp384r1_sha384",
83
+ "rsa_pss_rsae_sha384",
84
+ "rsa_pkcs1_sha384",
85
+ "rsa_pss_rsae_sha512",
86
+ "rsa_pkcs1_sha512"
87
+ );
88
+
89
+ pub const NEW_SIGALGS_LIST: &str = join!(
90
+ ":",
91
+ "mldsa44",
92
+ "mldsa65",
93
+ "mldsa87",
94
+ "ecdsa_secp256r1_sha256",
95
+ "rsa_pss_rsae_sha256",
96
+ "rsa_pkcs1_sha256",
97
+ "ecdsa_secp384r1_sha384",
98
+ "rsa_pss_rsae_sha384",
99
+ "rsa_pkcs1_sha384",
100
+ "rsa_pss_rsae_sha512",
101
+ "rsa_pkcs1_sha512"
102
+ );
103
+
104
+ pub const CERTIFICATE_COMPRESSORS: &[&'static dyn CertificateCompressor] = &[&BrotliCompressor];
105
+
106
+ #[derive(TypedBuilder)]
107
+ pub struct ChromeTlsConfig {
108
+ #[builder(default = CURVES_1)]
109
+ curves: &'static str,
110
+
111
+ #[builder(default = SIGALGS_LIST)]
112
+ sigalgs_list: &'static str,
113
+
114
+ #[builder(default = CIPHER_LIST)]
115
+ cipher_list: &'static str,
116
+
117
+ #[builder(default = AlpsProtocol::HTTP2, setter(into))]
118
+ alps_protos: AlpsProtocol,
119
+
120
+ #[builder(default = false)]
121
+ alps_use_new_codepoint: bool,
122
+
123
+ #[builder(default = false, setter(into))]
124
+ enable_ech_grease: bool,
125
+
126
+ #[builder(default = false, setter(into))]
127
+ permute_extensions: bool,
128
+
129
+ #[builder(default = false, setter(into))]
130
+ pre_shared_key: bool,
131
+ }
132
+
133
+ impl From<ChromeTlsConfig> for TlsOptions {
134
+ fn from(val: ChromeTlsConfig) -> Self {
135
+ TlsOptions::builder()
136
+ .grease_enabled(true)
137
+ .enable_ocsp_stapling(true)
138
+ .enable_signed_cert_timestamps(true)
139
+ .curves_list(val.curves)
140
+ .sigalgs_list(val.sigalgs_list)
141
+ .cipher_list(val.cipher_list)
142
+ .min_tls_version(TlsVersion::TLS_1_2)
143
+ .max_tls_version(TlsVersion::TLS_1_3)
144
+ .permute_extensions(val.permute_extensions)
145
+ .pre_shared_key(val.pre_shared_key)
146
+ .enable_ech_grease(val.enable_ech_grease)
147
+ .alps_protocols([val.alps_protos])
148
+ .alps_use_new_codepoint(val.alps_use_new_codepoint)
149
+ .aes_hw_override(true)
150
+ .certificate_compressors(CERTIFICATE_COMPRESSORS)
151
+ .build()
152
+ }
153
+ }