diff --git a/VERSION b/VERSION index 1fa01c0d..c3cbd4cc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 1.99.3 (2011-12-09 20:38:05) stable +Version 1.99.3 (2011-12-09 20:46:02) stable diff --git a/applications/welcome/models/db.py b/applications/welcome/models/db.py index 2dd75224..533ea8e6 100644 --- a/applications/welcome/models/db.py +++ b/applications/welcome/models/db.py @@ -5,6 +5,10 @@ ## File is released under public domain and you can use without limitations ######################################################################### +## if SSL/HTTPS is properly configured and you want all HTTP requests to +## be redirected to HTTPS, uncomment the line below: +# request.requires_https() + if not request.env.web2py_runtime_gae: ## if NOT running on Google App Engine use SQLite or other DB db = DAL('sqlite://storage.sqlite') diff --git a/gluon/globals.py b/gluon/globals.py index a973632b..63b3bc1c 100644 --- a/gluon/globals.py +++ b/gluon/globals.py @@ -18,8 +18,8 @@ from storage import Storage, List from streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE from xmlrpc import handler from contenttype import contenttype -from html import xmlescape, TABLE, TR, PRE -from http import HTTP +from html import xmlescape, TABLE, TR, PRE, URL +from http import HTTP, redirect from fileutils import up from serializers import json, custom_json import settings @@ -109,6 +109,16 @@ class Request(Storage): for key,value in user_agent.items(): if isinstance(value,dict): user_agent[key] = Storage(value) return user_agent + + def requires_https(self): + """ + If request comes in over HTTP, redirect it to HTTPS + and secure the session. + """ + if not global_settings.cronjob and not self.is_https: + redirect(URL(scheme='https', args=self.args, vars=self.vars)) + + current.session.secure() def restful(self): def wrapper(action,self=self):