asknothingx2_util/api/preset/extra_config.rs
1use reqwest::{redirect::Policy, tls};
2
3/// **Default Security Profile (strict_1_2):**
4/// - Cookies: Not saved, Referer: Not sent
5/// - TLS: 1.2+ minimum required
6/// - Redirects: Up to 3 allowed
7#[derive(Debug)]
8pub struct SecurityProfile {
9 pub save_cookies: bool,
10 pub send_referer: bool,
11 pub min_tls_version: Option<tls::Version>,
12 pub redirect: Policy,
13}
14
15impl SecurityProfile {
16 /// - Cookies: Not saved, Referer: Not sent
17 /// - TLS: 1.3+ minimum
18 /// - Redirects: Up to 3 allowed
19 pub fn strict_1_3() -> Self {
20 Self {
21 save_cookies: false,
22 send_referer: false,
23 min_tls_version: Some(tls::Version::TLS_1_3),
24 redirect: Policy::limited(3),
25 }
26 }
27
28 /// - Cookies: Not saved, Referer: Not sent
29 /// - TLS: 1.2+ minimum
30 /// - Redirects: Up to 3 allowed
31 pub fn strict_1_2() -> Self {
32 Self {
33 save_cookies: false,
34 send_referer: false,
35 min_tls_version: Some(tls::Version::TLS_1_2),
36 redirect: Policy::limited(3),
37 }
38 }
39
40 /// - Cookies: Saved, Referer: Sent
41 /// - TLS: 1.2+ minimum
42 /// - Redirects: Up to 10 allowed
43 pub fn permissive() -> Self {
44 Self {
45 save_cookies: true,
46 send_referer: true,
47 min_tls_version: Some(tls::Version::TLS_1_2),
48 redirect: Policy::limited(10),
49 }
50 }
51
52 /// - Cookies: Not saved, Referer: Not sent
53 /// - TLS: No minimum version
54 /// - Redirects: Up to 3 allowed
55 pub fn test() -> Self {
56 Self {
57 save_cookies: false,
58 send_referer: false,
59 min_tls_version: None,
60 redirect: Policy::limited(3),
61 }
62 }
63
64 /// - Cookies: Saved, Referer: Sent
65 /// - TLS: No minimum version
66 /// - Redirects: Up to 15 allowed
67 pub fn debug() -> Self {
68 Self {
69 save_cookies: true,
70 send_referer: true,
71 min_tls_version: None,
72 redirect: Policy::limited(15),
73 }
74 }
75
76 pub fn redirect(mut self, policy: Policy) -> Self {
77 self.redirect = policy;
78 self
79 }
80}
81
82impl Default for SecurityProfile {
83 fn default() -> Self {
84 Self::strict_1_2()
85 }
86}
87
88/// HTTP/2 protocol tuning parameters for performance optimization.
89///
90/// Controls flow control windows, frame sizes, and adaptive algorithms to optimize
91/// HTTP/2 performance for different use cases from low-latency real-time applications
92/// to high-throughput batch processing.
93///
94/// **Default Configuration:**
95/// - Stream window: 64KB (good for most use cases)
96/// - Connection window: 1MB (allows multiple concurrent streams)
97/// - Frame size: 16KB (HTTP/2 default)
98/// - Adaptive window: Enabled (automatically tunes flow control)
99///
100/// # Performance Profiles
101///
102/// - **Low latency**: Small windows, disabled adaptive algorithms
103/// - **High throughput**: Large windows, enabled adaptive algorithms
104/// - **Real-time**: Minimal buffering, predictable flow control
105/// - **Batch processing**: Maximum windows for bulk transfers
106///
107#[derive(Debug)]
108pub struct Http2Settings {
109 pub initial_stream_window_size: u32,
110 pub initial_connection_window_size: u32,
111 pub max_frame_size: u32,
112 pub adaptive_window: bool,
113}
114
115impl Default for Http2Settings {
116 fn default() -> Self {
117 Self {
118 initial_stream_window_size: 65_536,
119 initial_connection_window_size: 1_048_576,
120 max_frame_size: 16_384,
121 adaptive_window: true,
122 }
123 }
124}
125
126impl Http2Settings {
127 /// Create custom HTTP/2 tuning parameters.
128 ///
129 /// # Parameters
130 ///
131 /// - `initial_stream_window_size`: Per-stream buffer size (bytes)
132 /// - `initial_connection_window_size`: Total connection buffer size (bytes)
133 /// - `max_frame_size`: Maximum frame size (bytes, 16KB to 16MB)
134 /// - `adaptive_window`: Enable automatic window size adjustment
135 ///
136 pub fn new(
137 initial_stream_window_size: u32,
138 initial_connection_window_size: u32,
139 max_frame_size: u32,
140 adaptive_window: bool,
141 ) -> Self {
142 Self {
143 initial_stream_window_size,
144 initial_connection_window_size,
145 max_frame_size,
146 adaptive_window,
147 }
148 }
149}