From 18a9e197c9c71bb2acd649a90054a593be90cb99 Mon Sep 17 00:00:00 2001 From: daftshady Date: Fri, 12 Dec 2014 19:49:13 +0900 Subject: [PATCH] correctly parse If-None-Match header --- tornado/web.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tornado/web.py b/tornado/web.py index 92907a515..f68967a06 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -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: -- 2.47.2