Allow funplex to handle requests to root.
[wrw.git] / wrw / util.py
index 7c42eae..7209ae4 100644 (file)
@@ -10,7 +10,10 @@ def wsgiwrap(callable):
 def formparams(callable):
     spec = inspect.getargspec(callable)
     def wrapper(req):
-        data = form.formdata(req)
+        try:
+            data = form.formdata(req)
+        except IOError:
+            raise resp.httperror(400, "Invalid request", "Form data was incomplete")
         args = dict(data.items())
         args["req"] = req
         if not spec.keywords:
@@ -38,6 +41,8 @@ class funplex(object):
 
     def __call__(self, req):
         if req.pathinfo == "":
+            if "__root__" in self.dir:
+                return self.dir["__root__"](req)
             raise resp.redirect(req.uriname + "/")
         if req.pathinfo[:1] != "/":
             raise resp.notfound()
@@ -49,7 +54,9 @@ class funplex(object):
             p = p.partition("/")[0]
             bi = len(p) + 1
         if p in self.dir:
-            return self.dir[p](req.shift(bi))
+            sreq = req.shift(bi)
+            sreq.selfpath = req.pathinfo[1:]
+            return self.dir[p](sreq)
         raise resp.notfound()
 
     def add(self, fun):
@@ -267,6 +274,6 @@ class specdirty(sessiondata, metaclass=specclass):
 def datecheck(req, mtime):
     if "If-Modified-Since" in req.ihead:
         rtime = proto.phttpdate(req.ihead["If-Modified-Since"])
-        if rtime >= math.floor(mtime):
+        if rtime is not None and rtime >= math.floor(mtime):
             raise resp.unmodified()
     req.ohead["Last-Modified"] = proto.httpdate(mtime)