-
-
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
JSONResponse Wrong Content-Length Value #1282
Comments
Nota BeneWhile the bug still persists, there is a work around for the particular use case which prompted this bug report ... Implement the patch for an empty response class, from pull request #1270, directly in your own backend code. Then return EmptyResponse(headers={'Allow': '<comma separated list of allowed HTTP methods>'}, status_code=204) |
Looks like I have a suggestion why this is happens. When you pass just quotes But most interesting part is — Why it is Let's take a look at the code: Here is rendering of empty JSON Response starlette/starlette/responses.py Lines 156 to 163 in 42592d6
Looks good, but what happens if we try to encode
That's why empty response weights Personally I do not even sure this is a bug. I suggest such behaviour as expected when you deal with JSON. So, |
I have just revised that pull request. I eliminated the EmptyResponse class in favor of handling the special cases in the Response class. The unit tests I wrote also check that JSONResponse does the right thing for 204, 205, and 304 status codes. |
If you want to return an empty response, then return Or even better, once #1397 is in, then return The behaviour we currently have does make sense...
Including an |
Describe the bug
JSONResponse
populates the response header with a non-zeroContent-Length
whenever the response object is instantiated without any content.Checklist
master
.To reproduce
Expected behavior
Actual behavior
Debugging material
All that is needed is the currently stable release of
Starlette
, and the trustyterminal
.Environment
Additional context
I was trying to adhere to the HTTP ref spec when constructing responses to the OPTIONS and HEAD methods.
The text was updated successfully, but these errors were encountered: