diff roundup/rest.py @ 6539:f8df7fed18f6

issue2551175 - Make ETag content-encoding aware. HTTP ETag headers now include a suffix (-gzip, -br, -zstd) indicating the content-encoding used to send the data per rfc7232. Validate any form of ETag by stripping a suffix (if present).
author John Rouillard <rouilj@ieee.org>
date Wed, 01 Dec 2021 19:52:54 -0500
parents c505c774a94d
children 982460ed0a23
line wrap: on
line diff
--- a/roundup/rest.py	Tue Nov 30 00:21:55 2021 -0500
+++ b/roundup/rest.py	Wed Dec 01 19:52:54 2021 -0500
@@ -218,8 +218,20 @@
                                repr_format=repr_format)
 
     for etag in etags:
-        if etag is not None:
-            if etag != node_etag:
+        # etag includes doublequotes around tag:
+        #   '"a46a5572190e4fad63958c135f3746fa"'
+        # but can include content-encoding suffix like:
+        #   '"a46a5572190e4fad63958c135f3746fa-gzip"'
+        # turn the latter into the former as we don't care what
+        # encoding was used to send the body with the etag.
+        try:
+            suffix_start = etag.rindex('-')
+            clean_etag = etag[:suffix_start] + '"'
+        except (ValueError, AttributeError):
+            # - not in etag or etag is None
+            clean_etag = etag
+        if clean_etag is not None:
+            if clean_etag != node_etag:
                 return False
             have_etag_match = True
 

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