MUST NOT send Content-Length/Transfer-Encoding for 1xx or 204 #4901
Closed
Description
🐞 Describe the bug
According to RFC7230 (https://tools.ietf.org/html/rfc7230#section-3.3.2 and https://tools.ietf.org/html/rfc7230#section-3.3.1) a server must not send neither the Content-Length nor the Transfer-Encoding header field for 1xx and 204 responses.
Note that in practice clients and proxies might get into trouble when receiving such a response. E.g. with a nginx reverse proxy this behaviour leads to the following error: upstream prematurely closed connection ...
💡 To Reproduce
Exemplary for web.Response:
from aiohttp import web
async def reproduce(request):
return web.Response(status=204)
app = web.Application()
app.add_routes([web.get('/', reproduce)])
web.run_app(app, host='localhost', port=8080)$ curl -v -o - "http://localhost:8080/"
* Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 204 No Content
< Content-Length: 0
< Content-Type: application/octet-stream
< Date: Fri, 07 Aug 2020 16:16:33 GMT
< Server: Python/3.8 aiohttp/4.0.0a1
<
* Connection #0 to host localhost left intact💡 Expected behavior
Do not ship the headers mentioned above.
📋 Your version of the Python
$ python --version
Python 3.8.2📋 Your version of the aiohttp/yarl/multidict distributions
pip freeze | grep aiohttp
-e git+https://github.com/aio-libs/aiohttp.git@1d296d549050aa335ef542421b8b7dad788246d5#egg=aiohttpThe aiohttp version should agree with the current master.
$ python -m pip show multidict
Name: multidict
Version: 4.7.6
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /home/ubuntu/work/projects/aiohttp-reproducer/venv/lib/python3.8/site-packages
Requires:
Required-by: yarl, aiohttp$ python -m pip show yarl
Name: yarl
Version: 1.4.2
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /home/ubuntu/work/projects/aiohttp-reproducer/venv/lib/python3.8/site-packages
Requires: idna, multidict
Required-by: aiohttp