aboutsummaryrefslogtreecommitdiff
path: root/budget/utils.py
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2015-11-09 09:26:11 +0100
committerAlexis Metaireau <alexis@notmyidea.org>2015-11-09 09:26:11 +0100
commita8841f9d3f90ec4c1915493a1b34fa1798895772 (patch)
tree665a03e1f5e6b186980a9de8c8abf13b76031135 /budget/utils.py
parenteff0f7c2df4cdbde11f91ca7413af89c3a0606c9 (diff)
parent15091e28c070dc0d248b310fe1aa9638de92424a (diff)
downloadihatemoney-mirror-a8841f9d3f90ec4c1915493a1b34fa1798895772.zip
ihatemoney-mirror-a8841f9d3f90ec4c1915493a1b34fa1798895772.tar.gz
ihatemoney-mirror-a8841f9d3f90ec4c1915493a1b34fa1798895772.tar.bz2
Merge pull request #122 from JocelynDelalande/configurable-prefix
Made an URL prefix configurable in settings
Diffstat (limited to 'budget/utils.py')
-rw-r--r--budget/utils.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/budget/utils.py b/budget/utils.py
index 60337fb..7717aaa 100644
--- a/budget/utils.py
+++ b/budget/utils.py
@@ -32,3 +32,34 @@ class Redirect303(HTTPException, RoutingException):
def get_response(self, environ):
return redirect(self.new_url, 303)
+
+
+class PrefixedWSGI(object):
+ '''
+ Wrap the application in this middleware and configure the
+ front-end server to add these headers, to let you quietly bind
+ this to a URL other than / and to an HTTP scheme that is
+ different than what is used locally.
+
+ It relies on "APPLICATION_ROOT" app setting.
+
+ Inspired from http://flask.pocoo.org/snippets/35/
+
+ :param app: the WSGI application
+ '''
+ def __init__(self, app):
+ self.app = app
+ self.wsgi_app = app.wsgi_app
+
+ def __call__(self, environ, start_response):
+ script_name = self.app.config['APPLICATION_ROOT']
+ if script_name:
+ environ['SCRIPT_NAME'] = script_name
+ path_info = environ['PATH_INFO']
+ if path_info.startswith(script_name):
+ environ['PATH_INFO'] = path_info[len(script_name):]
+
+ scheme = environ.get('HTTP_X_SCHEME', '')
+ if scheme:
+ environ['wsgi.url_scheme'] = scheme
+ return self.wsgi_app(environ, start_response)