Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1548 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 79be9b2e7d5e369a6bdb6f807d87529434731fb9 1 parent 3cd7755
Adrian Holovaty authored December 05, 2005

Showing 1 changed file with 6 additions and 3 deletions. Show diff stats Hide diff stats

  1. 9  django/middleware/common.py
9  django/middleware/common.py
@@ -30,9 +30,9 @@ def process_request(self, request):
30 30
                     return httpwrappers.HttpResponseForbidden('<h1>Forbidden</h1>')
31 31
 
32 32
         # 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]
34 34
         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.'):
36 36
             new_url[0] = 'www.' + old_url[0]
37 37
         # Append a slash if append_slash is set and the URL doesn't have a
38 38
         # trailing slash or a file extension.
@@ -40,7 +40,10 @@ def process_request(self, request):
40 40
             new_url[1] = new_url[1] + '/'
41 41
         if new_url != old_url:
42 42
             # 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]
44 47
             if request.GET:
45 48
                 newurl += '?' + request.GET.urlencode()
46 49
             return httpwrappers.HttpResponseRedirect(newurl)

0 notes on commit 79be9b2

Please sign in to comment.
Something went wrong with that request. Please try again.