1use core::time::Duration;
4
5pub const DEFAULT_READ_BUF_LIMIT: usize = 1024 * 1024;
11
12pub const DEFAULT_WRITE_BUF_LIMIT: usize = 8192 + 4096 * 100;
16
17pub const DEFAULT_HEADER_LIMIT: usize = 64;
21
22#[derive(Copy, Clone)]
23pub struct HttpServiceConfig<
24 const HEADER_LIMIT: usize = DEFAULT_HEADER_LIMIT,
25 const READ_BUF_LIMIT: usize = DEFAULT_READ_BUF_LIMIT,
26 const WRITE_BUF_LIMIT: usize = DEFAULT_WRITE_BUF_LIMIT,
27> {
28 pub(crate) vectored_write: bool,
29 pub(crate) keep_alive_timeout: Duration,
30 pub(crate) request_head_timeout: Duration,
31 pub(crate) tls_accept_timeout: Duration,
32 pub(crate) peek_protocol: bool,
33}
34
35impl Default for HttpServiceConfig {
36 fn default() -> Self {
37 Self::new()
38 }
39}
40
41impl HttpServiceConfig {
42 pub const fn new() -> Self {
43 Self {
44 vectored_write: true,
45 keep_alive_timeout: Duration::from_secs(5),
46 request_head_timeout: Duration::from_secs(5),
47 tls_accept_timeout: Duration::from_secs(3),
48 peek_protocol: false,
49 }
50 }
51}
52
53impl<const HEADER_LIMIT: usize, const READ_BUF_LIMIT: usize, const WRITE_BUF_LIMIT: usize>
54 HttpServiceConfig<HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>
55{
56 pub fn disable_vectored_write(mut self) -> Self {
60 self.vectored_write = false;
61 self
62 }
63
64 pub fn keep_alive_timeout(mut self, dur: Duration) -> Self {
69 self.keep_alive_timeout = dur;
70 self
71 }
72
73 pub fn request_head_timeout(mut self, dur: Duration) -> Self {
78 self.request_head_timeout = dur;
79 self
80 }
81
82 pub fn tls_accept_timeout(mut self, dur: Duration) -> Self {
87 self.tls_accept_timeout = dur;
88 self
89 }
90
91 pub fn max_read_buf_size<const READ_BUF_LIMIT_2: usize>(
96 self,
97 ) -> HttpServiceConfig<HEADER_LIMIT, READ_BUF_LIMIT_2, WRITE_BUF_LIMIT> {
98 self.mutate_const_generic::<HEADER_LIMIT, READ_BUF_LIMIT_2, WRITE_BUF_LIMIT>()
99 }
100
101 pub fn max_write_buf_size<const WRITE_BUF_LIMIT_2: usize>(
106 self,
107 ) -> HttpServiceConfig<HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT_2> {
108 self.mutate_const_generic::<HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT_2>()
109 }
110
111 pub fn max_request_headers<const HEADER_LIMIT_2: usize>(
116 self,
117 ) -> HttpServiceConfig<HEADER_LIMIT_2, READ_BUF_LIMIT, WRITE_BUF_LIMIT> {
118 self.mutate_const_generic::<HEADER_LIMIT_2, READ_BUF_LIMIT, WRITE_BUF_LIMIT>()
119 }
120
121 pub fn peek_protocol(mut self) -> Self {
127 self.peek_protocol = true;
128 self
129 }
130
131 #[doc(hidden)]
132 pub fn mutate_const_generic<
134 const HEADER_LIMIT2: usize,
135 const READ_BUF_LIMIT2: usize,
136 const WRITE_BUF_LIMIT2: usize,
137 >(
138 self,
139 ) -> HttpServiceConfig<HEADER_LIMIT2, READ_BUF_LIMIT2, WRITE_BUF_LIMIT2> {
140 HttpServiceConfig {
141 vectored_write: self.vectored_write,
142 keep_alive_timeout: self.keep_alive_timeout,
143 request_head_timeout: self.request_head_timeout,
144 tls_accept_timeout: self.tls_accept_timeout,
145 peek_protocol: self.peek_protocol,
146 }
147 }
148}