diff --git a/src/async_impl/body.rs b/src/async_impl/body.rs index e081e0d796..419d00e5c3 100644 --- a/src/async_impl/body.rs +++ b/src/async_impl/body.rs @@ -354,6 +354,8 @@ where #[cfg(test)] mod tests { + use http_body::Body as _; + use super::Body; #[test] @@ -362,4 +364,11 @@ mod tests { let body = Body::from(&test_data[..]); assert_eq!(body.as_bytes(), Some(&test_data[..])); } + + #[test] + fn body_exact_length() { + assert_eq!(Body::empty().size_hint().exact(), None); + assert_eq!(Body::reusable("abc".into()).size_hint().exact(), Some(3)); + assert_eq!(Body::streaming(Body::reusable("abc".into())).size_hint().exact(), None); + } } diff --git a/tests/blocking.rs b/tests/blocking.rs index c4ea04befe..62370a0f18 100644 --- a/tests/blocking.rs +++ b/tests/blocking.rs @@ -21,6 +21,27 @@ fn test_response_text() { assert_eq!(b"Hello", body.as_bytes()); } +#[test] +fn donot_set_conent_length_0_if_have_no_body() { + let server = server::http(move |req| async move { + let headers = req.headers(); + assert_eq!(headers.get("content-length"), None); + dbg!(&headers); + http::Response::default() + }); + + let url = format!("http://{}/conent-length", server.addr()); + let res = reqwest::blocking::Client::builder() + .no_proxy() + .build() + .expect("client builder") + .get(&url) + .send() + .expect("request"); + + assert_eq!(res.status(), reqwest::StatusCode::OK); +} + #[test] #[cfg(feature = "charset")] fn test_response_non_utf_8_text() { diff --git a/tests/client.rs b/tests/client.rs index 02f32fc854..60eea57e0d 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -54,6 +54,28 @@ async fn auto_headers() { assert_eq!(res.remote_addr(), Some(server.addr())); } +#[tokio::test] +async fn donot_set_conent_length_0_if_have_no_body() { + let server = server::http(move |req| async move { + let headers = req.headers(); + assert_eq!(headers.get("content-length"), None); + dbg!(&headers); + http::Response::default() + }); + + let url = format!("http://{}/conent-length", server.addr()); + let res = reqwest::Client::builder() + .no_proxy() + .build() + .expect("client builder") + .get(&url) + .send() + .await + .expect("request"); + + assert_eq!(res.status(), reqwest::StatusCode::OK); +} + #[tokio::test] async fn user_agent() { let server = server::http(move |req| async move {