]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
web: do not send 500 on invalid If-Modified-Since header (#3412)
authorRonak Gajrawala <rgajrawala@gmail.com>
Mon, 15 Jul 2024 16:47:18 +0000 (09:47 -0700)
committerGitHub <noreply@github.com>
Mon, 15 Jul 2024 16:47:18 +0000 (12:47 -0400)
https://github.com/tornadoweb/tornado/issues/3408

tornado/test/web_test.py
tornado/web.py

index 32a12bad990b6a8ebd511b352528e9ac5ad3fb91..42c66171a2a98b3cd1dac87df55823430a3448fa 100644 (file)
@@ -1230,6 +1230,13 @@ class StaticFileTest(WebTestCase):
         )
         self.assertEqual(response2.code, 200)
 
+    def test_static_304_if_modified_since_invalid(self):
+        response = self.get_and_head(
+            "/static/robots.txt",
+            headers={"If-Modified-Since": "!nv@l!d"},
+        )
+        self.assertEqual(response.code, 200)
+
     def test_static_if_modified_since_pre_epoch(self):
         # On windows, the functions that work with time_t do not accept
         # negative values, and at least one client (processing.js) seems
index 93ce35013991b015f6d62e634d5208a4e66603e4..357c5f1aefd147bd89ddc7be519890faa7ab4899 100644 (file)
@@ -2861,7 +2861,10 @@ class StaticFileHandler(RequestHandler):
         # content has not been modified
         ims_value = self.request.headers.get("If-Modified-Since")
         if ims_value is not None:
-            if_since = email.utils.parsedate_to_datetime(ims_value)
+            try:
+                if_since = email.utils.parsedate_to_datetime(ims_value)
+            except Exception:
+                return False
             if if_since.tzinfo is None:
                 if_since = if_since.replace(tzinfo=datetime.timezone.utc)
             assert self.modified is not None