From 63045d19285baee65124f88ffaf0f991d3300541 Mon Sep 17 00:00:00 2001 From: Nick Daly Date: Sat, 5 Oct 2013 14:36:07 -0500 Subject: [PATCH] Redirect all requests to HTTPS. --- plinth.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plinth.py b/plinth.py index e2bd80818..d36c5dc4e 100755 --- a/plinth.py +++ b/plinth.py @@ -29,6 +29,19 @@ __maintainer__ = "James Vasile" __email__ = "james@jamesvasile.com" __status__ = "Development" + +import urlparse + +def make_secure(header="Secure"): + secure = cherrypy.request.headers.get(header, False) + if not secure: + url = urlparse.urlparse(cherrypy.url()) + secure_url = urlparse.urlunsplit(('https', url[1], url[2], + url[3], url[4])) + raise cherrypy.HTTPRedirect(secure_url) + +cherrypy.tools.secure = cherrypy.Tool('before_handler', make_secure) + def error_page(status, dynamic_msg, stock_msg): return u.page_template(template="err", title=status, main="

%s

%s" % (dynamic_msg, stock_msg))