aboutsummaryrefslogtreecommitdiff
path: root/src/request.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/request.rs')
-rw-r--r--src/request.rs21
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