changeset 36807:1e2194e0ef62

hgweb: use computed base URL from parsed request Let's not reinvent URL construction in a function that runs the templater. Differential Revision: https://phab.mercurial-scm.org/D2735
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 08 Mar 2018 12:59:25 -0800
parents 69b2d0900cd7
children 0031e972ded2
files mercurial/hgweb/hgweb_mod.py
diffstat 1 files changed, 3 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Sat Mar 10 10:20:51 2018 -0800
+++ b/mercurial/hgweb/hgweb_mod.py	Thu Mar 08 12:59:25 2018 -0800
@@ -142,21 +142,9 @@
             if typ in allowed or self.configbool('web', 'allow%s' % typ):
                 yield {'type': typ, 'extension': spec[2], 'node': nodeid}
 
-    def templater(self, wsgireq):
+    def templater(self, wsgireq, req):
         # determine scheme, port and server name
         # this is needed to create absolute urls
-
-        proto = wsgireq.env.get('wsgi.url_scheme')
-        if proto == 'https':
-            proto = 'https'
-            default_port = '443'
-        else:
-            proto = 'http'
-            default_port = '80'
-
-        port = wsgireq.env[r'SERVER_PORT']
-        port = port != default_port and (r':' + port) or r''
-        urlbase = r'%s://%s%s' % (proto, wsgireq.env[r'SERVER_NAME'], port)
         logourl = self.config('web', 'logourl')
         logoimg = self.config('web', 'logoimg')
         staticurl = (self.config('web', 'staticurl')
@@ -194,7 +182,7 @@
             'logourl': logourl,
             'logoimg': logoimg,
             'staticurl': staticurl,
-            'urlbase': urlbase,
+            'urlbase': req.advertisedbaseurl,
             'repo': self.reponame,
             'encoding': encoding.encoding,
             'motd': motd,
@@ -396,7 +384,7 @@
         # process the web interface request
 
         try:
-            tmpl = rctx.templater(wsgireq)
+            tmpl = rctx.templater(wsgireq, req)
             ctype = tmpl('mimetype', encoding=encoding.encoding)
             ctype = templater.stringify(ctype)