[PATCH] fix absolute url generation in hgweb feeds

Alexander Solovyov piranha at piranha.org.ua
Fri Aug 14 16:10:55 CDT 2009


# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1250284112 -10800
# Node ID 5ec9127736ffe4b06f70aab5d0bf52fb0f58237a
# Parent  cc3916411873596afa470e000d9436fff2939c59
fix absolute url generation in hgweb feeds

HTTP_HOST is an HTTP header, which allows to understand more precisely which
address is external for hgweb instance. This is useful when using hgweb behind
reverse proxy.

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
@@ -212,9 +212,13 @@ class hgweb(object):
             proto = 'http'
             default_port = "80"
 
-        port = req.env["SERVER_PORT"]
+        host = req.env.get('HTTP_HOST', req.env['SERVER_NAME'])
+        if ':' in host:
+            host, port = host.split(':')
+        else:
+            port = req.env['SERVER_PORT']
         port = port != default_port and (":" + port) or ""
-        urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
+        urlbase = '%s://%s%s' % (proto, host, port)
         staticurl = self.config("web", "staticurl") or req.url + 'static/'
         if not staticurl.endswith('/'):
             staticurl += '/'


More information about the Mercurial-devel mailing list