comparison rhodecode/lib/middleware/https_fixup.py @ 2668:f0851f37d6be beta

Implementes #509 require SSL flag now works for both git and mercurial. - check is done at earlies possible stage - if detected protocol is not https and flag require is there RhodeCode will return HTTP Error 406: Not Acceptable, before even checking credentials - removed push_ssl flag from mercurial UI objects since that would duplicate logic
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 26 Jul 2012 23:03:26 +0200
parents 8ecfed1d8f8b
children 63e58ef80ef1 26bf9c8baad2
comparison
equal deleted inserted replaced
2667:129beb0062c2 2668:f0851f37d6be
40 """ 40 """
41 Function to fixup the environ as needed. In order to use this 41 Function to fixup the environ as needed. In order to use this
42 middleware you should set this header inside your 42 middleware you should set this header inside your
43 proxy ie. nginx, apache etc. 43 proxy ie. nginx, apache etc.
44 """ 44 """
45 # DETECT PROTOCOL !
46 if 'HTTP_X_URL_SCHEME' in environ:
47 proto = environ.get('HTTP_X_URL_SCHEME')
48 elif 'HTTP_X_FORWARDED_SCHEME' in environ:
49 proto = environ.get('HTTP_X_FORWARDED_SCHEME')
50 elif 'HTTP_X_FORWARDED_PROTO' in environ:
51 proto = environ.get('HTTP_X_FORWARDED_PROTO')
52 else:
53 proto = 'http'
54 org_proto = proto
45 55
56 # if we have force, just override
46 if str2bool(self.config.get('force_https')): 57 if str2bool(self.config.get('force_https')):
47 proto = 'https' 58 proto = 'https'
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'
57 if proto == 'https':
58 environ['wsgi.url_scheme'] = proto
59 else:
60 environ['wsgi.url_scheme'] = 'http'
61 59
62 return None 60 environ['wsgi.url_scheme'] = proto
61 environ['wsgi._org_proto'] = org_proto