From 0ab64e9803fbf2f82caa1c8e10115d4add376fbb Mon Sep 17 00:00:00 2001 From: Arnulfo Solis Date: Fri, 2 Feb 2018 09:29:54 +0100 Subject: [PATCH] simplified logic when handling the body --- sanic/response.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sanic/response.py b/sanic/response.py index 7a490ffe..01d0843d 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -196,11 +196,13 @@ class HTTPResponse(BaseHTTPResponse): if keep_alive and keep_alive_timeout is not None: timeout_header = b'Keep-Alive: %d\r\n' % keep_alive_timeout + body = b'' content_length = 0 if self.status is not 204: + body = self.body content_length = self.headers.get('Content-Length', len(self.body)) - self.headers['Content-Length'] = content_length + self.headers['Content-Length'] = content_length self.headers['Content-Type'] = self.headers.get( 'Content-Type', self.content_type) @@ -222,7 +224,7 @@ class HTTPResponse(BaseHTTPResponse): b'keep-alive' if keep_alive else b'close', timeout_header, headers, - self.body if self.status is not 204 else b'' + body ) @property