[PATCH 2 of 2] hgweb: fix url base generation to handle absolute paths in baseurl
Alexander Solovyov
piranha at piranha.org.ua
Tue May 5 16:41:51 CDT 2009
# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1241522145 -10800
# Node ID edefd80728d897b3c2b970c82fd3d338125b7c0d
# Parent a491764e18132a855bd13ddc08afdc2c33c95c99
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
@@ -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 += '/'
More information about the Mercurial-devel
mailing list