pub fn bounded(token: &str) -> Cow<'_, str>Expand description
Caps a peer-chosen token at what a log line can afford to carry.
Some of the tokens that reach a log line are a field section’s worth of
bytes – up to crate::h3api::MAX_FIELD_SECTION_SIZE – from a peer that
has not authenticated: the :protocol of an extended CONNECT, the user-id
of a rejected credential. Logging one whole puts tens of kilobytes in the
journal per request, for free, and journald’s rate limiting counts lines
rather than bytes, so it is no backstop. The routing decision and the
response still see the whole value; only the log is bounded.
The length is kept because a token cut short is otherwise indistinguishable
from a short one, and the cut lands on a character boundary because slicing
a str anywhere else panics.
This bounds length only. Escaping is the recording sigil’s job: the
result goes into a line as a str field or with ?, never with %, or a
newline inside it forges a journal entry exactly as the third rule above
describes.
assert_eq!(bounded("connect-udp"), "connect-udp");