# HG changeset patch # User Dirkjan Ochtman # Date 1196533148 -3600 # Node ID e15f7db0f0eebc359cc6da5dd6f199f02a326130 # Parent 733b50883f7351fd3b3736a74194d343735f639f Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846). diff -r 733b50883f73 -r e15f7db0f0ee mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py Sat Dec 01 19:10:00 2007 +0100 +++ b/mercurial/hgweb/hgweb_mod.py Sat Dec 01 19:19:08 2007 +0100 @@ -726,37 +726,21 @@ def rewrite_request(req): '''translate new web interface to traditional format''' - def spliturl(req): - def firstitem(query): - return query.split('&', 1)[0].split(';', 1)[0] - - def normurl(url): - inner = '/'.join([x for x in url.split('/') if x]) - tl = len(url) > 1 and url.endswith('/') and '/' or '' - - return '%s%s%s' % (url.startswith('/') and '/' or '', - inner, tl) - - root = normurl(urllib.unquote(req.env.get('REQUEST_URI', '').split('?', 1)[0])) - pi = normurl(req.env.get('PATH_INFO', '')) - if pi: - # strip leading / - pi = pi[1:] - if pi: - root = root[:root.rfind(pi)] - if req.env.has_key('REPO_NAME'): - rn = req.env['REPO_NAME'] + '/' - root += rn - query = pi[len(rn):] - else: - query = pi - else: - root += '?' - query = firstitem(req.env['QUERY_STRING']) - - return (root, query) - - req.url, query = spliturl(req) + req.url = req.env['SCRIPT_NAME'] + if not req.url.endswith('/'): + req.url += '/' + if req.env.has_key('REPO_NAME'): + req.url += req.env['REPO_NAME'] + '/' + + if req.env.get('PATH_INFO'): + parts = req.env.get('PATH_INFO').strip('/').split('/') + repo_parts = req.env.get('REPO_NAME', '').split('/') + if parts[:len(repo_parts)] == repo_parts: + parts = parts[len(repo_parts):] + query = '/'.join(parts) + else: + query = req.env['QUERY_STRING'].split('&', 1)[0] + query = query.split(';', 1)[0] if req.form.has_key('cmd'): # old style diff -r 733b50883f73 -r e15f7db0f0ee mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py Sat Dec 01 19:10:00 2007 +0100 +++ b/mercurial/hgweb/hgwebdir_mod.py Sat Dec 01 19:19:08 2007 +0100 @@ -91,15 +91,11 @@ def config(section, name, default=None, untrusted=True): return parentui.config(section, name, default, untrusted) - url = req.env['REQUEST_URI'].split('?')[0] + url = req.env.get('SCRIPT_NAME', '') if not url.endswith('/'): url += '/' - pathinfo = req.env.get('PATH_INFO', '').strip('/') + '/' - base = url[:len(url) - len(pathinfo)] - if not base.endswith('/'): - base += '/' - staticurl = config('web', 'staticurl') or base + 'static/' + staticurl = config('web', 'staticurl') or url + 'static/' if not staticurl.endswith('/'): staticurl += '/' @@ -158,8 +154,10 @@ if u.configbool("web", "hidden", untrusted=True): continue - url = ('/'.join([req.env["REQUEST_URI"].split('?')[0], name]) - .replace("//", "/")) + '/' + parts = [req.env['PATH_INFO'], name] + if req.env['SCRIPT_NAME']: + parts.insert(0, req.env['SCRIPT_NAME']) + url = ('/'.join(parts).replace("//", "/")) + '/' # update time with local timezone try: diff -r 733b50883f73 -r e15f7db0f0ee mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py Sat Dec 01 19:10:00 2007 +0100 +++ b/mercurial/hgweb/server.py Sat Dec 01 19:19:08 2007 +0100 @@ -84,6 +84,7 @@ env['SERVER_NAME'] = self.server.server_name env['SERVER_PORT'] = str(self.server.server_port) env['REQUEST_URI'] = self.path + env['SCRIPT_NAME'] = '' env['PATH_INFO'] = path_info env['REMOTE_HOST'] = self.client_address[0] env['REMOTE_ADDR'] = self.client_address[0] diff -r 733b50883f73 -r e15f7db0f0ee mercurial/hgweb/wsgicgi.py --- a/mercurial/hgweb/wsgicgi.py Sat Dec 01 19:10:00 2007 +0100 +++ b/mercurial/hgweb/wsgicgi.py Sat Dec 01 19:19:08 2007 +0100 @@ -16,6 +16,9 @@ util.set_binary(sys.stdout) environ = dict(os.environ.items()) + if 'PATH_INFO' not in environ: + environ['PATH_INFO'] = '' + environ['wsgi.input'] = sys.stdin environ['wsgi.errors'] = sys.stderr environ['wsgi.version'] = (1, 0) diff -r 733b50883f73 -r e15f7db0f0ee tests/test-hgweb-no-request-uri --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-hgweb-no-request-uri Sat Dec 01 19:19:08 2007 +0100 @@ -0,0 +1,74 @@ +#!/bin/sh + +mkdir repo +cd repo +hg init +echo foo > bar +hg add bar +hg commit -m "test" -d "0 0" -u "Testing" +hg tip + +cat > request.py < + + + http://127.0.0.1/ + + + repo Changelog + 1970-01-01T00:00:00+00:00 + + + test + http://www.selenic.com/mercurial/#changeset-4cbec7e6f8c42eb52b6b52670e1f7560ae9a101e + + + Testing + Testing + + 1970-01-01T00:00:00+00:00 + 1970-01-01T00:00:00+00:00 + +
+
test
+
+
+
+ +
+ +---- ERRORS + +---- HEADERS +200 Script output follows +---- DATA +[('content-type', 'text/plain; charset=ascii')] + +-rw-r--r-- 4 bar + + + +---- ERRORS + +---- HEADERS +200 Script output follows +---- DATA +[('content-type', 'text/plain; charset=ascii')] + +/repo/ + + +---- ERRORS + +---- HEADERS +200 Script output follows +---- DATA +[('content-type', 'text/plain; charset=ascii')] + +-rw-r--r-- 4 bar + + + +---- ERRORS +