[QUESTION] How to send 204 response?
See original GitHub issueI tried to send 204 response in delete method
Example handler
@router.delete('/{order_id}/', tags=['smart order'], status_code=204)
async def cancel_smart_order(
session: Session = Depends(get_session),
order_id: UUID = Path(...)
):
order = await session.get(order_id)
if order.status != OrderStatus.open:
raise HTTPException(409, f'Order have status: {order.status}')
order.status = OrderStatus.canceled
await session.commit_only(order)
But got error h11._util.LocalProtocolError: Too much data for declared Content-Length
. Seems framefork convert None to null but set content length 0.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:27 (12 by maintainers)
Top Results From Across the Web
204 No Content - HTTP - MDN Web Docs - Mozilla
The HTTP 204 No Content success status response code indicates that a request has succeeded, but that the client doesn't need to navigate ......
Read more >Lumen does send 204 response - php - Stack Overflow
You should do: return response('', 204);.
Read more >HTTP Status 204 (No Content) - REST
The 204 response MUST NOT include a message-body and thus is always terminated by the first empty line after the header fields. 1....
Read more >REST Receiver HTTP 204 response code - SAP Community
I am working on a REST scneario, where data have to be sent asynchronously to a REST service, using POST operation. In success...
Read more >Azure usage api getting 204 response code and no content
Microsoft Q&A is the best place to get answers to all your technical questions on Microsoft products and services. Community. Forum.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Instead of returning
None
, and instead of injecting the response, just return a newly created response. It would look like:The reason you are getting content is because FastAPI uses a
JSONResponse
by default (instead of aResponse
), which converts the returned valueNone
to"null"
. By returning aResponse
directly, you prevent FastAPI from using theJSONResponse
and encoding theNone
.This is a bug: FastAPI is not conforming to the HTTP RFC: https://tools.ietf.org/html/rfc2616#section-10.2.5
FastAPI should made it difficult to produce an invalid HTTP response, not allowing to create a valid one with a workaround.