From 518ef25bdb52ba1c565f1dd107883a2e2adb9e9a Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sat, 12 May 2012 20:42:52 -0700 Subject: [PATCH] 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. --- src/allmydata/web/directory.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index 55293563..80f5aa3d 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -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. -- 2.45.2