Add ETags for immutable directories

Like immutable files, the ETag is based on the storage index. However, since
a directory is a special interpretation of a file, it is distinguished from
the file by prepending "DIR:" onto the start of the ETag, and adding
-representation on the end (where -representation is the ?t= argument, json,
info, etc).

It also checks the return of setETag and avoids generating a representation
if the client already has it.
This commit is contained in:
Jeremy Fitzhardinge 2012-05-12 20:42:52 -07:00 committed by Brian Warner
parent 488b6f8ccd
commit 518ef25bdb

View File

@ -153,6 +153,12 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
req = IRequest(ctx)
# This is where all of the directory-related ?t=* code goes.
t = get_arg(req, "t", "").strip()
if not self.node.is_mutable():
si = self.node.get_storage_index()
if si and req.setETag('DIR:%s-%s' % (base32.b2a(si), t or "")):
return ""
if not t:
# render the directory as HTML, using the docFactory and Nevow's
# whole templating thing.