Skip to content

Commit

Permalink
fix(server): skip automatic Content-Length headers when not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
psmit committed Jun 3, 2020
1 parent 2354a7e commit 4323493
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/proto/h1/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,13 @@ impl Http1Transaction for Server {
}
}
None | Some(BodyLength::Known(0)) => {
if msg.head.subject != StatusCode::NOT_MODIFIED {
if Server::can_have_body(msg.req_method, msg.head.subject) {
extend(dst, b"content-length: 0\r\n");
}
Encoder::length(0)
}
Some(BodyLength::Known(len)) => {
if msg.head.subject == StatusCode::NOT_MODIFIED {
if !Server::can_have_body(msg.req_method, msg.head.subject) {
Encoder::length(0)
} else {
extend(dst, b"content-length: ");
Expand Down Expand Up @@ -595,13 +595,11 @@ impl Server {
if method == &Some(Method::HEAD) || method == &Some(Method::CONNECT) && status.is_success()
{
false
} else if status.is_informational() {
false
} else {
match status {
// TODO: support for 1xx codes needs improvement everywhere
// would be 100...199 => false
StatusCode::SWITCHING_PROTOCOLS
| StatusCode::NO_CONTENT
| StatusCode::NOT_MODIFIED => false,
StatusCode::NO_CONTENT | StatusCode::NOT_MODIFIED => false,
_ => true,
}
}
Expand Down

0 comments on commit 4323493

Please sign in to comment.