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
//! The per-request identity that code deep inside a handler reads without
//! having a `Request` to extract from.
//!
//! Two consumers, and neither is the HTTP layer: `OrionError::IntoResponse`
//! embeds `request_id` in the error body so a client does not have to
//! correlate header to body, and a channel's custom error body can interpolate
//! it. `errors` sits below `server` — every module in the tree produces an
//! `OrionError` — so reading the context out of `server::request_context` made
//! the error type depend on the HTTP layer.
//!
//! A parameter would be the obvious alternative, but `IntoResponse::into_response`
//! takes `self` and nothing else, so there is nowhere to put one. A task-local
//! is the right mechanism; it was only in the wrong place. The middleware that
//! *fills* it stays in [`crate::server::request_context`], where the `Request`
//! and the trusted-proxy policy are.
/// Longest inbound `x-request-id` carried in the context. The value is
/// attacker-controlled — `SetRequestIdLayer` only *generates* an id when the
/// header is absent, so a caller that sends one controls this string end to
/// end — and it is persisted in an audit row's `details` and echoed in
/// `error.request_id`. Generous next to the 36-byte UUID we generate, but
/// bounded. Truncating here does not change the response header, which
/// `PropagateRequestIdLayer` echoes verbatim.
pub const MAX_REQUEST_ID_LEN: usize = 200;
/// Longest user-agent string persisted in an audit row. Real agents are well
/// under 200 bytes; the cap exists for the same reason as
/// [`MAX_REQUEST_ID_LEN`].
pub const MAX_USER_AGENT_LEN: usize = 256;
/// The caller-supplied change context (K5): tooling stamps what a mutation
/// was part of — the packaging CLI sends `package=<name>@<version>` — and the
/// audit trail records it, making a multi-request apply reconstructible.
/// Free-form; same cap and reasoning.
pub const MAX_CHANGE_CONTEXT_LEN: usize = 256;
/// Request-scoped identity of the caller.
task_local!
/// The current request id, or `None` outside a request scope.
/// A clone of the current request context, or `None` outside a request scope.