changeset 13821:a35aff48d577

hgweb: use url.url when setting CGI environment variables
author Brodie Rao <brodie@bitheap.org>
date Wed, 30 Mar 2011 20:01:46 -0700
parents 65b89e80f892
children fbf32a6c903e
files mercurial/hgweb/hgwebdir_mod.py
diffstat 1 files changed, 7 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py	Wed Mar 30 20:01:44 2011 -0700
+++ b/mercurial/hgweb/hgwebdir_mod.py	Wed Mar 30 20:01:46 2011 -0700
@@ -6,10 +6,10 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-import os, re, time, urlparse
+import os, re, time
 from mercurial.i18n import _
 from mercurial import ui, hg, util, templater
-from mercurial import error, encoding
+from mercurial import error, encoding, url
 from common import ErrorResponse, get_mtime, staticfile, paritygen, \
                    get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
 from hgweb_mod import hgweb
@@ -361,17 +361,9 @@
         return tmpl
 
     def updatereqenv(self, env):
-        def splitnetloc(netloc):
-            if ':' in netloc:
-                return netloc.split(':', 1)
-            else:
-                return (netloc, None)
-
         if self._baseurl is not None:
-            urlcomp = urlparse.urlparse(self._baseurl)
-            host, port = splitnetloc(urlcomp[1])
-            path = urlcomp[2]
-            env['SERVER_NAME'] = host
-            if port:
-                env['SERVER_PORT'] = port
-            env['SCRIPT_NAME'] = path
+            u = url.url(self._baseurl)
+            env['SERVER_NAME'] = u.host
+            if u.port:
+                env['SERVER_PORT'] = u.port
+            env['SCRIPT_NAME'] = '/' + u.path