From patchwork Thu Jan 31 21:34:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [STABLE] hgweb: returns 404 for unknow revision instead of 500 From: Pierre-Yves David X-Patchwork-Id: 776 Message-Id: <916f042886d5b3900a64.1359668086@yamac.lan> To: mercurial-devel@selenic.com Cc: pierre-yves.david@ens-lyon.org Date: Thu, 31 Jan 2013 22:34:46 +0100 # HG changeset patch # User Pierre-Yves David # Date 1359667852 -3600 # Branch stable # Node ID 916f042886d5b3900a64fa116d6ac4369f92e279 # Parent 2a1fac3650a5b4d650198604c82ab59969500374 hgweb: returns 404 for unknow revision instead of 500 I noticed that access to filtered revision returned HTTP 500 code (internal server error). Investigation shown that it was the case for unknown revision too. That wrong and we now properly return a 404 for revision not found. 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 @@ -229,14 +229,14 @@ class hgweb(object): content = getattr(webcommands, cmd)(self, req, tmpl) req.respond(HTTP_OK, ctype) return content - except error.LookupError, err: + except (error.LookupError, error.RepoLookupError), err: req.respond(HTTP_NOT_FOUND, ctype) msg = str(err) - if 'manifest' not in msg: + if util.safehasattr(err, 'name') and 'manifest' not in msg: msg = 'revision not found: %s' % err.name return tmpl('error', error=msg) except (error.RepoError, error.RevlogError), inst: req.respond(HTTP_SERVER_ERROR, ctype) return tmpl('error', error=str(inst)) diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t --- a/tests/test-hgweb-commands.t +++ b/tests/test-hgweb-commands.t @@ -1398,6 +1398,35 @@ search works with filtering $ QUERY_STRING='rev=babar' $ python hgweb.cgi > search $ grep Status search Status: 200 Script output follows\r (esc) +proper status for filtered revision + + +(missing rev) + + $ PATH_INFO=/rev/5; export PATH_INFO + $ QUERY_STRING='style=raw' + $ python hgweb.cgi #> search + Status: 404 Not Found\r (esc) + ETag: *\r (glob) (esc) + Content-Type: text/plain; charset=ascii\r (esc) + \r (esc) + + error: unknown revision '5' + + + +(filtered rev) + + $ PATH_INFO=/rev/4; export PATH_INFO + $ QUERY_STRING='style=raw' + $ python hgweb.cgi #> search + Status: 404 Not Found\r (esc) + ETag: *\r (glob) (esc) + Content-Type: text/plain; charset=ascii\r (esc) + \r (esc) + + error: unknown revision '4' + $ cd ..