changeset 27184:64187e9a5659

hgweb: load server settings from --web-conf (issue4699) It copies the ui before loading the webconf and passes the copied ui only to the service. This way, the hgwebdir app can reload configs cleanly.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 31 Oct 2015 22:50:03 +0900
parents 0945539a3a6b
children d52765831086
files mercurial/hgweb/__init__.py tests/test-hgwebdir.t
diffstat 2 files changed, 51 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/__init__.py	Tue Nov 17 16:42:52 2015 -0600
+++ b/mercurial/hgweb/__init__.py	Sat Oct 31 22:50:03 2015 +0900
@@ -96,6 +96,16 @@
         alluis.update([repo.baseui, repo.ui])
     else:
         baseui = ui
+    webconf = opts.get('web_conf') or opts.get('webdir_conf')
+    if webconf:
+        # load server settings (e.g. web.port) to "copied" ui, which allows
+        # hgwebdir to reload webconf cleanly
+        servui = ui.copy()
+        servui.readconfig(webconf, sections=['web'])
+        alluis.add(servui)
+    else:
+        servui = ui
+
     optlist = ("name templates style address port prefix ipv6"
                " accesslog errorlog certificate encoding")
     for o in optlist.split():
@@ -105,7 +115,6 @@
         for u in alluis:
             u.setconfig("web", o, val, 'serve')
 
-    webconf = opts.get('web_conf') or opts.get('webdir_conf')
     if webconf:
         app = hgwebdir_mod.hgwebdir(webconf, baseui=baseui)
     else:
@@ -113,4 +122,4 @@
             raise error.RepoError(_("there is no Mercurial repository"
                                     " here (.hg not found)"))
         app = hgweb_mod.hgweb(repo, baseui=baseui)
-    return httpservice(ui, app, opts)
+    return httpservice(servui, app, opts)
--- a/tests/test-hgwebdir.t	Tue Nov 17 16:42:52 2015 -0600
+++ b/tests/test-hgwebdir.t	Sat Oct 31 22:50:03 2015 +0900
@@ -1181,6 +1181,38 @@
   </body>
   </html>
   
+
+test listening address/port specified by web-conf (issue4699):
+
+  $ killdaemons.py
+  $ cat >> paths.conf <<EOF
+  > [web]
+  > address = localhost
+  > port = $HGPORT1
+  > EOF
+  $ hg serve -d --pid-file=hg.pid --web-conf paths.conf \
+  >     -A access-paths.log -E error-paths-9.log
+  listening at http://*:$HGPORT1/ (bound to 127.0.0.1:$HGPORT1) (glob)
+  $ cat hg.pid >> $DAEMON_PIDS
+  $ get-with-headers.py localhost:$HGPORT1 '?style=raw'
+  200 Script output follows
+  
+  
+  
+test --port option overrides web.port:
+
+  $ killdaemons.py
+  $ hg serve -p $HGPORT2 -d -v --pid-file=hg.pid --web-conf paths.conf \
+  >     -A access-paths.log -E error-paths-10.log
+  listening at http://*:$HGPORT2/ (bound to 127.0.0.1:$HGPORT2) (glob)
+  $ cat hg.pid >> $DAEMON_PIDS
+  $ get-with-headers.py localhost:$HGPORT2 '?style=raw'
+  200 Script output follows
+  
+  
+  
+
+  $ killdaemons.py
   $ cat > collections.conf <<EOF
   > [collections]
   > $root=$root
@@ -1338,6 +1370,14 @@
 
   $ cat error-paths-8.log
 
+paths errors 9
+
+  $ cat error-paths-9.log
+
+paths errors 10
+
+  $ cat error-paths-10.log
+
 collections errors
 
   $ cat error-collections.log