comparison rhodecode/lib/middleware/simplegit.py @ 1834:d0e477b5dc95

backported fixes for issue #318 - session cleanup for mercurial and git middlewares
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 06 Jan 2012 06:09:12 +0200
parents 95c3e33ef32e
children 82a88013a3fd
comparison
equal deleted inserted replaced
1829:6f8f1ab20b7d 1834:d0e477b5dc95
25 # along with this program. If not, see <http://www.gnu.org/licenses/>. 25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 26
27 import os 27 import os
28 import logging 28 import logging
29 import traceback 29 import traceback
30 import time
30 31
31 from dulwich import server as dulserver 32 from dulwich import server as dulserver
32 33
33 34
34 class SimpleGitUploadPackHandler(dulserver.UploadPackHandler): 35 class SimpleGitUploadPackHandler(dulserver.UploadPackHandler):
70 from paste.httpheaders import REMOTE_USER, AUTH_TYPE 71 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
71 72
72 from rhodecode.lib import safe_str 73 from rhodecode.lib import safe_str
73 from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware 74 from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware
74 from rhodecode.lib.utils import invalidate_cache, is_valid_repo 75 from rhodecode.lib.utils import invalidate_cache, is_valid_repo
76 from rhodecode.model import meta
75 from rhodecode.model.db import User 77 from rhodecode.model.db import User
76 78
77 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError 79 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
78 80
79 log = logging.getLogger(__name__) 81 log = logging.getLogger(__name__)
100 self.basepath = self.config['base_path'] 102 self.basepath = self.config['base_path']
101 #authenticate this mercurial request using authfunc 103 #authenticate this mercurial request using authfunc
102 self.authenticate = AuthBasicAuthenticator('', authfunc) 104 self.authenticate = AuthBasicAuthenticator('', authfunc)
103 105
104 def __call__(self, environ, start_response): 106 def __call__(self, environ, start_response):
107 start = time.time()
108 try:
109 return self._handle_request(environ, start_response)
110 finally:
111 log = logging.getLogger(self.__class__.__name__)
112 log.debug('Request time: %.3fs' % (time.time() - start))
113 meta.Session.remove()
114
115 def _handle_request(self, environ, start_response):
105 if not is_git(environ): 116 if not is_git(environ):
106 return self.application(environ, start_response) 117 return self.application(environ, start_response)
107 118
108 proxy_key = 'HTTP_X_REAL_IP' 119 proxy_key = 'HTTP_X_REAL_IP'
109 def_key = 'REMOTE_ADDR' 120 def_key = 'REMOTE_ADDR'