##// END OF EJS Templates
Removed unneeded PATH_INFO manipulation, and added 404 codes on bad repositories paths
marcink -
r124:f8ae5c1d default
parent child Browse files
Show More
@@ -1,53 +1,59 b''
1 import os
1 import os
2 from mercurial.hgweb import hgweb
2 from mercurial.hgweb import hgweb
3 from mercurial.hgweb.request import wsgiapplication
3 from mercurial.hgweb.request import wsgiapplication
4 from pylons_app.lib.utils import make_ui
4 from pylons_app.lib.utils import make_ui
5 from pylons.controllers.util import abort
6 from webob.exc import HTTPNotFound
5 class SimpleHg(object):
7 class SimpleHg(object):
6
8
7 def __init__(self, application, config):
9 def __init__(self, application, config):
8 self.application = application
10 self.application = application
9 self.config = config
11 self.config = config
10
12
11 def __call__(self, environ, start_response):
13 def __call__(self, environ, start_response):
12 if not is_mercurial(environ):
14 if not is_mercurial(environ):
13 return self.application(environ, start_response)
15 return self.application(environ, start_response)
14 else:
16 else:
15 #repo_name = environ['PATH_INFO'].replace('/', '')
17 try:
16 repo_name = environ['PATH_INFO'].split('/')[1]
18 repo_name = environ['PATH_INFO'].split('/')[1]
17 if not environ['PATH_INFO'].endswith == '/':
19 except:
18 environ['PATH_INFO'] += '/'
20 return HTTPNotFound()(environ, start_response)
19 #environ['SCRIPT_NAME'] = request.path
21
22 #since we wrap into hgweb, just reset the path
20 environ['PATH_INFO'] = '/'
23 environ['PATH_INFO'] = '/'
21 self.baseui = make_ui()
24 self.baseui = make_ui()
22 self.basepath = self.baseui.configitems('paths')[0][1].replace('*', '')
25 self.basepath = self.baseui.configitems('paths')[0][1].replace('*', '')
23 self.repo_path = os.path.join(self.basepath, repo_name)
26 self.repo_path = os.path.join(self.basepath, repo_name)
27 try:
24 app = wsgiapplication(self._make_app)
28 app = wsgiapplication(self._make_app)
29 except Exception as e:
30 return HTTPNotFound()(environ, start_response)
25 return app(environ, start_response)
31 return app(environ, start_response)
26
32
27 def _make_app(self):
33 def _make_app(self):
28 hgserve = hgweb(self.repo_path)
34 hgserve = hgweb(self.repo_path)
29 return self.load_web_settings(hgserve)
35 return self.load_web_settings(hgserve)
30
36
31
37
32 def load_web_settings(self, hgserve):
38 def load_web_settings(self, hgserve):
33 repoui = make_ui(os.path.join(self.repo_path, '.hg', 'hgrc'), False)
39 repoui = make_ui(os.path.join(self.repo_path, '.hg', 'hgrc'), False)
34 #set the global ui for hgserve
40 #set the global ui for hgserve
35 hgserve.repo.ui = self.baseui
41 hgserve.repo.ui = self.baseui
36
42
37 if repoui:
43 if repoui:
38 #set the repository based config
44 #set the repository based config
39 hgserve.repo.ui = repoui
45 hgserve.repo.ui = repoui
40
46
41 return hgserve
47 return hgserve
42
48
43 def is_mercurial(environ):
49 def is_mercurial(environ):
44 """
50 """
45 Returns True if request's target is mercurial server - header
51 Returns True if request's target is mercurial server - header
46 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
52 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
47 """
53 """
48 http_accept = environ.get('HTTP_ACCEPT')
54 http_accept = environ.get('HTTP_ACCEPT')
49 if http_accept and http_accept.startswith('application/mercurial'):
55 if http_accept and http_accept.startswith('application/mercurial'):
50 return True
56 return True
51 return False
57 return False
52
58
53
59
General Comments 0
You need to be logged in to leave comments. Login now