Skip to content

Commit

Permalink
magic-removal: Added support for HTTP_X_FORWARDED_HOST in all
Browse files Browse the repository at this point in the history
places where HTTP_HOST is used, for support of virtual hosting
situations.


git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2601 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
spookylukey committed Mar 30, 2006
1 parent 835dc7e commit 8102d12
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions django/contrib/admin/views/doc.py
Expand Up @@ -5,7 +5,7 @@
from django.db import models
from django.shortcuts import render_to_response
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
from django.http import Http404
from django.http import Http404, get_host
from django.core import urlresolvers
from django.contrib.admin import utils
from django.contrib.sites.models import Site
Expand All @@ -24,7 +24,7 @@ def bookmarklets(request):
# Hack! This couples this view to the URL it lives at.
admin_root = request.path[:-len('doc/bookmarklets/')]
return render_to_response('admin_doc/bookmarklets', {
'admin_url': "%s://%s%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', request.META['HTTP_HOST'], admin_root),
'admin_url': "%s://%s%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', get_host(request), admin_root),
}, context_instance=RequestContext(request))
bookmarklets = staff_member_required(bookmarklets)

Expand Down
7 changes: 7 additions & 0 deletions django/http/__init__.py
Expand Up @@ -252,3 +252,10 @@ class HttpResponseServerError(HttpResponse):
def __init__(self, *args, **kwargs):
HttpResponse.__init__(self, *args, **kwargs)
self.status_code = 500

def get_host(request):
"""Gets the HTTP host from the environment or request headers."""
host = request.META.get('HTTP_X_FORWARDED_HOST', '')
if not host:
host = request.META.get('HTTP_HOST', '')
return host
5 changes: 3 additions & 2 deletions django/middleware/common.py
Expand Up @@ -30,7 +30,8 @@ def process_request(self, request):
return http.HttpResponseForbidden('<h1>Forbidden</h1>')

# Check for a redirect based on settings.APPEND_SLASH and settings.PREPEND_WWW
old_url = [request.META.get('HTTP_HOST', ''), request.path]
host = http.get_host(request)
old_url = [host, request.path]
new_url = old_url[:]
if settings.PREPEND_WWW and old_url[0] and not old_url[0].startswith('www.'):
new_url[0] = 'www.' + old_url[0]
Expand All @@ -56,7 +57,7 @@ def process_response(self, request, response):
if settings.SEND_BROKEN_LINK_EMAILS:
# If the referrer was from an internal link or a non-search-engine site,
# send a note to the managers.
domain = request.META['HTTP_HOST']
domain = http.get_host(request)
referer = request.META.get('HTTP_REFERER', None)
is_internal = referer and (domain in referer)
path = request.get_full_path()
Expand Down

0 comments on commit 8102d12

Please sign in to comment.