1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
//!# reqrio - High-Performance HTTP Request Engine
//!
//! A modern Rust HTTP request library optimized for low latency, high concurrency, and minimal memory overhead.
//! Designed to mimic browser behavior for advanced web automation, API integration, and reverse proxy development.
//!
//! ## Why reqrio?
//!
//! - **Undetectable Client Simulation**: Authentic TLS fingerprinting and browser-identical request headers for bypassing bot detection
//! - **Enterprise-Grade Performance**: Handle thousands of concurrent requests with minimal overhead using async/sync dual-mode
//! - **Production-Ready TLS**: BoringSSL-based implementation with certificate management, mTLS support, and session resumption
//! - **Efficient Memory Usage**: Intelligent use of Rust's lifetime system and `Cow` to eliminate unnecessary copies
//!
//! ## Core Features
//!
//! - **Efficient Reference-Based Architecture**: Leverages Rust's ownership model with `Cow` and lifetime borrowing to minimize allocations
//! - **Dual Concurrency Models**: Sync (`ScReq`) and Async (`AcReq`) engines for flexible deployment
//! - **Browser-Compatible TLS**: Implemented with BoringSSL for feature parity with Chrome, Firefox, and Edge
//! - **Advanced TLS Fingerprinting** (subscription): Customize via hexadecimal, Ja3, or Ja4 standards for maximum authenticity
//! - **Strict Header Ordering**: Enforces HTTP/2.0 and HTTP/1.1 header sequences consistent with real browser requests
//! - **Complete Protocol Support**: HTTP/1.1, HTTP/2.0, and full-duplex WebSocket with connection pooling
//!
//! ## Architecture: Efficient Data Pipeline
//!
//! `reqrio` uses a layered architecture that optimizes memory usage through intelligent borrowing and streaming:
//!
//! ```text
//! Form ┌─────────┐ ┌───────────────┐ ┌─────────────┐ ┌──────┐
//! User ───────►│ Req │ Body │ RequestBuf │ Buffer │ │ Encrypted │ │
//! Json │ Engine ├─ Cow<T> ──┤ Header + Body │──────────►│ TlsStream │──────────►│ TCP │
//! Files │ (Sync) │ Lifetime │ Readers │ │ Encrypt │ │ Send │
//! User ───────►│ (Async) │ │ (borrowed) │ │ │ │ │
//! └─────────┘ └───────────────┘ └─────────────┘ └──────┘
//! ```
//!
//! **Key Design Principles:**
//! - **Lifetime-Based Borrowing**: Data is borrowed via lifetime parameters during header and body processing, avoiding unnecessary copies
//! - **Copy-on-Write (Cow)**: Form data and JSON payloads use `Cow<T>` to support both borrowed and owned data without overhead
//! - **Streaming Body Readers**: Support for HTTP/1.1 and HTTP/2.0 with separate body readers for efficient chunking
//! - **Single Data Copy at Encryption**: Data flows into TLS encryption layer where it is copied once for cryptographic operations
//! - **Zero-Copy for Files**: Large file uploads are read on-demand through `BodyReader` interface, avoiding full buffering
//!
//!
//! ## Quick Start Guide
//!
//! ### Simple GET Request
//! The simplest way to send a GET request:
//!
//! ```rust
//! # use reqrio::*;
//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let mut res = reqrio::get("https://api.example.com/users", None)?;
//! println!("{}", res.as_text()?);
//! # Ok(())
//! # }
//! ```
//!
//! ### GET Request with Query Parameters
//! Add query parameters using the `.params()` method:
//! ```rust
//! # use reqrio::*;
//! # fn ff() {
//! let params = json::object! {
//! "p1": 1,
//! "p2": "??34//11<<><"
//! };
//!
//! // Send GET request with query parameters
//! let mut res = reqrio::get("https://www.baidu.com".params(params), None).unwrap();
//!
//! // Access response headers
//! let header = res.header();
//!
//! // Parse as JSON
//! let json = res.json().unwrap();
//! # }
//! ```
//!
//! ### POST with Form Data
//! ```rust
//! # use reqrio::*;
//! # fn ff() {
//! let url = "https://www.baidu.com/api";
//! let data = json::object! {
//! "field1": "value1",
//! "field2": "value2"
//! };
//!
//! let resp = reqrio::post(url, data.form()).unwrap();
//! # }
//! ```
//!
//! ### POST with JSON Data
//! ```rust
//! # use reqrio::*;
//! # fn ff() {
//! let url = "https://www.baidu.com/api";
//! let data = json::object! {
//! "field1": "value1",
//! "field2": "value2"
//! };
//!
//! let resp = reqrio::post(url, data).unwrap();
//! # }
//! ```
//!
//! ### POST with Serializable Struct
//! ```rust
//! # use reqrio::*;
//! # use serde::Serialize;
//! # fn ff() {
//! #[derive(Serialize)]
//! struct Data {
//! field1: String,
//! field2: bool,
//! }
//!
//! let url = "https://www.baidu.com/api";
//! let resp = reqrio::post(
//! url,
//! Body::json(&Data {
//! field1: "value".to_string(),
//! field2: false,
//! }).unwrap()
//! ).unwrap();
//! # }
//! ```
//!
//! ### Advanced: Custom Session with Fingerprinting
//! For authentic browser emulation, configure a session with custom headers and TLS settings:
//!
//! ```rust
//! # use reqrio::*;
//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let headers = json::object! {
//! "Accept": "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.7",
//! "Accept-Encoding": "gzip, deflate, br, zstd",
//! "Accept-Language": "en-US,en;q=0.9",
//! "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36"
//! };
//!
//! let mut session = ScReq::new()
//! .with_alpn(ALPN::Http20) // Use HTTP/2.0 for modern sites
//! .with_header_json(headers)? // Set browser-compatible headers
//! .with_timeout(Timeout::new_same(5000, 3)); // 5s timeout with 3 retries
//!
//! // Configure TLS fingerprint (if subscription available)
//! // session.set_fingerprint(Fingerprint::chrome_120());
//!
//! // Make requests with persistent session state
//! let resp = session.post("https://api.example.com/data", json::object! {"key": "value"})?;
//! # Ok(())
//! # }
//! ```
//!
//! ### WebSocket Connection (Sync)
//! Real-time communication with WebSocket protocol:
//! ```rust
//! # use reqrio::*;
//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let url = Url::try_from("wss://stream.example.com/events")?;
//!
//! let mut ws = WebSocket::sync_build()
//! .with_origin("https://example.com")?
//! .with_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")?
//! .build(&url)?;
//!
//! // Read frames in a loop
//! loop {
//! let frame = ws.read_frame()?;
//! match frame.frame_type().op_code() {
//! WsOpcode::TEXT => {
//! let text = String::from_utf8(frame.payload().as_bytes().to_vec())?;
//! println!("Received: {}", text);
//! }
//! WsOpcode::BINARY => println!("Binary data received"),
//! WsOpcode::PING => {
//! let pong = WsFrame::new_pong(true, frame.payload().as_bytes());
//! ws.write_frame(pong)?;
//! }
//! WsOpcode::CLOSE => break,
//! _ => {}
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Performance Characteristics
//!
//! - **Request Latency**: ~1-5ms per request (varies by network/server)
//! - **Concurrent Throughput**: 10K+ requests/sec on standard hardware
//! - **Memory Efficiency**: ~50-100KB per idle connection
//! - **Zero Allocation**: Header processing uses stack when possible
//!
//! ## Use Cases
//!
//! - **Web Scraping**: Authentic browser behavior bypass advanced detection
//! - **API Testing**: Precise control over HTTP semantics and TLS configuration
//! - **Real-Time Systems**: WebSocket support for live data streaming
//! - **Reverse Proxies**: Direct TLS record layer access for protocol development
//! - **Performance Tools**: Connection pooling and efficient concurrent requests
//!
//! ## Thread Safety & Concurrency
//!
//! - `ScReq` (Sync): Single-threaded, `Send + Sync` for thread pools
//! - `AcReq` (Async): Tokio-based, designed for `async/await` workloads
//! - Connection pooling and session reuse recommended for production
//!
//! ## Feature Flags
//!
//! - `aync`: Enable async runtime with Tokio support (required for `AcReq`)
//! - `export`: Enable C FFI bindings for cross-language integration
//! - `serde`: Enable serde serialization/deserialization support
//! - `log`: Enable internal debug logging (requires Rust nightly)
//!
//! ## Security Considerations
//!
//! - **Certificate Verification**: Enabled by default; disable only for testing with `verify(false)`
//! - **TLS Session Caching**: Automatic session resumption for performance; explicitly managed
//! - **Memory Safety**: Rust type system prevents buffer overflows and use-after-free bugs
//! - **Constant-Time Operations**: Critical cryptographic operations use constant-time implementations
//!
//! ## Advanced Topics
//!
//! ### Custom TLS Configuration
//! For advanced TLS scenarios like mTLS or custom certificate chains:
//!
//! ```rust,no_run
//! # use reqrio::*;
//! let mut req = ScReq::new();
//!
//! // Load client certificate and key
//! let certs = Certificate::from_pem_file("client.pem")?;
//! let key = RsaKey::from_pri_pem_file("client.key")?;
//!
//! // Add custom CA certificates
//! let ca_certs = Certificate::from_pem_file("ca-bundle.pem")?;
//!
//! // Set them in the request engine
//! // req.with_certs(certs).with_key(key).with_ca_certs(ca_certs);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ### Proxy Configuration
//! Route requests through HTTP/SOCKS proxies:
//!
//! ```rust,no_run
//! # use reqrio::*;
//! // let proxy = Proxy::http("http://proxy.example.com:8080")?;
//! // let mut req = ScReq::new().with_proxy(proxy);
//! ```
//!
//! ## Ecosystem Integration
//!
//! - **reqtls**: Underlying TLS and cryptographic engine
//! - **reqrio-json**: Built-in JSON utilities
//! - **hpack**: HTTP/2 header compression support
//!
//! For more examples and advanced usage, visit the [GitHub repository](https://github.com/xllgl2017/reqrio)
pub type ReqCallback = ;
pub const HTTP_GAP: & = b"\r\n\r\n";
pub const CHUNK_END: = ;
use crateHlsResult;
pub use AcReq;
pub use ;
pub use HlsError;
pub use ;
pub use ;
pub use ;
pub use reqrio_json as json;
pub use *;
pub use ScReq;
pub use TlsStream;
pub use ;
pub use ;
pub use tokio;
pub use Logger;