From 4323493e1b2f631cf2841f0a72d16bf93e4f0497 Mon Sep 17 00:00:00 2001 From: Peter Smit Date: Wed, 3 Jun 2020 11:54:41 +0200 Subject: [PATCH] fix(server): skip automatic Content-Length headers when not allowed Closes #2215 --- src/proto/h1/role.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index 46b8b2646e..606d995bdb 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -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: "); @@ -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, } }