wreq 1.2.4 → 1.2.5

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +3 -7
  3. data/Cargo.toml +6 -1
  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 +370 -0
  22. data/crates/wreq-util/src/emulate/profile/chrome/header.rs +59 -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 +21 -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 +30 -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 +51 -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 +20 -18
  58. data/lib/wreq_ruby/body.rb +3 -0
  59. data/lib/wreq_ruby/client.rb +18 -18
  60. data/lib/wreq_ruby/cookie.rb +2 -2
  61. data/lib/wreq_ruby/emulate.rb +3 -1
  62. data/lib/wreq_ruby/header.rb +205 -114
  63. data/lib/wreq_ruby/response.rb +28 -3
  64. data/src/emulate.rs +1 -0
  65. data/src/error.rs +2 -6
  66. data/src/header/helper.rs +112 -0
  67. data/src/header.rs +198 -133
  68. data/test/header_test.rb +228 -192
  69. data/test/stream_test.rb +36 -0
  70. metadata +54 -1
@@ -0,0 +1,370 @@
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-dest", HeaderValue::from_static("document"));
99
+ $headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate"));
100
+ $headers.insert("sec-fetch-site", HeaderValue::from_static("none"));
101
+ };
102
+ }
103
+
104
+ macro_rules! header_chrome_ua {
105
+ ($headers:expr, $ua:expr) => {
106
+ $headers.insert(USER_AGENT, HeaderValue::from_static($ua));
107
+ };
108
+ }
109
+
110
+ macro_rules! header_chrome_accept {
111
+ ($headers:expr) => {
112
+ $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"));
113
+ #[cfg(feature = "emulation-compression")]
114
+ $headers.insert(
115
+ ACCEPT_ENCODING,
116
+ HeaderValue::from_static("gzip, deflate, br"),
117
+ );
118
+ $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9"));
119
+ };
120
+ (zstd, $headers:expr) => {
121
+ $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"));
122
+ #[cfg(feature = "emulation-compression")]
123
+ $headers.insert(
124
+ ACCEPT_ENCODING,
125
+ HeaderValue::from_static("gzip, deflate, br, zstd"),
126
+ );
127
+ $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9"));
128
+ }
129
+ }
130
+
131
+ macro_rules! header_firefox_sec_fetch {
132
+ ($headers:expr) => {
133
+ $headers.insert("sec-fetch-dest", HeaderValue::from_static("document"));
134
+ $headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate"));
135
+ $headers.insert("sec-fetch-site", HeaderValue::from_static("none"));
136
+ };
137
+ }
138
+
139
+ macro_rules! header_firefox_accept {
140
+ ($headers:expr) => {
141
+ $headers.insert(
142
+ ACCEPT,
143
+ HeaderValue::from_static(
144
+ "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
145
+ ),
146
+ );
147
+ #[cfg(feature = "emulation-compression")]
148
+ $headers.insert(
149
+ ACCEPT_ENCODING,
150
+ HeaderValue::from_static("gzip, deflate, br"),
151
+ );
152
+ $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.5"));
153
+ };
154
+ (zstd, $headers:expr) => {
155
+ $headers.insert(
156
+ ACCEPT,
157
+ HeaderValue::from_static(
158
+ "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
159
+ ),
160
+ );
161
+ #[cfg(feature = "emulation-compression")]
162
+ $headers.insert(
163
+ ACCEPT_ENCODING,
164
+ HeaderValue::from_static("gzip, deflate, br, zstd"),
165
+ );
166
+ $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.5"));
167
+ };
168
+ }
169
+
170
+ macro_rules! header_firefox_ua {
171
+ ($headers:expr, $ua:expr) => {
172
+ $headers.insert(
173
+ HeaderName::from_static("te"),
174
+ HeaderValue::from_static("trailers"),
175
+ );
176
+ $headers.insert(USER_AGENT, HeaderValue::from_static($ua));
177
+ };
178
+ }
179
+
180
+ macro_rules! join {
181
+ ($sep:expr, $first:expr $(, $rest:expr)*) => {
182
+ concat!($first $(, $sep, $rest)*)
183
+ };
184
+ }
185
+
186
+ macro_rules! standard_mod_generator {
187
+ ($mod_name:ident, $tls_options:expr, $http2_options:expr, $headers:expr) => {
188
+ pub(crate) mod $mod_name {
189
+ use super::*;
190
+
191
+ #[inline]
192
+ pub fn emulation(emulation: Emulation) -> wreq::Emulation {
193
+ build_emulation(emulation.http2, ($headers)(&emulation))
194
+ }
195
+
196
+ pub fn build_emulation(
197
+ http2: bool,
198
+ default_headers: Option<HeaderMap>,
199
+ ) -> wreq::Emulation {
200
+ build_standard_emulation(
201
+ stringify!($mod_name),
202
+ $tls_options,
203
+ http2.then(|| $http2_options),
204
+ default_headers,
205
+ )
206
+ }
207
+ }
208
+ };
209
+ ($mod_name:ident, $build_emulation:expr, $headers:expr) => {
210
+ pub(crate) mod $mod_name {
211
+ use super::*;
212
+
213
+ #[inline]
214
+ pub fn emulation(emulation: Emulation) -> wreq::Emulation {
215
+ $build_emulation(emulation.http2, ($headers)(&emulation))
216
+ }
217
+ }
218
+ };
219
+ }
220
+
221
+ macro_rules! fixed_headers {
222
+ ($emulation:expr, $header_initializer:ident, $ua:expr) => {
223
+ $emulation.headers.then(|| $header_initializer($ua))
224
+ };
225
+ }
226
+
227
+ macro_rules! platform_headers {
228
+ (
229
+ $emulation:expr,
230
+ $header_initializer:ident,
231
+ [($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*]
232
+ ) => {{
233
+ #[allow(unreachable_patterns)]
234
+ $emulation.headers.then(|| {
235
+ match $emulation.platform {
236
+ $(
237
+ Platform::$other_os => $header_initializer(
238
+ $other_sec_ch_ua,
239
+ $other_ua,
240
+ $emulation.platform,
241
+ ),
242
+ )*
243
+ _ => $header_initializer(
244
+ $default_sec_ch_ua,
245
+ $default_ua,
246
+ Platform::$default_os,
247
+ ),
248
+ }
249
+ })
250
+ }};
251
+ }
252
+
253
+ macro_rules! firefox_platform_headers {
254
+ ($emulation:expr, $header_initializer:ident, [($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*]) => {{
255
+ #[allow(unreachable_patterns)]
256
+ $emulation.headers.then(|| {
257
+ match $emulation.platform {
258
+ $(
259
+ Platform::$other_os => $header_initializer($other_ua),
260
+ )*
261
+ _ => $header_initializer($default_ua),
262
+ }
263
+ })
264
+ }};
265
+ }
266
+
267
+ macro_rules! mod_generator {
268
+ (
269
+ $mod_name:ident,
270
+ $tls_options:expr,
271
+ $http2_options:expr,
272
+ $header_initializer:ident,
273
+ [($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*]
274
+ ) => {
275
+ standard_mod_generator!(
276
+ $mod_name,
277
+ $tls_options,
278
+ $http2_options,
279
+ |emulation: &Emulation| {
280
+ platform_headers!(
281
+ emulation,
282
+ $header_initializer,
283
+ [($default_os, $default_sec_ch_ua, $default_ua) $(, ($other_os, $other_sec_ch_ua, $other_ua))*]
284
+ )
285
+ }
286
+ );
287
+ };
288
+ (
289
+ $mod_name:ident,
290
+ $tls_options:expr,
291
+ $http2_options:expr,
292
+ $header_initializer:ident,
293
+ [($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*]
294
+ ) => {
295
+ standard_mod_generator!(
296
+ $mod_name,
297
+ $tls_options,
298
+ $http2_options,
299
+ |emulation: &Emulation| {
300
+ firefox_platform_headers!(
301
+ emulation,
302
+ $header_initializer,
303
+ [($default_os, $default_ua) $(, ($other_os, $other_ua))*]
304
+ )
305
+ }
306
+ );
307
+ };
308
+ (
309
+ $mod_name:ident,
310
+ $tls_options:expr,
311
+ $http2_options:expr,
312
+ $header_initializer:ident,
313
+ $ua:expr
314
+ ) => {
315
+ standard_mod_generator!(
316
+ $mod_name,
317
+ $tls_options,
318
+ $http2_options,
319
+ |emulation: &Emulation| fixed_headers!(emulation, $header_initializer, $ua)
320
+ );
321
+ };
322
+ (
323
+ $mod_name:ident,
324
+ $build_emulation:expr,
325
+ $header_initializer:ident,
326
+ [($default_os:ident, $default_sec_ch_ua:tt, $default_ua:tt) $(, ($other_os:ident, $other_sec_ch_ua:tt, $other_ua:tt))*]
327
+ ) => {
328
+ standard_mod_generator!(
329
+ $mod_name,
330
+ $build_emulation,
331
+ |emulation: &Emulation| {
332
+ platform_headers!(
333
+ emulation,
334
+ $header_initializer,
335
+ [($default_os, $default_sec_ch_ua, $default_ua) $(, ($other_os, $other_sec_ch_ua, $other_ua))*]
336
+ )
337
+ }
338
+ );
339
+ };
340
+ (
341
+ $mod_name:ident,
342
+ $build_emulation:expr,
343
+ $header_initializer:ident,
344
+ [($default_os:ident, $default_ua:tt) $(, ($other_os:ident, $other_ua:tt))*]
345
+ ) => {
346
+ standard_mod_generator!(
347
+ $mod_name,
348
+ $build_emulation,
349
+ |emulation: &Emulation| {
350
+ firefox_platform_headers!(
351
+ emulation,
352
+ $header_initializer,
353
+ [($default_os, $default_ua) $(, ($other_os, $other_ua))*]
354
+ )
355
+ }
356
+ );
357
+ };
358
+ (
359
+ $mod_name:ident,
360
+ $build_emulation:expr,
361
+ $header_initializer:ident,
362
+ $ua:expr
363
+ ) => {
364
+ standard_mod_generator!(
365
+ $mod_name,
366
+ $build_emulation,
367
+ |emulation: &Emulation| fixed_headers!(emulation, $header_initializer, $ua)
368
+ );
369
+ };
370
+ }
@@ -0,0 +1,59 @@
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
+ header_chrome_ua!(headers, ua);
16
+ header_chrome_sec_fetch!(headers);
17
+ header_chrome_accept!(headers);
18
+ headers
19
+ }
20
+
21
+ pub fn header_initializer_with_zstd(
22
+ sec_ch_ua: &'static str,
23
+ ua: &'static str,
24
+ emulation_os: Platform,
25
+ ) -> HeaderMap {
26
+ let mut headers = HeaderMap::new();
27
+ header_chrome_sec_ch_ua!(
28
+ headers,
29
+ sec_ch_ua,
30
+ emulation_os.platform(),
31
+ emulation_os.is_mobile()
32
+ );
33
+ header_chrome_ua!(headers, ua);
34
+ header_chrome_sec_fetch!(headers);
35
+ header_chrome_accept!(zstd, headers);
36
+ headers
37
+ }
38
+
39
+ pub fn header_initializer_with_zstd_priority(
40
+ sec_ch_ua: &'static str,
41
+ ua: &'static str,
42
+ emulation_os: Platform,
43
+ ) -> HeaderMap {
44
+ let mut headers = HeaderMap::new();
45
+ header_chrome_sec_ch_ua!(
46
+ headers,
47
+ sec_ch_ua,
48
+ emulation_os.platform(),
49
+ emulation_os.is_mobile()
50
+ );
51
+ header_chrome_ua!(headers, ua);
52
+ header_chrome_sec_fetch!(headers);
53
+ header_chrome_accept!(zstd, headers);
54
+ headers.insert(
55
+ HeaderName::from_static("priority"),
56
+ HeaderValue::from_static("u=0, i"),
57
+ );
58
+ headers
59
+ }
@@ -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
+ }