From: Ben Darnell Date: Sun, 18 Nov 2012 04:37:42 +0000 (-0500) Subject: Fix If-None-Match support for StaticFileHandler. X-Git-Tag: v3.0.0~222 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f5e658998172a271815028f7a95903fcdb8a02c;p=thirdparty%2Ftornado.git Fix If-None-Match support for StaticFileHandler. No longer set Cache-Control: public on static files; redbot.org says it generally doesn't do anything useful. --- diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index c602ba623..46b4ec1e7 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -785,13 +785,19 @@ class StaticFileTest(WebTestCase): response = self.fetch(path % int(include_host)) self.assertEqual(response.body, utf8(str(True))) - def test_static_304(self): + def test_static_304_if_modified_since(self): response1 = self.fetch("/static/robots.txt") response2 = self.fetch("/static/robots.txt", headers={ 'If-Modified-Since': response1.headers['Last-Modified']}) self.assertEqual(response2.code, 304) self.assertTrue('Content-Length' not in response2.headers) self.assertTrue('Last-Modified' not in response2.headers) + + def test_static_304_if_none_match(self): + response1 = self.fetch("/static/robots.txt") + response2 = self.fetch("/static/robots.txt", headers={ + 'If-None-Match': response1.headers['Etag']}) + self.assertEqual(response2.code, 304) wsgi_safe.append(StaticFileTest) class CustomStaticFileTest(WebTestCase): diff --git a/tornado/web.py b/tornado/web.py index 7d179482d..c6d6fada0 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1612,8 +1612,6 @@ class StaticFileHandler(RequestHandler): self.set_header("Expires", datetime.datetime.utcnow() + datetime.timedelta(seconds=cache_time)) self.set_header("Cache-Control", "max-age=" + str(cache_time)) - else: - self.set_header("Cache-Control", "public") self.set_extra_headers(path) @@ -1629,9 +1627,6 @@ class StaticFileHandler(RequestHandler): with open(abspath, "rb") as file: data = file.read() - hasher = hashlib.sha1() - hasher.update(data) - self.set_header("Etag", '"%s"' % hasher.hexdigest()) if include_body: self.write(data) else: diff --git a/website/sphinx/releases/next.rst b/website/sphinx/releases/next.rst index 02a199c04..30a8001d9 100644 --- a/website/sphinx/releases/next.rst +++ b/website/sphinx/releases/next.rst @@ -163,3 +163,5 @@ In progress ``get_auth_http_client``, which can be overridden to use a non-default `AsyncHTTPClient` instance (e.g. to use a different `IOLoop`) * `tornado.auth.TwitterMixin` now works on Python 3. +* ``Etag``/``If-None-Match`` requests now work with `StaticFileHandler`. +* `StaticFileHandler` no longer sets ``Cache-Control: public`` unnecessarily.