]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix If-None-Match support for StaticFileHandler.
authorBen Darnell <ben@bendarnell.com>
Sun, 18 Nov 2012 04:37:42 +0000 (23:37 -0500)
committerBen Darnell <ben@bendarnell.com>
Sun, 18 Nov 2012 04:37:42 +0000 (23:37 -0500)
No longer set Cache-Control: public on static files; redbot.org says
it generally doesn't do anything useful.

tornado/test/web_test.py
tornado/web.py
website/sphinx/releases/next.rst

index c602ba6231647cc7f9770b71fc5b78fcfd5b3f86..46b4ec1e73a5079843ccca368305fe11769baa25 100644 (file)
@@ -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):
index 7d179482d1c9d684c0e8ea8f3a4caae596a5c7de..c6d6fada07d01d16adf16a00835e1abf0aaec904 100644 (file)
@@ -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:
index 02a199c04c32eaaaf3e1d3728beb35ff5220835e..30a8001d90daac13fb2a01d29be542af4cfd6df7 100644 (file)
@@ -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.