1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 09:42:40 +01:00

separate ResponseLength::Zero is not needed

This commit is contained in:
Nikolay Kim 2018-10-08 15:33:38 -07:00
parent 805e7a4cd0
commit 3984ad45df
3 changed files with 11 additions and 11 deletions

View File

@ -158,7 +158,8 @@ impl Codec {
buffer.extend_from_slice(b"\r\ntransfer-encoding: chunked\r\n") buffer.extend_from_slice(b"\r\ntransfer-encoding: chunked\r\n")
} }
ResponseLength::Zero => { 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) => { ResponseLength::Length(len) => {
helpers::write_content_length(len, buffer) helpers::write_content_length(len, buffer)
@ -169,10 +170,6 @@ impl Codec {
buffer.extend_from_slice(b"\r\n"); buffer.extend_from_slice(b"\r\n");
} }
ResponseLength::None => 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 // write headers
@ -185,7 +182,7 @@ impl Codec {
TRANSFER_ENCODING => continue, TRANSFER_ENCODING => continue,
CONTENT_LENGTH => match self.te.length { CONTENT_LENGTH => match self.te.length {
ResponseLength::None => (), ResponseLength::None => (),
ResponseLength::HeaderOrZero => { ResponseLength::Zero => {
len_is_set = true; len_is_set = true;
} }
_ => continue, _ => continue,

View File

@ -17,10 +17,8 @@ use response::Response;
#[derive(Debug)] #[derive(Debug)]
pub(crate) enum ResponseLength { pub(crate) enum ResponseLength {
Chunked, Chunked,
/// Content length is 0
Zero,
/// Check if headers contains length or write 0 /// Check if headers contains length or write 0
HeaderOrZero, Zero,
Length(usize), Length(usize),
Length64(u64), Length64(u64),
/// Do no set content-length /// Do no set content-length
@ -82,7 +80,7 @@ impl ResponseEncoder {
| StatusCode::CONTINUE | StatusCode::CONTINUE
| StatusCode::SWITCHING_PROTOCOLS | StatusCode::SWITCHING_PROTOCOLS
| StatusCode::PROCESSING => ResponseLength::None, | StatusCode::PROCESSING => ResponseLength::None,
_ => ResponseLength::HeaderOrZero, _ => ResponseLength::Zero,
}; };
TransferEncoding::empty() TransferEncoding::empty()
} }

View File

@ -123,6 +123,12 @@ fn test_content_length() {
.unwrap(); .unwrap();
let response = sys.block_on(req.send()).unwrap(); let response = sys.block_on(req.send()).unwrap();
assert_eq!(response.headers().get(&header), None); 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 { for i in 4..6 {
@ -254,7 +260,6 @@ fn test_head_empty() {
assert!(response.status().is_success()); assert!(response.status().is_success());
{ {
println!("RESP: {:?}", response);
let len = response let len = response
.headers() .headers()
.get(http::header::CONTENT_LENGTH) .get(http::header::CONTENT_LENGTH)