Skip to content

Commit

Permalink
Allow specifying SSL port
Browse files Browse the repository at this point in the history
  • Loading branch information
cancan101 committed Nov 19, 2014
1 parent 2cee4fb commit f898602
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sslify/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf import settings
from django.http import HttpResponsePermanentRedirect
import urlparse


class SSLifyMiddleware(object):
Expand All @@ -21,5 +22,9 @@ def process_request(self, request):
# If we get here, proceed as normal.
if not request.is_secure():
url = request.build_absolute_uri(request.get_full_path())
secure_url = url.replace('http://', 'https://')
url_split = urlparse.urlsplit(url)
schema = 'https' if url_split[0] == 'http' else url_split[0]
ssl_port = getattr(settings, 'SSL_PORT', 443)
url_secure_split = (schema, "%s:%d" % (url_split.hostname or '', ssl_port)) + urlparse.urlsplit(url)[2:]
secure_url = urlparse.urlunsplit(url_secure_split)
return HttpResponsePermanentRedirect(secure_url)

0 comments on commit f898602

Please sign in to comment.