diff options
author | Martin Fischer <martin@push-f.com> | 2021-01-29 21:11:07 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-01-29 21:11:07 +0100 |
commit | 7a9b7447577ed5eaeb326d1e9017a8f773e1f193 (patch) | |
tree | af4ce23258ea3b09d24854ac8cf734f450f8dd3e /src | |
parent | c7d3bd087c49bdd0b33ed23ff583bf58ba705a1c (diff) |
add test for enforce_content_type
Diffstat (limited to 'src')
-rw-r--r-- | src/request.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/request.rs b/src/request.rs index 8059e07..95f5a32 100644 --- a/src/request.rs +++ b/src/request.rs @@ -203,4 +203,25 @@ pub enum JsonError { #[error("json deserialize error: {0}")] Deserialize(#[from] serde_json::Error), +} + +#[cfg(test)] +mod tests { + use std::convert::TryInto; + + use hyper::{Request, header}; + + use super::SputnikParts; + + #[test] + fn test_enforce_content_type() { + let (mut parts, _body) = Request::new(hyper::Body::empty()).into_parts(); + assert!(parts.enforce_content_type(mime::APPLICATION_JSON).is_err()); + + parts.headers.append(header::CONTENT_TYPE, "application/json".try_into().unwrap()); + assert!(parts.enforce_content_type(mime::APPLICATION_JSON).is_ok()); + + parts.headers.insert(header::CONTENT_TYPE, "text/html".try_into().unwrap()); + assert!(parts.enforce_content_type(mime::APPLICATION_JSON).is_err()); + } }
\ No newline at end of file |