如果HTTP Content-Length与实际体型不同,该怎么办? [英] What to do if HTTP Content-Length differs from actual body size?

查看:1283
本文介绍了如果HTTP Content-Length与实际体型不同,该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果HTTP服务器发送带有Content-Length标头和稍大于该长度的消息体的回复,那么处理这种不匹配的方法是什么?我应该默默地忽略额外的数据吗?我没有在HTTP / 1.1 RFC中看到这个,它只是说应该始终匹配。看起来可能有一些错误的服务器没有做到这一点。

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.

谢谢。

推荐答案

长度由Content-Length标头字段(或Chunked Encoding,或关闭连接)定义。

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

如果length不匹配这意味着额外的字节属于下一条消息。如果这些额外的字节不代表额外的HTTP消息,那就是通信错误。只需关闭连接并报告错误。

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.

(参见 https://greenbytes.de/tech/webdav/rfc7230.html#message.body.length

这篇关于如果HTTP Content-Length与实际体型不同,该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆