diff --git a/ylong_http/src/body/chunk.rs b/ylong_http/src/body/chunk.rs index c71153180eb86a30fb3e73fe25f38ed8e33efd79..8b3ec35b7f04bf8d18cdd84006eafcc90e91b0df 100644 --- a/ylong_http/src/body/chunk.rs +++ b/ylong_http/src/body/chunk.rs @@ -100,9 +100,9 @@ enum DataState { // Component encoding status enum TokenStatus { // The current component is completely encoded. - Complete(T), + Complete(T), // The current component is partially encoded. - Partial(E), + Partial(E), } type Token = TokenStatus; diff --git a/ylong_http/src/body/mod.rs b/ylong_http/src/body/mod.rs index 0bc031b521fb639267c451a039c66b3048ae2052..d3d6ca6eed24c6dbcaec78ca55863a52512a7aa3 100644 --- a/ylong_http/src/body/mod.rs +++ b/ylong_http/src/body/mod.rs @@ -382,7 +382,6 @@ pub mod async_impl { poll_read(Pin::new(&mut self.as_bytes()), cx, buf) } } - } // Type definitions of the origin of the body data. diff --git a/ylong_http_client/src/util/normalizer.rs b/ylong_http_client/src/util/normalizer.rs index 7af6f6936dceca5d4039c66b874008aef66735d9..384ccff04ffbd01ca7d4ac44cfb830519cd81089 100644 --- a/ylong_http_client/src/util/normalizer.rs +++ b/ylong_http_client/src/util/normalizer.rs @@ -159,13 +159,15 @@ impl<'a> BodyLengthParser<'a> { .and_then(|v| v.to_str().ok()) .and_then(|s| s.parse::().ok()); - return if let Some(len) = content_length_valid { - Ok(BodyLength::Length(len)) - } else { - Err(HttpClientError::new_with_message( + return match content_length_valid { + // If `content-length` is 0, the io stream cannot be read, + // otherwise it will get stuck. + Some(0) => Ok(BodyLength::Empty), + Some(len) => Ok(BodyLength::Length(len)), + None => Err(HttpClientError::new_with_message( ErrorKind::Request, "Invalid response content-length", - )) + )), }; } diff --git a/ylong_http_client/tests/sdv_async_http_on_tcp.rs b/ylong_http_client/tests/sdv_async_http_on_tcp.rs index 96ba103a5b8cb7999feb53662b65ea364782d8e4..4debf46925aa16c33e3113922d0be4075ee3a446 100644 --- a/ylong_http_client/tests/sdv_async_http_on_tcp.rs +++ b/ylong_http_client/tests/sdv_async_http_on_tcp.rs @@ -114,6 +114,23 @@ fn sdv_async_client_send_request() { Body: "Hi!", }, ); + + // The content-length of `Response` is 0. + async_client_test_on_tcp!( + HTTP; + Request: { + Method: "GET", + Path: "/data", + Header: "Content-Length", "6", + Body: "Hello!", + }, + Response: { + Status: 200, + Version: "HTTP/1.1", + Header: "Content-Length", "0", + Body: "", + }, + ); } /// SDV test cases for `async::Client`.