From 4f1bc1b3873d0349039d98b4c679af247936fc97 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sat, 12 May 2012 20:42:52 -0700 Subject: [PATCH] Short circuit GET on ETags match When client does a conditional GET/HEAD with If-none-match:, if the condition fails (ie, the client's ETag matches the file's) then we can short-circuit the whole process and immediately return an empty body. --- src/allmydata/web/filenode.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/allmydata/web/filenode.py b/src/allmydata/web/filenode.py index fd7e7eb8..634df9c2 100644 --- a/src/allmydata/web/filenode.py +++ b/src/allmydata/web/filenode.py @@ -415,12 +415,12 @@ class FileDownloader(rend.Page): contentsize = filesize req.setHeader("accept-ranges", "bytes") if not self.filenode.is_mutable(): - # TODO: look more closely at Request.setETag and how it interacts - # with a conditional "if-etag-equals" request, I think this may - # need to occur after the setResponseCode below + # if the client already has the ETag then we can short-circuit + # the whole process. si = self.filenode.get_storage_index() - if si: - req.setETag(base32.b2a(si)) + if si and req.setETag(base32.b2a(si)): + return "" + # TODO: for mutable files, use the roothash. For LIT, hash the data. # or maybe just use the URI for CHK and LIT. rangeheader = req.getHeader('range') -- 2.45.2