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
//! The caller's bounds, passed to every decode, and the numbers they default
//! to.
//!
//! HTTP sets no limit of its own on a head, a field count or a chunk line
//! (RFC 9110 §5.4 lets a recipient refuse with 431 and says nothing about
//! where): every bound is the recipient's choice. So each is an **argument**,
//! carried by value in [`Limits`], and each is checked from what the peer
//! declared or from how far the decoder has searched, before anything is
//! reserved for it.
//!
//! Four numbers, because a peer has four ways to make a decoder commit memory
//! or time: a head (or a compressed field section) that never ends or expands
//! without bound, a field section of unboundedly many tiny fields, a chunk-size
//! line that never ends, and a frame whose length prefix announces megabytes.
/// A starting value for [`Limits::max_head_bytes`]: 64 KiB.
///
/// A **named constant, not a cap**: the cap is the field, set by the caller.
/// 64 KiB is four times the HTTP/2 default frame payload and well above what
/// browsers send (cookies included); servers commonly refuse at 8 to 64 KiB.
pub const DEFAULT_MAX_HEAD_BYTES: usize = 64 * 1024;
/// A starting value for [`Limits::max_fields`]: 128.
///
/// A **named constant, not a cap**. `a:\r\n` is four octets, so a 64 KiB head
/// can carry sixteen thousand fields, each costing a vector slot; 128 is an
/// order of magnitude above what a browser sends.
pub const DEFAULT_MAX_FIELDS: usize = 128;
/// A starting value for [`Limits::max_chunk_line`]: 1 KiB.
///
/// A **named constant, not a cap**. A chunk-size line is sixteen hex digits at
/// most; the rest is chunk extensions, which nobody uses and which this codec
/// steps over, so the bound only has to be generous to them.
pub const DEFAULT_MAX_CHUNK_LINE: usize = 1024;
/// A starting value for [`Limits::max_frame_size`]: 16 384, the HTTP/2
/// default and minimum of `SETTINGS_MAX_FRAME_SIZE` (RFC 9113 §6.5.2).
///
/// A **named constant, not a cap**.
pub const DEFAULT_MAX_FRAME_SIZE: u32 = 16_384;
/// Bounds a decoder applies to remote input.
///
/// Every decode entry point in this crate takes one, by value. There is no way
/// to switch a bound off; `usize::MAX` still cannot make a decoder read past
/// its input, but it lets a peer's declaration through, which is exactly what
/// the type exists to stop.