1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

magic-removal: Added support for HTTP_X_FORWARDED_HOST in all

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
This commit is contained in:
Luke Plant 2006-03-30 23:03:19 +00:00
parent 835dc7e863
commit 8102d1262e
3 changed files with 12 additions and 4 deletions

View File

@ -5,7 +5,7 @@ from django.contrib.admin.views.decorators import staff_member_required
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
@ -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)

View File

@ -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

View File

@ -30,7 +30,8 @@ class CommonMiddleware:
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]
@ -56,7 +57,7 @@ class CommonMiddleware:
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()