Module: Tep::Cache
- Defined in:
- lib/tep/cache.rb
Class Method Summary collapse
-
.not_modified?(req, res) ⇒ Boolean
True iff ‘req`’s precondition says the client’s cached copy of ‘res` is still fresh (=> answer 304).
Class Method Details
.not_modified?(req, res) ⇒ Boolean
True iff ‘req`’s precondition says the client’s cached copy of ‘res` is still fresh (=> answer 304). Safe methods (GET/HEAD) only.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tep/cache.rb', line 11 def self.not_modified?(req, res) v = req.verb if v != "GET" && v != "HEAD" return false end # ETag / If-None-Match. `*` matches anything; otherwise the quoted # tag is matched as a substring so a comma-separated list of tags # in If-None-Match works. etag = res.headers["ETag"] if etag.length > 0 inm = req.headers["if-none-match"] if inm.length > 0 if inm == "*" return true end if Tep.str_find(inm, etag, 0) >= 0 return true end end end # Last-Modified / If-Modified-Since: fresh if our copy is no newer # than the client's cached date. lm = res.lastmod_epoch if lm > 0 ims = req.headers["if-modified-since"] if ims.length > 0 ims_epoch = Sock.sphttp_parse_http_date(ims) if ims_epoch >= 0 && lm <= ims_epoch return true end end end false end |