Mercurial > kallithea
comparison rhodecode/lib/middleware/https_fixup.py @ 547:1e757ac98988
renamed project to rhodecode
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 06 Oct 2010 03:18:16 +0200 |
parents | pylons_app/lib/middleware/https_fixup.py@3782a6d698af |
children | 07a6e8c65526 136af52f374b |
comparison
equal
deleted
inserted
replaced
546:7c2f5e4d7bbf | 547:1e757ac98988 |
---|---|
1 #!/usr/bin/env python | |
2 # encoding: utf-8 | |
3 # middleware to handle https correctly | |
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
5 | |
6 # This program is free software; you can redistribute it and/or | |
7 # modify it under the terms of the GNU General Public License | |
8 # as published by the Free Software Foundation; version 2 | |
9 # of the License or (at your opinion) any later version of the license. | |
10 # | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU General Public License for more details. | |
15 # | |
16 # You should have received a copy of the GNU General Public License | |
17 # along with this program; if not, write to the Free Software | |
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 # MA 02110-1301, USA. | |
20 | |
21 """ | |
22 Created on May 23, 2010 | |
23 | |
24 @author: marcink | |
25 """ | |
26 | |
27 class HttpsFixup(object): | |
28 def __init__(self, app): | |
29 self.application = app | |
30 | |
31 def __call__(self, environ, start_response): | |
32 self.__fixup(environ) | |
33 return self.application(environ, start_response) | |
34 | |
35 | |
36 def __fixup(self, environ): | |
37 """Function to fixup the environ as needed. In order to use this | |
38 middleware you should set this header inside your | |
39 proxy ie. nginx, apache etc. | |
40 """ | |
41 proto = environ.get('HTTP_X_URL_SCHEME') | |
42 | |
43 if proto == 'https': | |
44 environ['wsgi.url_scheme'] = proto | |
45 else: | |
46 environ['wsgi.url_scheme'] = 'http' | |
47 return None |