duande9301 2018-10-26 05:23
浏览 202
已采纳

RFC 2616 HTTP内容长度和传输编码兼容性

RFC 2616 states that the Content-Length header must not be sent if a Transfer-Encoding is present.

The Content-Length header field MUST NOT be sent if these two lengths are different (i.e., if a Transfer-Encoding header field is present).

However, if both headers are received, the client should ignore the Content-Length

If a message is received with both a Transfer-Encoding header field and a Content-Length header field, the latter MUST be ignored.

Is my interpretation correct that the client should treat the case where both headers are present as a proper HTTP response? Or is this clause implementation specific?

I'm asking because the Go standard net/http package returns an error when such scenario happens.

  • 写回答

1条回答 默认 最新

  • dsh7623 2018-10-26 05:38
    关注

    The standard does not really specify what should happen in this case, only that if the message is accepted at all then the Content-length should be ignored. To cite from RFC 7230:

    If a message is received with both a Transfer-Encoding and a Content-Length header field, the Transfer-Encoding overrides the Content-Length. Such a message might indicate an attempt to perform request smuggling (Section 9.5) or response splitting (Section 9.4) and ought to be handled as an error.

    Note the weak "ought to" here which is far from MUST. But at least net/http is fully correct in that this kind of response is wrong and can be handled as error. But it is not required to be treated as error.

    In practice all browsers seem to accept such a response and usually ignore the Content-length header. But I've seen als a behavior with MS Edge in the past where it correctly treated the response body as chunked but additionally used Content-length and ignored any bytes from the response body not covered by the Content-length.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端