]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
use weak comparison function when comparing entity-tags
authordaftshady <daftonshady@gmail.com>
Mon, 2 Mar 2015 08:34:42 +0000 (17:34 +0900)
committerdaftshady <daftonshady@gmail.com>
Thu, 5 Mar 2015 08:17:34 +0000 (17:17 +0900)
tornado/web.py

index 7072e5e80d1e71c7325075f0fcecfcff978e1aa2..df6436247481a8abf6fc65355dcac12b3e338170 100644 (file)
@@ -1310,15 +1310,27 @@ class RequestHandler(object):
         before completing the request.  The ``Etag`` header should be set
         (perhaps with `set_etag_header`) before calling this method.
         """
-        etag = self._headers.get("Etag")
+        computed_etag = self._headers.get("Etag")
         # Find all weak and strong etag values from If-None-Match header
         # because RFC 7232 allows multiple etag values in a single header.
         etags = re.findall(
-            r'(?:W/)?"[^"]*"',
+            r'\*|(?:W/)?"[^"]*"',
             utf8(self.request.headers.get("If-None-Match", ""))
         )
-        match = etags and ((etags[0] == '"*"') or (etag in etags))
-        return bool(etag and match)
+        if not computed_etag or not etags:
+            return False
+
+        match = False
+        if etags[0] == '*':
+            match = True
+        else:
+            # Use a weak comparison when comparing entity-tags.
+            val = lambda x: x[2:] if x.startswith('W/') else x
+            for etag in etags:
+                if val(etag) == val(computed_etag):
+                    match = True
+                    break
+        return match
 
     def _stack_context_handle_exception(self, type, value, traceback):
         try: