From: Fredrik Tolf Date: Wed, 29 May 2013 00:47:22 +0000 (+0200) Subject: Added a simple cache-helper function. X-Git-Url: http://dolda2000.com/gitweb/?p=wrw.git;a=commitdiff_plain;h=1864be32db482df017bc7dd57bbd2ccadeec4429 Added a simple cache-helper function. --- diff --git a/wrw/resp.py b/wrw/resp.py index 24896ba..159126a 100644 --- a/wrw/resp.py +++ b/wrw/resp.py @@ -71,3 +71,9 @@ class redirect(dispatch.restart): req.status(self.status, "Redirect") req.ohead["Location"] = proto.appendurl(proto.requrl(req), self.url) return [] + +class unmodified(dispatch.restart): + def handle(self, req): + req.status(304, "Not Modified") + req.ohead["Content-Length"] = "0" + return [] diff --git a/wrw/util.py b/wrw/util.py index cfc2c8c..abf865e 100644 --- a/wrw/util.py +++ b/wrw/util.py @@ -1,5 +1,5 @@ -import inspect -import req, dispatch, session, form, resp +import inspect, math +import req, dispatch, session, form, resp, proto def wsgiwrap(callable): def wrapper(env, startreq): @@ -233,3 +233,10 @@ class specdirty(sessiondata): ss[i] = specslot.unbound else: ss[i] = val + +def datecheck(req, mtime): + if "If-Modified-Since" in req.ihead: + rtime = proto.phttpdate(req.ihead["If-Modified-Since"]) + if rtime >= math.floor(mtime): + raise resp.unmodified() + req.ohead["Last-Modified"] = proto.httpdate(mtime)