From 60b3e66232ec6b2021dbc68b1ef42f8443162c68 Mon Sep 17 00:00:00 2001 From: Luca Wehrstedt Date: Sun, 30 Oct 2011 01:15:19 +0300 Subject: [PATCH 1/2] Add Content-Length header on HEAD requests for StaticFileHandler. --- tornado/web.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tornado/web.py b/tornado/web.py index e87f3305..78267b3a 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1484,6 +1484,7 @@ class StaticFileHandler(RequestHandler): return if not include_body: + self.set_header("Content-Length", os.path.getsize(abspath)) return file = open(abspath, "rb") try: From 848244ad0449a1906004ee0d7ccda3162d07e929 Mon Sep 17 00:00:00 2001 From: Luca Wehrstedt Date: Sun, 30 Oct 2011 17:37:29 +0100 Subject: [PATCH 2/2] Add Etag header on HEAD requests for StaticFileHandler. --- tornado/web.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tornado/web.py b/tornado/web.py index 78267b3a..86447bdc 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1485,6 +1485,10 @@ class StaticFileHandler(RequestHandler): if not include_body: self.set_header("Content-Length", os.path.getsize(abspath)) + with open(abspath, "rb") as file: + hasher = hashlib.sha1() + hasher.update(file.read()) + self.set_header("Etag", '"%s"' % hasher.hexdigest()) return file = open(abspath, "rb") try: