leyline/core/config/
websocket.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2#[non_exhaustive]
3pub struct WebSocketConfig {
4 pub(crate) prefer_http2: bool,
5 pub(crate) max_frame_size: Option<usize>,
6 pub(crate) max_message_size: Option<usize>,
7 pub(crate) read_buffer_size: Option<usize>,
8 pub(crate) write_buffer_size: Option<usize>,
9 pub(crate) max_write_buffer_size: Option<usize>,
10 pub(crate) accept_unmasked_frames: bool,
11}
12
13impl Default for WebSocketConfig {
14 fn default() -> Self {
15 Self {
16 prefer_http2: true,
17 max_frame_size: None,
18 max_message_size: None,
19 read_buffer_size: None,
20 write_buffer_size: None,
21 max_write_buffer_size: None,
22 accept_unmasked_frames: false,
23 }
24 }
25}
26
27impl WebSocketConfig {
28 pub fn new() -> Self {
29 Self::default()
30 }
31
32 pub fn prefer_http2(mut self, on: bool) -> Self {
33 self.prefer_http2 = on;
34 self
35 }
36
37 pub fn max_frame_size(mut self, n: impl Into<Option<usize>>) -> Self {
38 self.max_frame_size = n.into();
39 self
40 }
41
42 pub fn max_message_size(mut self, n: impl Into<Option<usize>>) -> Self {
43 self.max_message_size = n.into();
44 self
45 }
46
47 pub fn read_buffer_size(mut self, n: impl Into<Option<usize>>) -> Self {
48 self.read_buffer_size = n.into();
49 self
50 }
51
52 pub fn write_buffer_size(mut self, n: impl Into<Option<usize>>) -> Self {
53 self.write_buffer_size = n.into();
54 self
55 }
56
57 pub fn max_write_buffer_size(mut self, n: impl Into<Option<usize>>) -> Self {
58 self.max_write_buffer_size = n.into();
59 self
60 }
61
62 pub fn accept_unmasked_frames(mut self, on: bool) -> Self {
63 self.accept_unmasked_frames = on;
64 self
65 }
66}