[master] 857844765 hash: Centralize vary match

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Aug 27 15:23:07 UTC 2025


commit 857844765ac14bddbc5c452b88ac0f53dba5ee01
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue May 20 15:14:50 2025 +0200

    hash: Centralize vary match
    
    Better diff with the --ignore-all-space option.

diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 4d3b5e290..a49a1f76a 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -381,12 +381,26 @@ hsh_insert_busyobj(const struct worker *wrk, struct objhead *oh)
 /*---------------------------------------------------------------------
  */
 
+static int
+hsh_vry_match(struct req *req, struct objcore *oc, const uint8_t *vary)
+{
+
+	if (req->hash_ignore_vary)
+		return (1);
+	if (vary == NULL) {
+		if (! ObjHasAttr(req->wrk, oc, OA_VARY))
+			return (1);
+		vary = ObjGetAttr(req->wrk, oc, OA_VARY, NULL);
+		AN(vary);
+	}
+	return (VRY_Match(req, vary));
+}
+
 static unsigned
 hsh_rush_match(struct req *req)
 {
 	struct objhead *oh;
 	struct objcore *oc;
-	const uint8_t *vary;
 
 	oc = req->objcore;
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
@@ -404,14 +418,7 @@ hsh_rush_match(struct req *req)
 	oh = oc->objhead;
 	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 
-	if (req->hash_ignore_vary)
-		return (1);
-	if (!ObjHasAttr(req->wrk, oc, OA_VARY))
-		return (1);
-
-	vary = ObjGetAttr(req->wrk, oc, OA_VARY, NULL);
-	AN(vary);
-	return (VRY_Match(req, vary));
+	return (hsh_vry_match(req, oc, NULL));
 }
 
 /*---------------------------------------------------------------------
@@ -427,7 +434,6 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
 	const struct vcf_return *vr;
 	vtim_real exp_t_origin;
 	int busy_found;
-	const uint8_t *vary;
 	intmax_t boc_progress;
 	unsigned xid = 0;
 	unsigned ban_checks;
@@ -520,8 +526,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
 				continue;
 
 			if (oc->boc && oc->boc->vary != NULL &&
-			    !req->hash_ignore_vary &&
-			    !VRY_Match(req, oc->boc->vary)) {
+			    !hsh_vry_match(req, oc, oc->boc->vary)) {
 				wrk->strangelove++;
 				continue;
 			}
@@ -540,13 +545,9 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
 			continue;
 		}
 
-		if (!req->hash_ignore_vary && ObjHasAttr(wrk, oc, OA_VARY)) {
-			vary = ObjGetAttr(wrk, oc, OA_VARY, NULL);
-			AN(vary);
-			if (!VRY_Match(req, vary)) {
-				wrk->strangelove++;
-				continue;
-			}
+		if (!hsh_vry_match(req, oc, NULL)) {
+			wrk->strangelove++;
+			continue;
 		}
 
 		if (ban_checks >= ban_any_variant


More information about the varnish-commit mailing list