comparison rhodecode/lib/middleware/simplehg.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 c35980ae7958
children d5e42c00f3c1
comparison
equal deleted inserted replaced
2667:129beb0062c2 2668:f0851f37d6be
31 31
32 from mercurial.error import RepoError 32 from mercurial.error import RepoError
33 from mercurial.hgweb import hgweb_mod 33 from mercurial.hgweb import hgweb_mod
34 34
35 from paste.httpheaders import REMOTE_USER, AUTH_TYPE 35 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
36 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \
37 HTTPBadRequest, HTTPNotAcceptable
36 38
37 from rhodecode.lib.utils2 import safe_str 39 from rhodecode.lib.utils2 import safe_str
38 from rhodecode.lib.base import BaseVCSController 40 from rhodecode.lib.base import BaseVCSController
39 from rhodecode.lib.auth import get_container_username 41 from rhodecode.lib.auth import get_container_username
40 from rhodecode.lib.utils import make_ui, is_valid_repo, ui_sections 42 from rhodecode.lib.utils import make_ui, is_valid_repo, ui_sections
41 from rhodecode.model.db import User 43 from rhodecode.model.db import User
42 44
43 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
44 45
45 log = logging.getLogger(__name__) 46 log = logging.getLogger(__name__)
46 47
47 48
48 def is_mercurial(environ): 49 def is_mercurial(environ):
66 class SimpleHg(BaseVCSController): 67 class SimpleHg(BaseVCSController):
67 68
68 def _handle_request(self, environ, start_response): 69 def _handle_request(self, environ, start_response):
69 if not is_mercurial(environ): 70 if not is_mercurial(environ):
70 return self.application(environ, start_response) 71 return self.application(environ, start_response)
72 if not self._check_ssl(environ, start_response):
73 return HTTPNotAcceptable('SSL REQUIRED !')(environ, start_response)
71 74
72 ipaddr = self._get_ip_addr(environ) 75 ipaddr = self._get_ip_addr(environ)
73 username = None 76 username = None
74 # skip passing error to error controller 77 # skip passing error to error controller
75 environ['pylons.status_code_redirect'] = True 78 environ['pylons.status_code_redirect'] = True