sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"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 :

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.

source

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.

source

This can be ignored on Sanic's side by allowing it to consume the body.

https://sanic.dev/en/guide/basics/routing.md#http-methods

image