From 129df4861c8824f6d572ac99054307b8d56773b2 Mon Sep 17 00:00:00 2001 From: Dmitry Erlikh Date: Sat, 24 Oct 2020 18:14:54 +0200 Subject: [PATCH] fix #4901 --- CHANGES/4901.bugfix | 1 + aiohttp/web_response.py | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 CHANGES/4901.bugfix diff --git a/CHANGES/4901.bugfix b/CHANGES/4901.bugfix new file mode 100644 index 00000000000..910bdd76685 --- /dev/null +++ b/CHANGES/4901.bugfix @@ -0,0 +1 @@ +Server doesn't send Content-Length for 1xx or 204 diff --git a/aiohttp/web_response.py b/aiohttp/web_response.py index d6f0d0f0850..c1cdc6cb46b 100644 --- a/aiohttp/web_response.py +++ b/aiohttp/web_response.py @@ -426,6 +426,10 @@ async def _prepare_headers(self) -> None: del headers[hdrs.CONTENT_LENGTH] else: keep_alive = False + # HTTP 1.1: https://tools.ietf.org/html/rfc7230#section-3.3.2 + # HTTP 1.0: https://tools.ietf.org/html/rfc1945#section-10.4 + elif version >= HttpVersion11 and self.status in (100, 101, 102, 103, 204): + del headers[hdrs.CONTENT_LENGTH] headers.setdefault(hdrs.CONTENT_TYPE, "application/octet-stream") headers.setdefault(hdrs.DATE, rfc822_formatted_time())