pub struct ContentTypeHeaderRouteMatcher { /* private fields */ }
Expand description
A RouteMatcher
that succeeds when the Request
has been made with a Content-Type
header
that includes a supported media type. The matcher will fail if the Content-Type
header is missing, unless you call allow_no_type
on it.
Examples
let supported_media_types = vec![mime::APPLICATION_JSON];
let matcher = ContentTypeHeaderRouteMatcher::new(supported_media_types);
// No content type header
state.put(HeaderMap::new());
assert!(matcher.is_match(&state).is_err());
// Content type header of `application/json`
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, "application/json".parse().unwrap());
state.put(headers);
assert!(matcher.is_match(&state).is_ok());
// Not a valid Content-Type header
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, "text/plain".parse().unwrap());
state.put(headers);
assert!(matcher.is_match(&state).is_err());
// At least one supported content type header
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, "text/plain".parse().unwrap());
headers.insert(CONTENT_TYPE, "application/json".parse().unwrap());
state.put(headers);
assert!(matcher.is_match(&state).is_ok());
Implementations
Trait Implementations
sourceimpl Clone for ContentTypeHeaderRouteMatcher
impl Clone for ContentTypeHeaderRouteMatcher
sourcefn clone(&self) -> ContentTypeHeaderRouteMatcher
fn clone(&self) -> ContentTypeHeaderRouteMatcher
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations
impl RefUnwindSafe for ContentTypeHeaderRouteMatcher
impl Send for ContentTypeHeaderRouteMatcher
impl Sync for ContentTypeHeaderRouteMatcher
impl Unpin for ContentTypeHeaderRouteMatcher
impl UnwindSafe for ContentTypeHeaderRouteMatcher
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<M> IntoRouteMatcher for Mwhere
M: 'static + RouteMatcher + Send + Sync,
impl<M> IntoRouteMatcher for Mwhere
M: 'static + RouteMatcher + Send + Sync,
type Output = M
type Output = M
The concrete RouteMatcher each implementation will provide.
sourcefn into_route_matcher(self) -> <M as IntoRouteMatcher>::Output
fn into_route_matcher(self) -> <M as IntoRouteMatcher>::Output
Transform into a
RouteMatcher
of the the associated type identified by Output
.