# HG changeset patch # User Matt Mackall # Date 1312228390 18000 # Node ID a31b8e03af28c5c8c7f2c2c8aa935d85561dd2bb # Parent b55c1c6a793eae36c133491858275b2797309cfd hgweb: extract the path logic from updatereqenv and add doctests diff -r b55c1c6a793e -r a31b8e03af28 mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py Mon Aug 01 14:52:11 2011 -0500 +++ b/mercurial/hgweb/hgwebdir_mod.py Mon Aug 01 14:53:10 2011 -0500 @@ -51,6 +51,33 @@ yield (prefix + '/' + util.pconvert(path[len(roothead):]).lstrip('/')).strip('/'), path +def geturlcgivars(baseurl, port): + """ + Extract CGI variables from baseurl + + >>> geturlcgivars("http://host.org/base", "80") + ('host.org', '80', '/base') + >>> geturlcgivars("http://host.org:8000/base", "80") + ('host.org', '8000', '/base') + >>> geturlcgivars('/base', 8000) + ('', '8000', '/base') + >>> geturlcgivars("base", '8000') + ('', '8000', '/base') + >>> geturlcgivars("http://host", '8000') + ('host', '8000', '/') + >>> geturlcgivars("http://host/", '8000') + ('host', '8000', '/') + """ + u = util.url(baseurl) + name = u.host or '' + if u.port: + port = u.port + path = u.path or "" + if not path.startswith('/'): + path = '/' + path + + return name, str(port), path + class hgwebdir(object): refreshinterval = 20 @@ -366,11 +393,7 @@ def updatereqenv(self, env): if self._baseurl is not None: - u = util.url(self._baseurl) - env['SERVER_NAME'] = u.host - if u.port: - env['SERVER_PORT'] = u.port - path = u.path or "" - if not path.startswith('/'): - path = '/' + path + name, port, path = geturlcgivars(self._baseurl, env['SERVER_PORT']) + env['SERVER_NAME'] = name + env['SERVER_PORT'] = port env['SCRIPT_NAME'] = path