Skip to main content

http_type/request/
struct.rs

1use crate::*;
2
3/// Configuration for HTTP request parsing security limits.
4///
5/// This struct defines various limits and constraints to prevent
6/// denial-of-service attacks and other security vulnerabilities
7/// when parsing HTTP requests.
8#[derive(
9    Clone,
10    Copy,
11    Debug,
12    Deserialize,
13    DisplayDebug,
14    Eq,
15    Getter,
16    GetterMut,
17    PartialEq,
18    Serialize,
19    Setter,
20)]
21pub struct RequestConfigData {
22    /// Buffer size for reading operations.
23    #[get(type(copy))]
24    pub(super) buffer_size: usize,
25    /// Maximum size for HTTP request line in bytes.
26    #[get(type(copy))]
27    pub(super) max_request_line_size: usize,
28    /// Maximum size for URL path in bytes.
29    #[get(type(copy))]
30    pub(super) max_path_size: usize,
31    /// Maximum size for query string in bytes.
32    #[get(type(copy))]
33    pub(super) max_query_size: usize,
34    /// Maximum size for a single header line in bytes.
35    #[get(type(copy))]
36    pub(super) max_header_line_size: usize,
37    /// Maximum number of headers allowed in a request.
38    #[get(type(copy))]
39    pub(super) max_header_count: usize,
40    /// Maximum size for a header key in bytes.
41    #[get(type(copy))]
42    pub(super) max_header_key_size: usize,
43    /// Maximum size for a header value in bytes.
44    #[get(type(copy))]
45    pub(super) max_header_value_size: usize,
46    /// Maximum size for request body in bytes.
47    #[get(type(copy))]
48    pub(super) max_body_size: usize,
49    /// Maximum size for WebSocket frame in bytes.
50    #[get(type(copy))]
51    pub(super) max_ws_frame_size: usize,
52    /// Maximum number of WebSocket frames to process in a single request.
53    #[get(type(copy))]
54    pub(super) max_ws_frames_count: usize,
55    /// Timeout for reading HTTP request in milliseconds.
56    #[get(type(copy))]
57    pub(super) http_read_timeout_ms: u64,
58    /// Timeout for reading WebSocket frames in milliseconds.
59    #[get(type(copy))]
60    pub(super) ws_read_timeout_ms: u64,
61}
62
63/// Thread-safe configuration wrapper for HTTP request parsing.
64///
65/// This struct uses `ArcRwLock` to provide thread-safe access to `RequestConfigData `,
66/// allowing concurrent reads and exclusive writes. It is the public-facing API
67/// for configuring HTTP request parsing limits.
68#[derive(Clone, CustomDebug, DisplayDebug, Getter)]
69pub struct RequestConfig(#[get(pub(super))] pub(super) ArcRwLock<RequestConfigData>);
70
71/// HTTP request representation.
72///
73/// Contains all components of an HTTP request.
74#[derive(
75    Clone, Debug, Deserialize, DisplayDebug, Eq, Getter, GetterMut, PartialEq, Serialize, Setter,
76)]
77pub struct Request {
78    /// HTTP request method.
79    pub(super) method: RequestMethod,
80    /// Request host.
81    pub(super) host: RequestHost,
82    /// HTTP protocol version.
83    pub(super) version: RequestVersion,
84    /// Request path.
85    pub(super) path: RequestPath,
86    /// URL query parameters.
87    pub(super) querys: RequestQuerys,
88    /// HTTP headers collection.
89    pub(super) headers: RequestHeaders,
90    /// Request body content.
91    pub(super) body: RequestBody,
92}
93
94/// HTTP request representation.
95#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, New, PartialEq, Serialize)]
96pub(crate) struct Http;
97
98/// WebSocket request representation.
99#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, New, PartialEq, Serialize)]
100pub(crate) struct Ws;