From 661853b95deaa1d0d7288612f24065b73337dd25 Mon Sep 17 00:00:00 2001 From: Koga Kazuo Date: Sat, 11 Apr 2020 00:38:00 +0900 Subject: [PATCH] Check status code that has no response body --- src/response.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/response.rs b/src/response.rs index 8db8fcb..0a6ede7 100644 --- a/src/response.rs +++ b/src/response.rs @@ -280,17 +280,22 @@ impl Response { .unwrap_or(false); let is_head = (&self.unit).as_ref().map(|u| u.is_head()).unwrap_or(false); + let has_no_body = is_head + || match self.status { + 204 | 304 => true, + _ => false, + }; let is_chunked = self .header("transfer-encoding") .map(|enc| !enc.is_empty()) // whatever it says, do chunked .unwrap_or(false); - let use_chunked = !is_http10 && !is_head && is_chunked; + let use_chunked = !is_http10 && !has_no_body && is_chunked; let limit_bytes = if is_http10 || is_close { None - } else if is_head { + } else if has_no_body { // head requests never have a body Some(0) } else {