Handle a nonexistent repository with a 404 error.
Based on changeset
62ea868cafbfa3acb7e5dba6982ecb46a1637246 from
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
in http://hannibal.lr-s.tudelft.nl/~vincent/fcgi
--- a/mercurial/hgweb.py Sat Aug 27 23:42:51 2005 -0700
+++ b/mercurial/hgweb.py Sat Aug 27 23:43:08 2005 -0700
@@ -69,6 +69,10 @@
sys.stdout.write('Content-length: %d\n' % size)
sys.stdout.write('\n')
+def httpnotfound(filename):
+ sys.stdout.write("Status: 404\r\n\r\n")
+ sys.stdout.write("File not found: (%s)" % (filename, ))
+
def write(*things):
for thing in things:
if hasattr(thing, "__iter__"):
@@ -938,12 +942,17 @@
except:
virtual = ""
- if virtual[1:]:
- if self.cp.has_option("paths", virtual[1:]):
- real = self.cp.get("paths", virtual[1:])
+ virtual = virtual.strip('/')
+
+ if len(virtual):
+ try:
+ real = self.cp.get("paths", virtual)
h = hgweb(real)
h.run()
return
+ except NoOptionError:
+ httpnotfound(virtual)
+ return
def header(**map):
yield tmpl("header", **map)