-
-
Notifications
You must be signed in to change notification settings - Fork 953
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
Add EmptyResponse class #1178
Comments
Initially I wasn't sure about this, but I'm warming up to the idea of an explicit
|
Here are links to the relevant RFCs. 1xx: https://datatracker.ietf.org/doc/html/rfc7231#section-6.2 I would also be willing to take a crack at implementing an EmptyResponse class. |
Closing in favour of #1397 |
HTTP responses with status codes 1xx, 204, 205, and 304 are special cases. 1xx, 204, 304 responses must not include a message body. The empty message body for 205 responses can be handled in a few ways, but the only one that would make sense for Starlette would be to add a Content-Length header with value 0.
Currently it is not at all obvious to users how to implement these responses. Starlette can make it explicit with the addition of an EmptyResponse class that does the right thing for each of the status codes cited above.
The "right thing" differs by status code. The key difference is
Thus, an EmptyResponse object should ensure no Content-Length header in the first case, ensure Content-Length: 0 in the second case, and pass along a Content-Length header if supplied in the third case; here it is the caller's responsibility to get the value right.
In all cases, an EmptyResponse object would send an 'http.response.body' event with body: b'', more_body: False so that the ASGI server knows to begin sending the response.
The addition of an EmptyResponse class should resolve at least one open issue (#1099).
The text was updated successfully, but these errors were encountered: