From 3984ad45dfb5f13a9e645b0f48265c5ec5b6834f Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 8 Oct 2018 15:33:38 -0700 Subject: [PATCH] separate ResponseLength::Zero is not needed --- src/h1/codec.rs | 9 +++------ src/h1/encoder.rs | 6 ++---- tests/test_server.rs | 7 ++++++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/h1/codec.rs b/src/h1/codec.rs index 16965768f..8f97d6779 100644 --- a/src/h1/codec.rs +++ b/src/h1/codec.rs @@ -158,7 +158,8 @@ impl Codec { buffer.extend_from_slice(b"\r\ntransfer-encoding: chunked\r\n") } ResponseLength::Zero => { - buffer.extend_from_slice(b"\r\ncontent-length: 0\r\n") + len_is_set = false; + buffer.extend_from_slice(b"\r\n") } ResponseLength::Length(len) => { helpers::write_content_length(len, buffer) @@ -169,10 +170,6 @@ impl Codec { buffer.extend_from_slice(b"\r\n"); } ResponseLength::None => buffer.extend_from_slice(b"\r\n"), - ResponseLength::HeaderOrZero => { - len_is_set = false; - buffer.extend_from_slice(b"\r\n") - } } // write headers @@ -185,7 +182,7 @@ impl Codec { TRANSFER_ENCODING => continue, CONTENT_LENGTH => match self.te.length { ResponseLength::None => (), - ResponseLength::HeaderOrZero => { + ResponseLength::Zero => { len_is_set = true; } _ => continue, diff --git a/src/h1/encoder.rs b/src/h1/encoder.rs index 6e8d44cee..ea11f11fd 100644 --- a/src/h1/encoder.rs +++ b/src/h1/encoder.rs @@ -17,10 +17,8 @@ use response::Response; #[derive(Debug)] pub(crate) enum ResponseLength { Chunked, - /// Content length is 0 - Zero, /// Check if headers contains length or write 0 - HeaderOrZero, + Zero, Length(usize), Length64(u64), /// Do no set content-length @@ -82,7 +80,7 @@ impl ResponseEncoder { | StatusCode::CONTINUE | StatusCode::SWITCHING_PROTOCOLS | StatusCode::PROCESSING => ResponseLength::None, - _ => ResponseLength::HeaderOrZero, + _ => ResponseLength::Zero, }; TransferEncoding::empty() } diff --git a/tests/test_server.rs b/tests/test_server.rs index e86176097..3b13b98ed 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -123,6 +123,12 @@ fn test_content_length() { .unwrap(); let response = sys.block_on(req.send()).unwrap(); assert_eq!(response.headers().get(&header), None); + + let req = client::ClientRequest::head(format!("http://{}/{}", addr, i)) + .finish() + .unwrap(); + let response = sys.block_on(req.send()).unwrap(); + assert_eq!(response.headers().get(&header), None); } for i in 4..6 { @@ -254,7 +260,6 @@ fn test_head_empty() { assert!(response.status().is_success()); { - println!("RESP: {:?}", response); let len = response .headers() .get(http::header::CONTENT_LENGTH)