-
-
Save daemondev/aa307eab097d44a417a3fcc0bc386516 to your computer and use it in GitHub Desktop.
Revisions
-
devries revised this gist
Jul 28, 2015 . No changes.There are no files selected for viewing
-
devries created this gist
Jul 28, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ from urllib import quote class SSLRedirect(object): def __init__(self,app): self.app=app def __call__(self,environ,start_response): proto = environ.get('HTTP_X_FORWARDED_PROTO') or environ.get('wsgi.url_scheme', 'http') if proto=='https': return self.app(environ,start_response) else: url = 'https://' if environ.get('HTTP_HOST'): url += environ['HTTP_HOST'] else: url += environ['SERVER_NAME'] url += quote(environ.get('SCRIPT_NAME', '')) url += quote(environ.get('PATH_INFO', '')) if environ.get('QUERY_STRING'): url += '?' + environ['QUERY_STRING'] status = "301 Moved Permanently" headers = [('Location',url),('Content-Length','0')] start_response(status,headers) return ['']