From 6fb5c7cb9b5bfe9569d2c44c07552785630d708d Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 7 Dec 2016 20:38:52 +0200 Subject: [PATCH] Fix #1400 --- aiohttp/web_reqrep.py | 2 ++ tests/test_web_response.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/aiohttp/web_reqrep.py b/aiohttp/web_reqrep.py index a05889d36da..4e161eeb942 100644 --- a/aiohttp/web_reqrep.py +++ b/aiohttp/web_reqrep.py @@ -950,6 +950,8 @@ def __init__(self, *, body=None, status=200, super().__init__(status=status, reason=reason, headers=headers) if text is not None: self.text = text + elif body is None and hdrs.CONTENT_LENGTH in headers: + self._body = None else: self.body = body diff --git a/tests/test_web_response.py b/tests/test_web_response.py index ed766a3a278..5bdf270dd68 100644 --- a/tests/test_web_response.py +++ b/tests/test_web_response.py @@ -948,6 +948,11 @@ def test_text_with_empty_payload(): assert resp.text is None +def test_response_with_content_length_header_without_body(): + resp = Response(headers={'Content-Length': 123}) + assert resp.content_length == 123 + + class TestJSONResponse: def test_content_type_is_application_json_by_default(self):