summaryrefslogtreecommitdiff
path: root/guard/proxyfix.py
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2015-05-09 00:07:35 +0200
committerYves Fischer <yvesf-git@xapek.org>2016-08-21 15:13:57 +0200
commite4e413ede34a2ae306ddd130324435d0e735f064 (patch)
treed6d438ee1702b8c3bd294baa415be6d6694b2698 /guard/proxyfix.py
downloadinfluxdb-guard-e4e413ede34a2ae306ddd130324435d0e735f064.tar.gz
influxdb-guard-e4e413ede34a2ae306ddd130324435d0e735f064.zip
influxdb-guard
Diffstat (limited to 'guard/proxyfix.py')
-rw-r--r--guard/proxyfix.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/guard/proxyfix.py b/guard/proxyfix.py
new file mode 100644
index 0000000..bd86203
--- /dev/null
+++ b/guard/proxyfix.py
@@ -0,0 +1,31 @@
+from werkzeug.contrib.fixers import ProxyFix
+
+def _reverse_proxified(app):
+ """
+ Configure apache as:
+ RequestHeader set X-Script-Name /videos
+ """
+
+ def wsgi_call(environ, start_response):
+ script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
+ 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 app(environ, start_response)
+
+ return wsgi_call
+
+"""
+'ProxyFix' applied for reading X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Host
+
+'_reverse_proxified' applied for 'X-Script-Name'.
+That's required when external request path is different from application server path.
+"""
+def fix(app):
+ return _reverse_proxified(ProxyFix(app))