pub struct HeaderEscapeGuard;Expand description
Typed guard for HTTP response header values.
The struct is zero-sized; it exists for the namespace and for future extensions (e.g., per-boundary length policies). Callers invoke the guard exclusively through associated functions.
ⓘ
use crate::server::header_escape_guard::{HeaderEscapeGuard, EscapeError};
let value = HeaderEscapeGuard::header_value("max-age=3600")?;
// value is now an `http::HeaderValue` safe to attach to a
// response. Attempting to splice a second header line is
// rejected at the type boundary:
assert!(matches!(
HeaderEscapeGuard::header_value("evil\r\nX-Forged: 1"),
Err(EscapeError::ContainsCrlf),
));Implementations§
Source§impl HeaderEscapeGuard
impl HeaderEscapeGuard
Sourcepub fn header_value(s: &str) -> Result<HeaderValue, EscapeError>
pub fn header_value(s: &str) -> Result<HeaderValue, EscapeError>
Validate s and wrap it in a typed http::HeaderValue.
Returns the typed error (EscapeError) on the first byte that
violates the contract. The order of checks is: oversize →
CRLF → NUL → TAB → other non-printable. Callers must not
assume the order — only that some violation triggered the
rejection.
Auto Trait Implementations§
impl Freeze for HeaderEscapeGuard
impl RefUnwindSafe for HeaderEscapeGuard
impl Send for HeaderEscapeGuard
impl Sync for HeaderEscapeGuard
impl Unpin for HeaderEscapeGuard
impl UnsafeUnpin for HeaderEscapeGuard
impl UnwindSafe for HeaderEscapeGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request