-
Notifications
You must be signed in to change notification settings - Fork 218
Require server to handle Content-Length
headers when receive
ing HTTP requests
#510
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
base: main
Are you sure you want to change the base?
Conversation
Why apps don't just use more_body
Note that If a client sends more data than the |
Can you explain how that relates to the scenarios I'm describing? If a client say it's sending a request with a
That sounds like something the server should deal with, as the application does not have enough context knowledge. The behaviour described above is fairly standard webserver behaviour, in that they usually do not read beyond the announced |
If the app calls
What server implementation does that? That should be considered a bug. |
Let me rephrase: A server could read beyond the declared content length and serve it to the app, and would not be in violation of the spec, since the behaviour you're describing, while commonly understood to be standard server behaviour, is not codified. As a result, an application cannot rely on this behaviour, or at least should not, as I'd argue all behaviour not defined in the spec should be assumed implementation specific :) |
This can break Quart, because it calls receive() until the scope ends. Then I think it just needs to be emphasized that |
Add a clause in the spec that:
Content-Length
400 - Bad Request
if the actual length exceeds the announced lengthMotivation
Compatibility with the WSGI spec
As ASGI is a self-described "superset of the WSGI format", it should honour WSGIs stipulation around handling
Content-Length
. PEP 3333 says:The proposed addition would make ASGI compliant with the WSGI specification in this regard, and adding some additional guarantees by changing the server behaviour from should to must.
Confidence for downstream consumers
Currently, ASGI applications can not assume that the
Content-Length
header reflects the actual content length returned by successive calls toreceive()
. This means they can only use theContent-Length
header as a hint if present, but would need to check its consistency themselves if they want to rely on it.Compare this PR where such a feature is discussed: https://github.com/encode/starlette/pull/2328/files#r1397168621