【问题标题】:Who set the Transfer-Encoding: chunked header?谁设置了 Transfer-Encoding: chunked header?
【发布时间】:2018-09-12 06:39:19
【问题描述】:

我正在使用 Django、mod_wsgi 和 Apache。 当我作为 StreamingHttpResponse 做出响应并返回时,在响应中设置了 Transfer-Encoding: chunked header。 但是当我将 Content-Length 标头添加到 resposne 时,Transfer-Encoding 标头被删除,并且只存在 Content-Length 标头。

谁设置和删除了 Transfer-Encoding 标头?

【问题讨论】:

    标签: django apache http mod-wsgi


    【解决方案1】:

    当您未指定内容长度时,Apache 将设置Transfer-Encoding: chunked。您不应该尝试自己设置该标题。 WSGI 规范实际上禁止您 (https://www.python.org/dev/peps/pep-3333/#id34) 设置,因为它是逐跳标头。

    设置内容长度后,HTTP 不需要使用分块响应编码。

    【讨论】:

    • 你说如果 Content-Length 标头不存在,Apache 设置 Transfer-Encoding: chunked 标头。如果我设置 Content-Length 标头,Apache 将不会设置 Transfer-Encoding。我不能在我的应用程序中设置 Transfer-Encoding 标头。我说的对吗?
    • 正确,永远不要自己设置Transfer-Encoding,这不是你的工作。这取决于使用的底层 Web 服务器,因为您无法控制响应中的实际分块。
    猜你喜欢
    • 1970-01-01
    • 2021-08-18
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 1970-01-01
    相关资源
    最近更新 更多