Added a redirection restart.
authorFredrik Tolf <fredrik@dolda2000.com>
Sun, 6 Nov 2011 19:56:40 +0000 (20:56 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Sun, 6 Nov 2011 19:56:40 +0000 (20:56 +0100)
wrw/resp.py

index 2e26ccf..8216d23 100644 (file)
@@ -70,3 +70,14 @@ class httperror(usererror):
 class notfound(httperror):
     def __init__(self):
         return super(notfound, self).__init__(404)
+
+class redirect(dispatch.restart):
+    def __init__(self, url, status = 303):
+        super(redirect, self).__init__()
+        self.url = url
+        self.status = status
+
+    def handle(self, req):
+        req.status(self.status, "Redirect")
+        req.ohead["Location"] = proto.appendurl(proto.requrl(req), self.url)
+        return []