diff --git a/awc/src/request.rs b/awc/src/request.rs index 1daaa28cb..c97e08f81 100644 --- a/awc/src/request.rs +++ b/awc/src/request.rs @@ -544,6 +544,8 @@ impl fmt::Debug for ClientRequest { #[cfg(test)] mod tests { + use std::time::SystemTime; + use super::*; use crate::Client; @@ -555,6 +557,21 @@ mod tests { assert!(repr.contains("x-test")); } + #[test] + fn test_basics() { + let mut req = Client::new() + .put("/") + .version(Version::HTTP_2) + .set(header::Date(SystemTime::now().into())) + .content_type("plain/text") + .content_length(100); + assert!(req.headers().contains_key(header::CONTENT_TYPE)); + assert!(req.headers().contains_key(header::DATE)); + assert_eq!(req.head.version, Version::HTTP_2); + let _ = req.headers_mut(); + let _ = req.send_body(""); + } + #[test] fn test_client_header() { let req = Client::build() diff --git a/awc/src/test.rs b/awc/src/test.rs index fbbadef3a..8df21e8f9 100644 --- a/awc/src/test.rs +++ b/awc/src/test.rs @@ -134,3 +134,23 @@ impl TestResponse { } } } + +#[cfg(test)] +mod tests { + use std::time::SystemTime; + + use super::*; + use crate::{cookie, http::header}; + + #[test] + fn test_basics() { + let res = TestResponse::default() + .version(Version::HTTP_2) + .set(header::Date(SystemTime::now().into())) + .cookie(cookie::Cookie::build("name", "value").finish()) + .finish(); + assert!(res.headers().contains_key(header::SET_COOKIE)); + assert!(res.headers().contains_key(header::DATE)); + assert_eq!(res.version(), Version::HTTP_2); + } +} diff --git a/awc/src/ws.rs b/awc/src/ws.rs index 4f0983dc5..1ab6d563d 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -455,10 +455,20 @@ mod tests { .max_frame_size(100) .server_mode() .protocols(&["v1", "v2"]) + .set_header_if_none(header::CONTENT_TYPE, "json") + .set_header_if_none(header::CONTENT_TYPE, "text") .cookie(Cookie::build("cookie1", "value1").finish()); - assert_eq!(req.origin.unwrap().to_str().unwrap(), "test-origin"); + assert_eq!( + req.origin.as_ref().unwrap().to_str().unwrap(), + "test-origin" + ); assert_eq!(req.max_size, 100); assert_eq!(req.server_mode, true); assert_eq!(req.protocols, Some("v1,v2".to_string())); + assert_eq!( + req.head.headers.get(header::CONTENT_TYPE).unwrap(), + header::HeaderValue::from_static("json") + ); + let _ = req.connect(); } } diff --git a/src/middleware/cors.rs b/src/middleware/cors.rs index 1fa6e6690..813822c98 100644 --- a/src/middleware/cors.rs +++ b/src/middleware/cors.rs @@ -852,6 +852,17 @@ mod tests { assert_eq!(resp.status(), StatusCode::OK); } + #[test] + fn default() { + let mut cors = + block_on(Cors::default().new_transform(test::ok_service())).unwrap(); + let req = TestRequest::with_header("Origin", "https://www.example.com") + .to_srv_request(); + + let resp = test::call_success(&mut cors, req); + assert_eq!(resp.status(), StatusCode::OK); + } + #[test] fn test_preflight() { let mut cors = Cors::new()