Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 3f5e658998172a271815028f7a95903fcdb8a02c 1 parent bff0740
@bdarnell bdarnell authored
View
8 tornado/test/web_test.py
@@ -785,13 +785,19 @@ def _trigger_include_host_check(self, include_host):
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):
View
5 tornado/web.py
@@ -1612,8 +1612,6 @@ def get(self, path, include_body=True):
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 @@ def get(self, path, include_body=True):
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:
View
2  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.
Please sign in to comment.
Something went wrong with that request. Please try again.