]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
correctly parse If-None-Match header
authordaftshady <daftonshady@gmail.com>
Fri, 12 Dec 2014 10:49:13 +0000 (19:49 +0900)
committerdaftshady <daftonshady@gmail.com>
Thu, 5 Mar 2015 08:17:34 +0000 (17:17 +0900)
tornado/web.py

index 92907a51540e550f2a863436622f97fcf2d946c2..f68967a06614f5c0be96bab7e2e3dbbb736c1533 100644 (file)
@@ -1311,8 +1311,13 @@ class RequestHandler(object):
         (perhaps with `set_etag_header`) before calling this method.
         """
         etag = self._headers.get("Etag")
-        inm = utf8(self.request.headers.get("If-None-Match", ""))
-        return bool(etag and inm and inm.find(etag) >= 0)
+        # Split If-None-Match with `,` because RFC 2616 allows multiple etag
+        # values in a single header.
+        inm = utf8(self.request.headers.get("If-None-Match", "")).split(',')
+        # For the case of weak validator, strip inm entities with `W\"`.
+        tags = [x.lstrip('W/') for x in inm]
+        match = (inm[0] == '"*"') or (etag in tags)
+        return bool(etag and match)
 
     def _stack_context_handle_exception(self, type, value, traceback):
         try: