google-code-export / django-page-cms

Automatically exported from code.google.com/p/django-page-cms
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Pages raises KeyError when requesting 'HTTP_HOST' for use in custom apps #137

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use middleware dependant on 'HTTP_HOST'
2. For example: http://www.djangosnippets.org/snippets/1119/
3. Access admin pages - Key error 'HTTP_HOST' raised

What is the expected output? What do you see instead?
Error raised by: 

domain = request.META['HTTP_HOST']

In below code, as middleware, called in settings.py middleware as custom.

Effectively doesn't recieve 'HTTP_HOST' from the server. Seems to be
triggered in particular by cache pages_tags. Don't have the experience to
be able to debug beyond this point.

What version of the product are you using? On what operating system?
Latest trunk, on Apache2, Python 2.5

Please provide any additional information below.

Here's the middleware code:
    def process_request(self, request):
        domain_parts = request.get_host().split('.')
        if (len(domain_parts) > 2):
            subdomain = domain_parts[0]
            if (subdomain.lower() == 'www'):
                subdomain = ''
            domain = '.'.join(domain_parts[1:])
        else:
            subdomain = ''
            domain = request.META['HTTP_HOST']

        request.subdomain = subdomain
        request.domain = domain

Original issue reported on code.google.com by christop...@gmail.com on 5 Aug 2009 at 1:46

GoogleCodeExporter commented 9 years ago
Can you provide a full stack trace of this bug?

Original comment by batiste....@gmail.com on 13 Aug 2009 at 5:01

GoogleCodeExporter commented 9 years ago
Here is a patch that could maybe solve your problem. Can you test it and report 
if it
works for you?

Original comment by batiste....@gmail.com on 13 Aug 2009 at 5:50

Attachments:

GoogleCodeExporter commented 9 years ago
That's fixed it batiste, yes it's the undefined HTTP HOST that's the issue. I 
can see
it was reported int he snippet also, but ther updated code wasn't applied 
correctly.

Thanks for picking that up.

Original comment by christop...@gmail.com on 20 Aug 2009 at 12:42

GoogleCodeExporter commented 9 years ago

Original comment by batiste....@gmail.com on 25 Aug 2009 at 6:58