pub enum McpSessionIdError {
Empty,
NotVisibleAscii {
index: usize,
byte: u8,
low: u8,
high: u8,
},
WrongLength {
expected: usize,
found: usize,
},
NotHex {
index: usize,
character: char,
},
Unparsable {
source: ParseIntError,
},
}Expand description
Why a Mcp-Session-Id header is not an McpSessionId.
Four distinct refusals rather than one, because they are four different mistakes and a caller that gets one of them back needs to know which. A single “invalid” string would make the common case — a client that sent the wrong header name, or one that pre-dates the session concept — impossible to tell apart from a truncated value.
Deliberately not Copy, unlike the value types beside it: the last variant
carries a ParseIntError, and Copy is only worth having on a type that
lives on the request path. This one is produced once, on a refusal.
Variants§
Empty
The value was nothing but optional whitespace.
NotVisibleAscii
A byte outside the visible-ASCII range reached the value.
Fields
low: u8Lowest permitted byte, VISIBLE_ASCII_RANGE’s start.
high: u8Highest permitted byte, VISIBLE_ASCII_RANGE’s end.
WrongLength
The value was not sixteen characters.
NotHex
A character in the value was not a hexadecimal digit.
Unparsable
The digits were well-formed but did not denote a u64.
Fields
source: ParseIntErrorThe underlying conversion failure.
Implementations§
Source§impl McpSessionIdError
impl McpSessionIdError
Sourcepub fn validate_opaque(value: &str) -> Result<&str, Self>
pub fn validate_opaque(value: &str) -> Result<&str, Self>
Checks a raw header value and returns its significant part.
Trimming first is not leniency for its own sake: RFC 9110 §5.5 allows optional whitespace around a field-value and an HTTP parser is entitled to hand the field with it still attached. Rejecting a legal header because of transport framing the client could not have avoided would be our bug, not theirs.
Interior whitespace is not tolerated even though field-value
technically permits it, and the narrowing is deliberate: that allowance
is for a human-typed Subject:, and a session id is a machine-carried
identifier that no reader would expect to be trimmed. A value with a tab
in the middle is refused as not visible ASCII, which is where a reader
would look for it.
§Errors
McpSessionIdError::Empty for a wholly blank value, and
McpSessionIdError::NotVisibleAscii naming the first byte that is out
of range. Only the first offender is reported: the value is a header,
and a message listing every bad byte in a 4 KiB garbage string is noise.
This checks only what the specification requires of a session id:
“The session ID MUST only contain visible ASCII characters”, and it
is otherwise the server’s to shape. A client holds whatever id the
server it dialled issued — a UUID, a JWT, a counter — so it must not
insist on the sixteen-digit form this crate’s own server happens to
write; validate is for the server side, which does.
Trait Implementations§
Source§impl Clone for McpSessionIdError
impl Clone for McpSessionIdError
Source§impl Debug for McpSessionIdError
impl Debug for McpSessionIdError
Source§impl Display for McpSessionIdError
impl Display for McpSessionIdError
impl Eq for McpSessionIdError
Source§impl Error for McpSessionIdError
impl Error for McpSessionIdError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()