4

I'm writing a demo proxy server with Django 1.6 and Python 3.4. I get an error when the response has this header:

Transfer-Encoding=chunked

The error is:

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

I find out this question: Allow hop-by-hop headers in Django proxy middleware but seem like Django 1.6 don't have basehttp._hop_headers.

I run server with python3.4 manage.py runserver.

Please help

Community
  • 1
  • 1
Tuan Chau
  • 1,243
  • 1
  • 16
  • 30
  • 1
    _"a demo proxy server with django"_? Why are you writing a proxy server in django? It would be better to use Python and something like [werkzeug](http://werkzeug.pocoo.org/docs/0.9/http/#header-utilities). – Burhan Khalid Oct 18 '14 at 13:47
  • 1
    Similar issue here with Django 1.6 and Python 2.7. I suspect it's how manage.py works. Another member of my team was able to set the transfer-encoding header running under uWSGI, and it ran without error. – Joel B May 05 '15 at 22:24
  • `_hop_headers` are now in [`wsgiref.util`](https://stackoverflow.com/a/57113570/52499). – x-yuri Jul 19 '19 at 13:32

1 Answers1

9

The following HTTP/1.1 headers are hop-by-hop headers that wsgiref does not allowed:

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

See:

  1. Hypertext Transfer Protocol -- HTTP/1.1
  2. The code of wsgiref: util.py, handlers.py

Vex
  • 1,489
  • 13
  • 20
rossini
  • 751
  • 4
  • 6