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§
source§impl Clone for ContentTypeHeaderRouteMatcher
impl Clone for ContentTypeHeaderRouteMatcher
source§fn clone(&self) -> ContentTypeHeaderRouteMatcher
fn clone(&self) -> ContentTypeHeaderRouteMatcher
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for ContentTypeHeaderRouteMatcher
impl RefUnwindSafe for ContentTypeHeaderRouteMatcher
impl Send for ContentTypeHeaderRouteMatcher
impl Sync for ContentTypeHeaderRouteMatcher
impl Unpin for ContentTypeHeaderRouteMatcher
impl UnwindSafe for ContentTypeHeaderRouteMatcher
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<M> IntoRouteMatcher for M
impl<M> IntoRouteMatcher for M
source§fn 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
.