From 694e3765ddabe7451831e9c6defbdfab7a1105b9 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 4 Mar 2026 10:04:30 -0500 Subject: [PATCH] Use weak ETags --- netbox/netbox/api/viewsets/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/netbox/netbox/api/viewsets/__init__.py b/netbox/netbox/api/viewsets/__init__.py index 0c16a1e1c..80331b434 100644 --- a/netbox/netbox/api/viewsets/__init__.py +++ b/netbox/netbox/api/viewsets/__init__.py @@ -36,15 +36,17 @@ HTTP_ACTIONS = { class ETagMixin: """ - Adds ETag header support to ViewSets. Generates ETags from `last_updated` - (or `created` if unavailable). + Adds ETag header support to ViewSets. Generates weak ETags (W/ prefix per + RFC 7232 ยง2.1) from `last_updated` (or `created` if unavailable). Weak ETags + are appropriate here because the tag is derived from a modification timestamp + rather than a hash of the serialized payload. """ @staticmethod def _get_etag(obj): - """Return a quoted ETag string for the given object, or None.""" + """Return a weak ETag string for the given object, or None.""" if ts := getattr(obj, 'last_updated', None) or getattr(obj, 'created', None): - return f'"{ts.isoformat()}"' + return f'W/"{ts.isoformat()}"' return None def retrieve(self, request, *args, **kwargs):