【问题标题】:Allow hop-by-hop header Django允许逐跳标头 Django
【发布时间】:2014-11-20 13:21:00
【问题描述】:

我正在用 Django 1.6 和 Python 3.4 编写一个演示代理服务器。当响应包含此标头时出现错误:

Transfer-Encoding=chunked

错误是:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 214, in __call__
    start_response(force_str(status), response_headers)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wsgiref/handlers.py", line 236, in start_response
    assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed"
AssertionError: Hop-by-hop headers not allowed

我发现了这个问题:Allow hop-by-hop headers in Django proxy middleware 但似乎 Django 1.6 没有 basehttp._hop_headers

我使用python3.4 manage.py runserver 运行服务器。

请帮忙

【问题讨论】:

  • “一个带有 django 的演示代理服务器”?为什么要在 django 中编写代理服务器?最好使用 Python 之类的 werkzeug
  • 这里有 Django 1.6 和 Python 2.7 的类似问题。我怀疑这就是 manage.py 的工作方式。我团队的另一位成员能够设置在 uWSGI 下运行的传输编码标头,并且运行没有错误。
  • _hop_headers 现在在wsgiref.util

标签: python django wsgi chunked


【解决方案1】:

以下 HTTP/1.1 标头是 wsgiref 不允许的逐跳标头:

  - Connection
  - Keep-Alive
  - Proxy-Authenticate
  - Proxy-Authorization
  - TE
  - Trailers
  - Transfer-Encoding
  - Upgrade

见:

  1. Hypertext Transfer Protocol -- HTTP/1.1
  2. wsgiref的代码:util.py,handlers.py

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-25
    • 2019-07-09
    • 2021-11-27
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 2019-10-27
    相关资源
    最近更新 更多