[PATCH] Make {urlbase} work in templates when https is used

Wesley J. Landaker wjl at icecavern.net
Tue Jul 10 16:56:45 UTC 2007


# HG changeset patch
# User Wesley J. Landaker <wjl at icecavern.net>
# Date 1184086494 21600
# Node ID 1f4b44a29f507f8ddec84f56744168e3c584eb32
# Parent  f48290864625d7de522ad990230e1d7cc437c20a
Make {urlbase} work in templates when https is used.

diff -r f48290864625 -r 1f4b44a29f50 mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py	Thu Jul 05 16:17:01 2007 -0500
+++ b/mercurial/hgweb/hgweb_mod.py	Tue Jul 10 10:54:54 2007 -0600
@@ -787,9 +787,17 @@ class hgweb(object):
             style = req.form['style'][0]
         mapfile = style_map(self.templatepath, style)
 
+        if req.env.get('HTTPS'):
+            proto = 'https'
+            default_port = "443"
+        else:
+            proto = 'http'
+            default_port = "80"
+            
         port = req.env["SERVER_PORT"]
-        port = port != "80" and (":" + port) or ""
-        urlbase = 'http://%s%s' % (req.env['SERVER_NAME'], 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