"body not consumed" error on GET request with content-length=0
Ivan-Roger opened this issue · comments
The default http check from HAProxy v2.4.22 performs a request that looks like this :
GET /health HTTP/1.0
content-length: 0
When presented with such a request sanic logs an error in the form of : [sanic.error] <Request: GET /health> body not consumed.
The issue here is with the content-length
header being sent for a GET
request that should not contain a payload.
Even though the value is 0
Sanic seems to believe the request has a payload.
The RFCs are not clear as to whether it is actually allowed or forbidden to send this header for GET
requests :
- https://groups.google.com/g/comp.protocols.tcp-ip/c/nFGtq4EywLc?hl=en#a701d2edcd9c089b
- https://lists.w3.org/Archives/Public/ietf-http-wg/2006AprJun/0103.html
- https://www.rfc-editor.org/rfc/rfc9110#field.content-length
Nevertheless I believe that in this specific case (A Content-Length
header with a value of 0
for a request that isn't expecting a payload) the error could be silently ignored (do not log the body not consumed
message)
The haproxy issue has since been adressed (haproxy/haproxy#2026)
Originally posted in #2685 (comment)
Hmm, I am not sure I agree that it is Sanic's responsibility for ignoring that.
A user agent SHOULD NOT send a Content-Length header field when the request message does not contain content and the method semantics do not anticipate such data.
A client SHOULD NOT generate content in a GET request unless it is made directly to an origin server that has previously indicated, in or out of band, that such a request has a purpose and will be adequately supported.
This can be ignored on Sanic's side by allowing it to consume the body.