Mercurial > kallithea
comparison rhodecode/lib/middleware/simplegit.py @ 2061:9f0fe6777833 beta
merge pull request #32 from codingtony
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 28 Feb 2012 17:44:17 +0200 |
parents | 572855f7a392 |
children | 9ab21c5ddb84 2632a49cb402 |
comparison
equal
deleted
inserted
replaced
2060:572855f7a392 | 2061:9f0fe6777833 |
---|---|
78 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError | 78 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError |
79 | 79 |
80 log = logging.getLogger(__name__) | 80 log = logging.getLogger(__name__) |
81 | 81 |
82 | 82 |
83 GIT_PROTO_PAT = re.compile(r'git-upload-pack|git-receive-pack|info\/refs') | 83 GIT_PROTO_PAT = re.compile(r'^/(.+)/(info/refs|git-upload-pack|git-receive-pack)') |
84 | 84 |
85 | 85 |
86 def is_git(environ): | 86 def is_git(environ): |
87 """Returns True if request's target is git server. | 87 path_info = environ['PATH_INFO'] |
88 ``HTTP_USER_AGENT`` would then have git client version given. | 88 isgit_path = GIT_PROTO_PAT.match(path_info) |
89 | 89 log.debug('is a git path %s pathinfo : %s' % (isgit_path, path_info)) |
90 :param environ: | 90 return isgit_path |
91 """ | |
92 http_user_agent = environ.get('HTTP_USER_AGENT') | |
93 if http_user_agent and http_user_agent.startswith('git'): | |
94 return True | |
95 return False | |
96 | 91 |
97 | 92 |
98 class SimpleGit(BaseVCSController): | 93 class SimpleGit(BaseVCSController): |
99 | 94 |
100 def _handle_request(self, environ, start_response): | 95 def _handle_request(self, environ, start_response): |
96 | |
101 if not is_git(environ): | 97 if not is_git(environ): |
102 return self.application(environ, start_response) | 98 return self.application(environ, start_response) |
103 | 99 |
104 proxy_key = 'HTTP_X_REAL_IP' | 100 proxy_key = 'HTTP_X_REAL_IP' |
105 def_key = 'REMOTE_ADDR' | 101 def_key = 'REMOTE_ADDR' |
220 | 216 |
221 :param environ: environ where PATH_INFO is stored | 217 :param environ: environ where PATH_INFO is stored |
222 """ | 218 """ |
223 try: | 219 try: |
224 environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO']) | 220 environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO']) |
225 repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:]) | 221 repo_name = GIT_PROTO_PAT.match(environ['PATH_INFO']).group(1) |
226 repo_name = GIT_PROTO_PAT.split(repo_name) | |
227 if repo_name: | |
228 repo_name = repo_name[0] | |
229 | |
230 if repo_name.endswith('/'): | |
231 repo_name = repo_name.rstrip('/') | |
232 except: | 222 except: |
233 log.error(traceback.format_exc()) | 223 log.error(traceback.format_exc()) |
234 raise | 224 raise |
235 | 225 |
236 return repo_name | 226 return repo_name |
237 | 227 |
238 def __get_user(self, username): | 228 def __get_user(self, username): |
239 return User.get_by_username(username) | 229 return User.get_by_username(username) |
240 | 230 |
241 def __get_action(self, environ): | 231 def __get_action(self, environ): |
242 """ | 232 """Maps git request commands into a pull or push command. |
243 Maps git request commands into a pull or push command. | |
244 | 233 |
245 :param environ: | 234 :param environ: |
246 """ | 235 """ |
247 service = environ['QUERY_STRING'].split('=') | 236 service = environ['QUERY_STRING'].split('=') |
248 if len(service) > 1: | 237 if len(service) > 1: |