oxedyne/fe2o3/fe2o3_net/src/constant.rs
4.3 KiB, 8 runs
created by r1870400018:559, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | // HTTP |
| 2 | pub const HTTP_DEFAULT_HEADER_CHUNK_SIZE: usize = 1_500; |
| 3 | pub const HTTP_DEFAULT_BODY_CHUNK_SIZE: usize = 5_000; |
| 4 | |
| 5 | /// Bytes copied from a file to the socket at a time when a message body is a |
| 6 | /// window of a file rather than a buffer. |
| 7 | /// |
| 8 | /// Larger than the body chunk above because this one is a bulk transfer, not a |
| 9 | /// protocol read: a gigabyte of video at five kilobytes a write is two hundred |
| 10 | /// thousand syscalls, and as many TLS records. |
| 11 | pub const HTTP_FILE_BODY_CHUNK_SIZE: usize = 65_536; |
| 12 | |
| 13 | /// Most that is reserved up front for a message body on the strength of its `Content-Length`. |
| 14 | /// |
| 15 | /// A body larger than this is still read, in the chunks the read loop already uses; the vector |
| 16 | /// simply grows into it. What the ceiling prevents is a single allocation sized by a number a |
| 17 | /// stranger wrote, which is free to write and not free to honour. One mebibyte covers the bodies |
| 18 | /// that actually arrive, so the reservation is doing its job in every ordinary case. |
| 19 | pub const HTTP_BODY_RESERVE_MAX: usize = 1_048_576; |
| 20 | |
| 21 | /// Longest a chunked body's chunk-size line may run before its terminating |
| 22 | /// CRLF arrives. |
| 23 | /// |
| 24 | /// The line is a hex length and optional `;`-delimited extensions, so a few |
| 25 | /// dozen bytes covers every legitimate one. Fixed rather than tied to |
| 26 | /// `ReadLimits::max_header_bytes`, because a peer that never closes the line |
| 27 | /// is a resource-exhaustion attempt whatever header or body bound is |
| 28 | /// configured -- including none -- so the cap applies even to a caller that |
| 29 | /// set no `ReadLimits` at all. A trailer line, by contrast, is bounded by |
| 30 | /// `max_header_bytes` itself: it is one more header-like field, and inherits |
| 31 | /// whatever policy the caller already chose for the header block. |
| 32 | pub const HTTP_CHUNK_LINE_MAX: usize = 4_096; |
| 33 | |
| 34 | pub const HTTP_HEADER_MAX_MULTILINES: u8 = 10; |
| 35 | pub const HTTP_HEADER_MAX_FIELDS: u16 = 100; |
| 36 | pub const HTTP_BODY_BYTES_MAX_VIEW: usize = 300; |
| 37 | pub const SESSION_ID_KEY_LABEL: &'static str = "session_id"; |
| 38 | |
| 39 | // SMTP |
| 40 | //pub const SMTP_READ_BUFFER_SIZE: usize = 10;//1_024; |
| 41 | |
| 42 | // WebSocket |
| 43 | pub const WEBSOCKET_GUID: &'static str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; |
| 44 | pub const WEBSOCKET_LATENCY_HISTORY_SIZE: usize = 540; // 3 hrs @ 30 s intervals |
| 45 | |
| 46 | /// Default bound on the payload one websocket frame may declare, in bytes. |
| 47 | /// |
| 48 | /// A frame header states its own payload length in as much as 64 bits, and the reader must have |
| 49 | /// somewhere to put those bytes before it can read them, so a reader that believes the number |
| 50 | /// allocates whatever a stranger asks it to. Sixteen mebibytes is the same default the widely |
| 51 | /// deployed Rust implementation uses, is far above any framing produced by a browser sending a |
| 52 | /// message of ordinary size, and is small enough that a machine can absorb several at once. |
| 53 | /// |
| 54 | /// An application whose peers legitimately send single frames larger than this raises the bound |
| 55 | /// rather than removing it -- see [`crate::ws::WebSocketLimits`]. |
| 56 | pub const WEBSOCKET_MAX_FRAME_BYTES: usize = 16 * 1_048_576; |
| 57 | |
| 58 | /// Default bound on the payload a whole websocket message may reach once its frames are joined, |
| 59 | /// in bytes. |
| 60 | /// |
| 61 | /// The frame bound alone bounds nothing: a message may arrive as any number of continuation |
| 62 | /// frames, each of them under the frame bound, and the reader joins them all in one buffer. Four |
| 63 | /// times the frame bound, so that a fragmented message has room to be several frames long while |
| 64 | /// the total a peer can pin remains a number chosen here rather than one chosen by the peer. |
| 65 | pub const WEBSOCKET_MAX_MESSAGE_BYTES: usize = 64 * 1_048_576; |
| 66 | |
| 67 | /// Largest payload a websocket control frame may carry, in bytes, as RFC 6455 §5.5 fixes it. |
| 68 | /// |
| 69 | /// Not configurable, because it is not ours to choose: a control frame declaring more than this is |
| 70 | /// malformed whatever an application would like to allow. |
| 71 | pub const WEBSOCKET_MAX_CONTROL_FRAME_BYTES: u64 = 125; |
| 72 | |
| 73 | pub const READ_LOOP_SAFETY_LIMIT: usize = 100; |
| 74 | |
| 75 | // DNS |
| 76 | /// List of special case domains that are valid without dots. Based on RFC 6761 and common |
| 77 | /// practice. |
| 78 | pub const SPECIAL_DOMAINS: &[&str] = &[ |
| 79 | "localhost", |
| 80 | "invalid", // RFC 6761 |
| 81 | "example", // RFC 6761 |
| 82 | "test", // RFC 6761 |
| 83 | ]; |