summaryrefslogtreecommitdiff
path: root/django/middleware/common.py
diff options
context:
space:
mode:
authorieatkittens <samuelm@gadventures.com>2016-03-18 15:21:41 -0400
committerTim Graham <timograham@gmail.com>2016-03-23 09:23:19 -0400
commit9390da7fb6e251eaa9a785692f987296cb14523f (patch)
treec854cd349137d22fe7d66a8c8cf9ee813c5b3eab /django/middleware/common.py
parent107165c4b04f4e5a830a60b6c66b2e5d8fb1d242 (diff)
Fixed #26293 -- Fixed CommonMiddleware to process PREPEND_WWW and APPEND_SLASH independently.
Diffstat (limited to 'django/middleware/common.py')
-rw-r--r--django/middleware/common.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/django/middleware/common.py b/django/middleware/common.py
index 70d8c57f7e..2135702062 100644
--- a/django/middleware/common.py
+++ b/django/middleware/common.py
@@ -54,18 +54,19 @@ class CommonMiddleware(object):
# Check for a redirect based on settings.PREPEND_WWW
host = request.get_host()
+ must_prepend = settings.PREPEND_WWW and host and not host.startswith('www.')
+ redirect_url = ('%s://www.%s' % (request.scheme, host)) if must_prepend else ''
- if settings.PREPEND_WWW and host and not host.startswith('www.'):
- host = 'www.' + host
-
- # Check if we also need to append a slash so we can do it all
- # with a single redirect.
- if self.should_redirect_with_slash(request):
- path = self.get_full_path_with_slash(request)
- else:
- path = request.get_full_path()
+ # Check if a slash should be appended
+ if self.should_redirect_with_slash(request):
+ path = self.get_full_path_with_slash(request)
+ else:
+ path = request.get_full_path()
- return self.response_redirect_class('%s://%s%s' % (request.scheme, host, path))
+ # Return a redirect if necessary
+ if redirect_url or path != request.get_full_path():
+ redirect_url += path
+ return self.response_redirect_class(redirect_url)
def should_redirect_with_slash(self, request):
"""