@wsgi_safe
class StaticFileTest(WebTestCase):
+ # The expected MD5 hash of robots.txt, used in tests that call
+ # StaticFileHandler.get_version
+ robots_txt_hash = b"f71d20196d4caf35b6a670db8c70b03d"
+
def get_handlers(self):
class StaticUrlHandler(RequestHandler):
def get(self, path):
def test_static_url(self):
response = self.fetch("/static_url/robots.txt")
- self.assertEqual(response.body, b"/static/robots.txt?v=f71d2")
+ self.assertEqual(response.body,
+ b"/static/robots.txt?v=" + self.robots_txt_hash)
def test_absolute_static_url(self):
response = self.fetch("/abs_static_url/robots.txt")
self.assertEqual(response.body,
- utf8(self.get_url("/") + "static/robots.txt?v=f71d2"))
+ utf8(self.get_url("/") +
+ "static/robots.txt?v=" +
+ self.robots_txt_hash))
def test_include_host_override(self):
self._trigger_include_host_check(False)
'If-Modified-Since': format_timestamp(stat.st_mtime + 1)})
self.assertEqual(response.code, 304)
+ def test_static_etag(self):
+ response = self.fetch('/static/robots.txt')
+ self.assertEqual(response.headers.get("Etag"),
+ b'"%s"' %(self.robots_txt_hash, ))
+
@wsgi_safe
class CustomStaticFileTest(WebTestCase):
hashes[abs_path] = None
hsh = hashes.get(abs_path)
if hsh:
- return hsh[:5]
+ return hsh
return None
def parse_url_path(self, url_path):
url_path = url_path.replace("/", os.path.sep)
return url_path
+ def compute_etag(self):
+ # Note: compute the etag for static files using get_version so that the
+ # entire file is always considered, even when the request includes a
+ # Range header, so the response will only be a portion of the file.
+ version_hash = self.get_version(self.settings, self.path_args[0])
+ if not version_hash:
+ return None
+ return '"%s"' %(version_hash, )
+
class FallbackHandler(RequestHandler):
"""A `RequestHandler` that wraps another HTTP server callback.