Struct gotham::router::route::matcher::ContentTypeHeaderRouteMatcher [−][src]
pub struct ContentTypeHeaderRouteMatcher { /* fields omitted */ }
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
Auto Trait Implementations
impl Send for ContentTypeHeaderRouteMatcher
impl Sync for ContentTypeHeaderRouteMatcher
impl Unpin for ContentTypeHeaderRouteMatcher
impl UnwindSafe for ContentTypeHeaderRouteMatcher
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = M
type Output = M
The concrete RouteMatcher each implementation will provide.
Transform into a RouteMatcher
of the the associated type identified by Output
.
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more