##// END OF EJS Templates
extended https fixup middleware.
marcink -
r2054:787f1d15 beta
parent child Browse files
Show More
@@ -1,54 +1,62 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.lib.middleware.https_fixup
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 middleware to handle https correctly
7 7
8 8 :created_on: May 23, 2010
9 9 :author: marcink
10 10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software: you can redistribute it and/or modify
14 14 # it under the terms of the GNU General Public License as published by
15 15 # the Free Software Foundation, either version 3 of the License, or
16 16 # (at your option) any later version.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 26 from rhodecode.lib import str2bool
27 27
28 28
29 29 class HttpsFixup(object):
30 30
31 31 def __init__(self, app, config):
32 32 self.application = app
33 33 self.config = config
34 34
35 35 def __call__(self, environ, start_response):
36 36 self.__fixup(environ)
37 37 return self.application(environ, start_response)
38 38
39 39 def __fixup(self, environ):
40 40 """
41 41 Function to fixup the environ as needed. In order to use this
42 42 middleware you should set this header inside your
43 43 proxy ie. nginx, apache etc.
44 44 """
45 proto = environ.get('HTTP_X_URL_SCHEME')
46 45
47 46 if str2bool(self.config.get('force_https')):
48 47 proto = 'https'
49
48 else:
49 if 'HTTP_X_URL_SCHEME' in environ:
50 proto = environ.get('HTTP_X_URL_SCHEME')
51 elif 'HTTP_X_FORWARDED_SCHEME' in environ:
52 proto = environ.get('HTTP_X_FORWARDED_SCHEME')
53 elif 'HTTP_X_FORWARDED_PROTO' in environ:
54 proto = environ.get('HTTP_X_FORWARDED_PROTO')
55 else:
56 proto = 'http'
50 57 if proto == 'https':
51 58 environ['wsgi.url_scheme'] = proto
52 59 else:
53 60 environ['wsgi.url_scheme'] = 'http'
61
54 62 return None
General Comments 0
You need to be logged in to leave comments. Login now