]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Set headers earlier in StaticFileHandler, so we return the correct
authorBen Darnell <bdarnell@beaker.local>
Wed, 3 Feb 2010 19:56:57 +0000 (11:56 -0800)
committerBen Darnell <bdarnell@beaker.local>
Wed, 3 Feb 2010 19:56:57 +0000 (11:56 -0800)
content-type with 304 results (instead of always returning text/html)

tornado/web.py

index 1b8ad3cc6e4396ec3c5386cb3c55756f80607fb2..5d1ab2b6476c680aac3b0017790768cda617cefe 100644 (file)
@@ -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")