Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do if HTTP Content-Length differs from actual body size?

If a HTTP server sends a reply with a Content-Length header and a message-body that is slightly larger than that length, what is the accepted way to handle this mismatch? Should I silently ignore the extra data? I don't see this specified in the HTTP/1.1 RFC, it just says that it should always match. Just seems like there could be some buggy servers out there that don't get this right.

Thanks.

like image 379
Darren S Avatar asked Nov 29 '11 16:11

Darren S


1 Answers

The length is defined by the Content-Length header field (or Chunked Encoding, or closing the connection).

If the length doesn't "match" this means that the extra bytes belong to the next message. If these extra bytes do not represent an additional HTTP message, that's a communications error. Just close the connection and report an error.

(see https://greenbytes.de/tech/webdav/rfc7230.html#message.body.length)

like image 117
Julian Reschke Avatar answered Sep 18 '22 19:09

Julian Reschke