handle multiple etags with regex

This commit is contained in:
daftshady 2015-01-31 05:49:46 +09:00
parent 23f033d583
commit 8024eee265
1 changed files with 7 additions and 6 deletions

View File

@ -1311,12 +1311,13 @@ class RequestHandler(object):
(perhaps with `set_etag_header`) before calling this method. (perhaps with `set_etag_header`) before calling this method.
""" """
etag = self._headers.get("Etag") etag = self._headers.get("Etag")
# Split If-None-Match with `,` because RFC 2616 allows multiple etag # Find all weak and strong etag values from If-None-Match header
# values in a single header. # because RFC 7232 allows multiple etag values in a single header.
inm = utf8(self.request.headers.get("If-None-Match", "")).split(',') etags = re.findall(
# For the case of weak validator, lstrip inm entities with `W/`. r'(?:W/)?"[^"]*"',
tags = [x.lstrip('W/') for x in inm] utf8(self.request.headers.get("If-None-Match", ""))
match = (inm[0] == '"*"') or (etag in tags) )
match = etags and ((etags[0] == '"*"') or (etag in etags))
return bool(etag and match) return bool(etag and match)
def _stack_context_handle_exception(self, type, value, traceback): def _stack_context_handle_exception(self, type, value, traceback):