Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#17941 closed Bug (invalid)

Value request.META["HTTP_HOST"] was lost

Reported by: Pavel Studeník Owned by: nobody
Component: Core (URLs) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Claude Paroz)

I found problem - I hope, that is a bug. I don't know how, but sometimes (one times from ten) the value request.META["HTTP_HOST"] was lost. It's possible? I trust that this value must exist always.

There is report:

===============================================================

Traceback (most recent call last):

  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 89, in get_response
    response = middleware_method(request)

  File "/var/www/hlplyn_cz/www/./middleware.py", line 18, in process_request
    if not request.META["HTTP_HOST"] in ("www.<doamin>","localhost:8000",):

KeyError: 'HTTP_HOST'


<WSGIRequest
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{'DOCUMENT_ROOT': '<path>/',
 'GATEWAY_INTERFACE': 'CGI/1.1',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0.1) Gecko/20100101 Firefox/8.0.1',
 'PATH_INFO': u'/',
 'PATH_TRANSLATED': '<path>/.run.wsgi/',
 'QUERY_STRING': '',
 'REMOTE_ADDR': '85.17.213.242',
 'REMOTE_PORT': '55876',
 'REQUEST_METHOD': 'GET',
 'REQUEST_URI': 'http://www.DOMENA.NET/',
 'SCRIPT_FILENAME': '<path>/.run.wsgi',
 'SCRIPT_NAME': u'',
 'SERVER_ADDR': '<ip>',
 'SERVER_ADMIN': '[no address given]',
 'SERVER_NAME': '<domain>',
 'SERVER_PORT': '80',
 'SERVER_PROTOCOL': 'HTTP/1.0',
 'SERVER_SIGNATURE': '<address>Apache/2.2.16 (Debian) Server at <domain> Port 80</address>\n',
 'SERVER_SOFTWARE': 'Apache/2.2.16 (Debian)',
 'mod_wsgi.application_group': '<domain>|',
 'mod_wsgi.callable_object': 'application',
 'mod_wsgi.handler_script': '',
 'mod_wsgi.input_chunked': '0',
 'mod_wsgi.listener_host': '',
 'mod_wsgi.listener_port': '80',
 'mod_wsgi.process_group': 'wsgi_<domain>',
 'mod_wsgi.request_handler': 'wsgi-script',
 'mod_wsgi.script_reloading': '1',
 'mod_wsgi.version': (3, 3),
 'wsgi.errors': <mod_wsgi.Log object at 0x7f84a37809b0>,
 'wsgi.file_wrapper': <built-in method file_wrapper of mod_wsgi.Adapter object at 0x7f84a311eeb8>,
 'wsgi.input': <mod_wsgi.Input object at 0x7f84a3780970>,
 'wsgi.multiprocess': True,
 'wsgi.multithread': True,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 1)}>

Change History (2)

comment:1 by Claude Paroz, 13 years ago

Description: modified (diff)
Resolution: invalid
Status: newclosed

The Host header is mandatory in HTTP 1.1 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23), however it might happen that older user agents still use the 1.0 protocol with no Host. You can either choose to return an error (400) if you don't want to support those, or use request.META.get('HTTP_HOST') and handle the None value. Django itself is not responsible to guarantee that HTTP_HOST will be filled in all requests.

Note: See TracTickets for help on using tickets.
Back to Top