What to do if HTTP Content-Length differs from act

2019-06-17 14:49发布

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.

1条回答
祖国的老花朵
2楼-- · 2019-06-17 15:30

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)

查看更多
登录 后发表回答