hgweb: handle invalid requests with both form data and querystring stable
authorMads Kiilerich <mads@kiilerich.com>
Mon, 21 Feb 2011 00:57:19 +0100
branchstable
changeset 13445 61a898576888
parent 13444 75f5f312df5f
child 13446 1e497df514e2
hgweb: handle invalid requests with both form data and querystring Invalid requests could give an unhandled ErrorResponse. Now this ErrorResponse is handled like other ErrorResponses so the client gets an error message which also is logged on the server.
mercurial/hgweb/hgweb_mod.py
tests/test-http.t
--- a/mercurial/hgweb/hgweb_mod.py	Mon Feb 21 00:52:26 2011 +0100
+++ b/mercurial/hgweb/hgweb_mod.py	Mon Feb 21 00:57:19 2011 +0100
@@ -114,17 +114,17 @@
 
         cmd = req.form.get('cmd', [''])[0]
         if protocol.iscmd(cmd):
-            if query:
-                raise ErrorResponse(HTTP_NOT_FOUND)
-            if cmd in perms:
-                try:
+            try:
+                if query:
+                    raise ErrorResponse(HTTP_NOT_FOUND)
+                if cmd in perms:
                     self.check_perm(req, perms[cmd])
-                except ErrorResponse, inst:
-                    if cmd == 'unbundle':
-                        req.drain()
-                    req.respond(inst, protocol.HGTYPE)
-                    return '0\n%s\n' % inst.message
-            return protocol.call(self.repo, req, cmd)
+                return protocol.call(self.repo, req, cmd)
+            except ErrorResponse, inst:
+                if cmd == 'unbundle':
+                    req.drain()
+                req.respond(inst, protocol.HGTYPE)
+                return '0\n%s\n' % inst.message
 
         # translate user-visible url structure to internal structure
 
--- a/tests/test-http.t	Mon Feb 21 00:52:26 2011 +0100
+++ b/tests/test-http.t	Mon Feb 21 00:57:19 2011 +0100
@@ -11,7 +11,7 @@
   adding foo.d/bAr.hg.d/BaR
   adding foo.d/baR.d.hg/bAR
   adding foo.d/foo
-  $ hg serve -p $HGPORT -d --pid-file=../hg1.pid
+  $ hg serve -p $HGPORT -d --pid-file=../hg1.pid -E ../error.log
   $ hg --config server.uncompressed=False serve -p $HGPORT1 -d --pid-file=../hg2.pid
 
 Test server address cannot be reused
@@ -85,3 +85,13 @@
   changegroup hook: HG_NODE=5fed3813f7f5e1824344fdc9cf8f63bb662c292d HG_SOURCE=pull HG_URL=http://localhost:$HGPORT1/ 
   (run 'hg update' to get a working copy)
   $ cd ..
+
+clone from invalid URL
+
+  $ hg clone http://localhost:$HGPORT/bad
+  abort: HTTP Error 404: Not Found
+  [255]
+
+check error log
+
+  $ cat error.log