fix(server): skip automatic Content-Length header for HTTP 304 responses

Closes #1797
This commit is contained in:
João Oliveira
2019-05-07 20:53:25 +01:00
committed by Sean McArthur
parent 7fde9ba6b8
commit b342c38f08
2 changed files with 56 additions and 7 deletions

View File

@@ -476,14 +476,20 @@ impl Http1Transaction for Server {
},
None |
Some(BodyLength::Known(0)) => {
extend(dst, b"content-length: 0\r\n");
if msg.head.subject != StatusCode::NOT_MODIFIED {
extend(dst, b"content-length: 0\r\n");
}
Encoder::length(0)
},
Some(BodyLength::Known(len)) => {
extend(dst, b"content-length: ");
let _ = ::itoa::write(&mut dst, len);
extend(dst, b"\r\n");
Encoder::length(len)
if msg.head.subject == StatusCode::NOT_MODIFIED {
Encoder::length(0)
} else {
extend(dst, b"content-length: ");
let _ = ::itoa::write(&mut dst, len);
extend(dst, b"\r\n");
Encoder::length(len)
}
},
};
}
@@ -1583,4 +1589,3 @@ mod tests {
})
}
}