#17941: Value request.META["HTTP_HOST"] was lost
-----------------------------+--------------------------------------
Reporter: Pajinek | Owner: nobody
Type: Bug | Status: closed
Component: Core (URLs) | Version: 1.3
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by claudep):
* status: new => closed
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* resolution: => invalid
Old description:
> 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)}>
New description:
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)}>
}}}
--
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/17941#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.