HG changeset patch User Alexander Solovyov piranha piranha org ua Date

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# HG changeset patch
# User Alexander Solovyov <piranha@piranha.org.ua>
# Date 1242120071 -10800
# Node ID 4dd1c63f855236a9518eb93b3eb7b9de9a369da2
# Parent 1f0f01bc86a505ce227d6778af38bc67cff7e85e
hgweb: fix url base generation to handle absolute paths in baseurl
Makes possible to specify hostname, port and protocol, used in absolute url
building (f.e. in atom urls), in webdir-conf via web.baseurl (which is then
passed as env['SCRIPT_NAME']). This allows usage of hgweb behind mod_proxy or
nginx.
diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -106,7 +106,7 @@ class hgweb(object):
# work with CGI variables to create coherent structure
# use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME
- req.url = req.env['SCRIPT_NAME']
+ req.url = self.config('web', 'baseurl', req.env['SCRIPT_NAME'])
if not req.url.endswith('/'):
req.url += '/'
if 'REPO_NAME' in req.env:
@@ -201,17 +201,24 @@ class hgweb(object):
# determine scheme, port and server name
# this is needed to create absolute urls
- proto = req.env.get('wsgi.url_scheme')
- if proto == 'https':
- proto = 'https'
- default_port = "443"
+ if not '://' in req.url:
+ proto = req.env.get('wsgi.url_scheme')
+ if proto == 'https':
+ proto = 'https'
+ default_port = "443"
+ else:
+ proto = 'http'
+ default_port = "80"
+
+ if not req.url.startswith('//'):
+ port = req.env["SERVER_PORT"]
+ port = port != default_port and (":" + port) or ""
+ urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
+ else:
+ urlbase = proto + '://'
else:
- proto = 'http'
- default_port = "80"
+ urlbase = ''
- port = req.env["SERVER_PORT"]
- port = port != default_port and (":" + port) or ""
- urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
staticurl = self.config("web", "staticurl") or req.url + 'static/'
if not staticurl.endswith('/'):
staticurl += '/'