From c8505bb53f6d93d4f4091c4a491e4077a5df370d Mon Sep 17 00:00:00 2001 From: Danil Berestov Date: Wed, 3 Oct 2018 00:15:48 +0800 Subject: [PATCH] content-length bug fix (#525) * content-length bug fix * changes.md is updated * typo --- CHANGES.md | 2 ++ src/server/output.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 145caec1..375f2882 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,8 @@ * Websocket server finished() isn't called if client disconnects #511 +* Responses with the following codes: 100, 101, 102, 204 -- are sent without Content-Length header. #521 + ## [0.7.8] - 2018-09-17 diff --git a/src/server/output.rs b/src/server/output.rs index 46b03c9d..70c24fac 100644 --- a/src/server/output.rs +++ b/src/server/output.rs @@ -11,7 +11,7 @@ use flate2::write::{GzEncoder, ZlibEncoder}; #[cfg(feature = "flate2")] use flate2::Compression; use http::header::{ACCEPT_ENCODING, CONTENT_LENGTH}; -use http::Version; +use http::{StatusCode, Version}; use super::message::InnerRequest; use body::{Binary, Body}; @@ -192,7 +192,13 @@ impl Output { let transfer = match resp.body() { Body::Empty => { if !info.head { - info.length = ResponseLength::Zero; + info.length = match resp.status() { + StatusCode::NO_CONTENT + | StatusCode::CONTINUE + | StatusCode::SWITCHING_PROTOCOLS + | StatusCode::PROCESSING => ResponseLength::None, + _ => ResponseLength::Zero, + }; } *self = Output::Empty(buf); return;