From: Ben Darnell Date: Wed, 3 Feb 2010 19:56:57 +0000 (-0800) Subject: Set headers earlier in StaticFileHandler, so we return the correct X-Git-Tag: v1.0.0~76^2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8186101e6530dcc025b714a7e8ee3026f5fa3665;p=thirdparty%2Ftornado.git Set headers earlier in StaticFileHandler, so we return the correct content-type with 304 results (instead of always returning text/html) --- diff --git a/tornado/web.py b/tornado/web.py index 1b8ad3cc6..5d1ab2b64 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1092,17 +1092,8 @@ class StaticFileHandler(RequestHandler): if not os.path.isfile(abspath): raise HTTPError(403, "%s is not a file", path) - # Check the If-Modified-Since, and don't send the result if the - # content has not been modified stat_result = os.stat(abspath) modified = datetime.datetime.fromtimestamp(stat_result[stat.ST_MTIME]) - ims_value = self.request.headers.get("If-Modified-Since") - if ims_value is not None: - date_tuple = email.utils.parsedate(ims_value) - if_since = datetime.datetime.fromtimestamp(time.mktime(date_tuple)) - if if_since >= modified: - self.set_status(304) - return self.set_header("Last-Modified", modified) self.set_header("Content-Length", stat_result[stat.ST_SIZE]) @@ -1116,6 +1107,16 @@ class StaticFileHandler(RequestHandler): if mime_type: self.set_header("Content-Type", mime_type) + # Check the If-Modified-Since, and don't send the result if the + # content has not been modified + ims_value = self.request.headers.get("If-Modified-Since") + if ims_value is not None: + date_tuple = email.utils.parsedate(ims_value) + if_since = datetime.datetime.fromtimestamp(time.mktime(date_tuple)) + if if_since >= modified: + self.set_status(304) + return + if not include_body: return file = open(abspath, "r")