Mercurial > farol > farol
comparison farol/proxy.py @ 3:3478e20885fd 0.1
Add a ReverseProxy and fix the cache path everywhere
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Wed, 24 Sep 2014 17:46:44 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:fe1918b6e3e0 | 3:3478e20885fd |
---|---|
1 # Code from http://flask.pocoo.org/snippets/35/ | |
2 # | |
3 # This snippet by Peter Hansen can be used freely for anything you like. | |
4 # Consider it public domain. | |
5 | |
6 | |
7 class ReverseProxied(object): | |
8 '''Wrap the application in this middleware and configure the | |
9 front-end server to add these headers, to let you quietly bind | |
10 this to a URL other than / and to an HTTP scheme that is | |
11 different than what is used locally. | |
12 | |
13 In nginx: | |
14 location /myprefix { | |
15 proxy_pass http://192.168.0.1:5001; | |
16 proxy_set_header Host $host; | |
17 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
18 proxy_set_header X-Scheme $scheme; | |
19 proxy_set_header X-Script-Name /myprefix; | |
20 } | |
21 | |
22 :param app: the WSGI application | |
23 ''' | |
24 def __init__(self, app): | |
25 self.app = app | |
26 | |
27 def __call__(self, environ, start_response): | |
28 script_name = environ.get('HTTP_X_SCRIPT_NAME', '') | |
29 if script_name: | |
30 environ['SCRIPT_NAME'] = script_name | |
31 path_info = environ['PATH_INFO'] | |
32 if path_info.startswith(script_name): | |
33 environ['PATH_INFO'] = path_info[len(script_name):] | |
34 | |
35 scheme = environ.get('HTTP_X_SCHEME', '') | |
36 if scheme: | |
37 environ['wsgi.url_scheme'] = scheme | |
38 return self.app(environ, start_response) |