comparison mercurial/hgweb/common.py @ 29491:7f0498bd284e

hgweb: emit a valid, weak ETag Previously, ETag headers from hgweb weren't correctly formed, because rfc2616 (section 14, header definitions) requires double quotes around the content of the header. str(web.mtime) didn't do that. Additionally, strong ETags signify that the resource representations are byte-for-byte identical. That is, they can be reconstructed from byte ranges if client so wishes. Considering ETags for all hgweb pages is just mtime of 00changelog.i and doesn't consider of e.g. .hg/hgrc with description, contact and other fields, it's clearly shouldn't be strong. The W/ prefix marks it as weak, which still allows caching the whole served file/page, but doesn't allow byte-range requests.
author Anton Shestakov <av6@dwimlabs.net>
date Sat, 09 Jul 2016 03:26:24 +0800
parents 37fcfe52c68c
children 075146e85bb6
comparison
equal deleted inserted replaced
29490:b4d117cee636 29491:7f0498bd284e
185 return (config("web", "contact") or 185 return (config("web", "contact") or
186 config("ui", "username") or 186 config("ui", "username") or
187 os.environ.get("EMAIL") or "") 187 os.environ.get("EMAIL") or "")
188 188
189 def caching(web, req): 189 def caching(web, req):
190 tag = str(web.mtime) 190 tag = 'W/"%s"' % web.mtime
191 if req.env.get('HTTP_IF_NONE_MATCH') == tag: 191 if req.env.get('HTTP_IF_NONE_MATCH') == tag:
192 raise ErrorResponse(HTTP_NOT_MODIFIED) 192 raise ErrorResponse(HTTP_NOT_MODIFIED)
193 req.headers.append(('ETag', tag)) 193 req.headers.append(('ETag', tag))