Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MUST NOT send Content-Length/Transfer-Encoding for 1xx or 204 #4901

Closed
damb opened this issue Aug 7, 2020 · 2 comments · Fixed by #5119
Closed

MUST NOT send Content-Length/Transfer-Encoding for 1xx or 204 #4901

damb opened this issue Aug 7, 2020 · 2 comments · Fixed by #5119
Labels
bug reproducer: present This PR or issue contains code, which reproduce the problem described or clearly understandable STR

Comments

@damb
Copy link

damb commented Aug 7, 2020

🐞 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=aiohttp

The 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
@damb damb added the bug label Aug 7, 2020
@damb damb changed the title MUST NOT send Transfer-Encoding for 1xx or 204 MUST NOT send Content-Length/Transfer-Encoding for 1xx or 204 Aug 7, 2020
@borysvorona borysvorona added the reproducer: present This PR or issue contains code, which reproduce the problem described or clearly understandable STR label Aug 12, 2020
@borysvorona
Copy link
Member

This is partially similar to #4612.

derlih added a commit to derlih/aiohttp that referenced this issue Oct 24, 2020
@damb
Copy link
Author

damb commented Oct 26, 2020

@derlih, thanks for fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug reproducer: present This PR or issue contains code, which reproduce the problem described or clearly understandable STR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants