comparison roundup/cgi/client.py @ 8020:60c98a8a23bd

fix: make If-None-Match work for static file (@@file) case Found by Redbot testing.
author John Rouillard <rouilj@ieee.org>
date Sun, 02 Jun 2024 20:35:47 -0400
parents 16cc72cd9c17
children 98429efb80cb
comparison
equal deleted inserted replaced
8019:16cc72cd9c17 8020:60c98a8a23bd
2714 # RFC2616 section 13.32 discusses etag and references 2714 # RFC2616 section 13.32 discusses etag and references
2715 # section 14.44 (Vary header) as being applicable to etag. 2715 # section 14.44 (Vary header) as being applicable to etag.
2716 # Hence the intermediate proxy should/must match 2716 # Hence the intermediate proxy should/must match
2717 # Accept-Encoding and ETag to determine whether to return 2717 # Accept-Encoding and ETag to determine whether to return
2718 # a 304 or report cache miss and fetch from origin server. 2718 # a 304 or report cache miss and fetch from origin server.
2719 #
2720 # RFC 9110 8.8.3.3 shows a different strong entity tag
2721 # generated for gzip and non gzip replies.
2719 etag = '"%x-%x-%x"' % (stat_info[stat.ST_INO], 2722 etag = '"%x-%x-%x"' % (stat_info[stat.ST_INO],
2720 length, 2723 length,
2721 stat_info[stat.ST_MTIME]) 2724 stat_info[stat.ST_MTIME])
2722 self.setHeader("ETag", etag) 2725 self.setHeader("ETag", etag)
2726
2727 inm = self.request.headers.get('If-None-Match')
2728 if (inm):
2729 inm_etags = inm.split(',')
2730 inm_etags = [tag.strip() for tag in inm_etags]
2731 if etag in inm_etags:
2732 self.setHeader('ETag', etag)
2733 self.setVary('Accept-Encoding')
2734 raise NotModified
2735
2736 # need to check for etag-compression_code:
2737 # a41932-8b5-664ce93d-zstd or a41932-8b5-664ce93d-gzip
2738 tag_prefix = etag[:-1] + '-'
2739 for inm_etag in inm_etags:
2740 if inm_etag.startswith(tag_prefix):
2741 self.setHeader('ETag', inm_etag)
2742 self.setVary('Accept-Encoding')
2743 raise NotModified
2744
2723 # RFC 2616 14.5: Accept-Ranges 2745 # RFC 2616 14.5: Accept-Ranges
2724 # 2746 #
2725 # Let the client know that we will accept range requests. 2747 # Let the client know that we will accept range requests.
2726 self.setHeader("Accept-Ranges", "bytes") 2748 self.setHeader("Accept-Ranges", "bytes")
2727 # RFC 2616 14.35: Range 2749 # RFC 2616 14.35: Range

Roundup Issue Tracker: http://roundup-tracker.org/