Django

Code

Changeset 1548

Show
Ignore:
Timestamp:
12/05/05 09:25:55 (3 years ago)
Author:
adrian
Message:

Changed CommonMiddleware? so it doesn't assume HTTP_HOST is set.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/middleware/common.py

    r1166 r1548  
    3131 
    3232        # Check for a redirect based on settings.APPEND_SLASH and settings.PREPEND_WWW 
    33         old_url = [request.META['HTTP_HOST'], request.path] 
     33        old_url = [request.META.get('HTTP_HOST', ''), request.path] 
    3434        new_url = old_url[:] 
    35         if settings.PREPEND_WWW and not old_url[0].startswith('www.'): 
     35        if settings.PREPEND_WWW and old_url[0] and not old_url[0].startswith('www.'): 
    3636            new_url[0] = 'www.' + old_url[0] 
    3737        # Append a slash if append_slash is set and the URL doesn't have a 
     
    4141        if new_url != old_url: 
    4242            # Redirect 
    43             newurl = "%s://%s%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', new_url[0], new_url[1]) 
     43            if new_url[0]: 
     44                newurl = "%s://%s%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', new_url[0], new_url[1]) 
     45            else: 
     46                newurl = new_url[1] 
    4447            if request.GET: 
    4548                newurl += '?' + request.GET.urlencode()