[PATCH] Add urlhost option

Schueler.external at lantiq.com Schueler.external at lantiq.com
Wed Oct 19 03:35:06 CDT 2011


Add an option to make host used for RSS and Atom links configurable

This patch is useful if you want your links to point to a different server than the one the repo is hosted on. In our setup, the repos are hosted on backend servers, while access to them is through a frontend server, so the links for RSS and Atom were wrong, they pointed to the backend server instead of the frontend. The reason for this is that the URLs were composed from the SERVERNAME which always contains the name of the server on which the repo is hosted.

We introduced an additional config setting, urlhost, that allows you to specify the server to which the links should point.

We implemented this as an option, so if you do not use the option, nothing is changed.

The option can be set in all configuration files.

The patch contains a test for the feature.



# HG changeset patch
# User Nikolaus Schüler <schueler.external at lantiq.com>
# Date 1315488931 -7200
# Branch lantiq
# Node ID ee716084dd9a6a1272488f2fc6a21846e06cbc9c
# Parent  1cde17ebe5ced1e873f0048cf67b3169987f8df8
HGSUP-203: Adding code change, docu addition and test to this head.

diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1291,3 +1291,7 @@ The full set of options is:

 ``templates``
     Where to find the HTML templates. Default is install path.
+
+``urlhost``
+   Name of the host that is used in ``urlbase``. If not specified, it defaults
+   to ``SERVER_NAME``.
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
@@ -233,7 +233,11 @@ class hgweb(object):

         port = req.env["SERVER_PORT"]
         port = port != default_port and (":" + port) or ""
-        urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
+        urlhost = self.config('web', 'urlhost')
+        if urlhost is None:
+            urlhost = req.env['SERVER_NAME']
+
+        urlbase = '%s://%s%s' % (proto, urlhost, port)
         logourl = self.config("web", "logourl", "http://mercurial.selenic.com/")
         staticurl = self.config("web", "staticurl") or req.url + 'static/'
         if not staticurl.endswith('/'):
diff --git a/tests/test-hgweb-urlhost.t b/tests/test-hgweb-urlhost.t
new file mode 100644
--- /dev/null
+++ b/tests/test-hgweb-urlhost.t
@@ -0,0 +1,59 @@
+Prove that a config setting for the server in fact lets this server appear in RSS links
+
+  $ hg init test
+  $ cd test
+  $ echo b > b
+  $ hg ci -Am "b"
+  adding b
+  $ echo a > a
+  $ hg ci -Am "first a"
+  adding a
+  $ hg rm a
+  $ hg ci -m "del a"
+  $ echo b > a
+  $ hg ci -Am "second a"
+  adding a
+  $ hg rm a
+  $ hg ci -m "del2 a"
+  $ hg mv b c
+  $ hg ci -m "mv b"
+  $ echo c >> c
+  $ hg ci -m "change c"
+  $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -E errors.log --config web.urlhost=example.org
+  $ cat hg.pid >> $DAEMON_PIDS
+
+rss log with server setting honored in RSS links
+
+  $ ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/rss-log/tip/a')
+  200 Script output follows
+
+  <?xml version="1.0" encoding="ascii"?>
+  <rss version="2.0">
+    <channel>
+      <link>http://*:$HGPORT/</link> (glob)
+      <language>en-us</language>
+
+      <title>test: a history</title>
+      <description>a revision history</description>
+      <item>
+      <title>second a</title>
+      <link>http://example.org:$HGPORT/log01de2d66a28d/a</link> (glob)
+      <description><![CDATA[second a]]></description>
+      <author>test</author>
+      <pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
+  </item>
+  <item>
+      <title>first a</title>
+      <link>http://example.org:$HGPORT/log5ed941583260/a</link> (glob)
+      <description><![CDATA[first a]]></description>
+      <author>test</author>
+      <pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
+  </item>
+
+    </channel>
+  </rss>
+
+
+errors
+
+  $ cat errors.log



More information about the Mercurial-devel mailing list