From 0d7c0eb861eb48060444b830af15579f2193e3af Mon Sep 17 00:00:00 2001 From: jake champion Date: Fri, 18 Sep 2026 15:22:48 +0100 Subject: [PATCH] Wrap cache key generation in `HttpSM` helpers Every cache key call site had to repeat the same two `txn_conf` arguments, which makes it easy for a new call site to pass a different `ignore_query` or generation number and silently compute a key that does not match the rest of the transaction. Funnel them through `generate_cache_key()`/`generate_ cache_key92()` instead. --- include/proxy/http/HttpSM.h | 2 ++ src/proxy/http/HttpSM.cc | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/proxy/http/HttpSM.h b/include/proxy/http/HttpSM.h index c2128eeca20..99e0e09dc52 100644 --- a/include/proxy/http/HttpSM.h +++ b/include/proxy/http/HttpSM.h @@ -429,6 +429,8 @@ class HttpSM : public Continuation, public PluginUserArgs void do_drain_request_body(HTTPHdr &response); void wait_for_full_body(); + void generate_cache_key(HttpCacheKey *key, URL *url); + void generate_cache_key92(HttpCacheKey *key, URL *url); virtual void handle_api_return(); void handle_server_setup_error(int event, void *data); diff --git a/src/proxy/http/HttpSM.cc b/src/proxy/http/HttpSM.cc index 54c9e98f967..1a25b84fe23 100644 --- a/src/proxy/http/HttpSM.cc +++ b/src/proxy/http/HttpSM.cc @@ -888,6 +888,18 @@ HttpSM::wait_for_full_body() tunnel.tunnel_run(p); } +void +HttpSM::generate_cache_key(HttpCacheKey *key, URL *url) +{ + Cache::generate_key(key, url, t_state.txn_conf->cache_ignore_query, t_state.txn_conf->cache_generation_number); +} + +void +HttpSM::generate_cache_key92(HttpCacheKey *key, URL *url) +{ + Cache::generate_key92(key, url, t_state.txn_conf->cache_ignore_query, t_state.txn_conf->cache_generation_number); +} + int HttpSM::state_watch_for_client_abort(int event, void *data) { @@ -5322,9 +5334,9 @@ HttpSM::do_cache_lookup_and_read() HttpCacheKey key; if (compatibility_cache_lookup == CompatibilityCacheLookup::COMPAT_CACHE_LOOKUP_92) { - Cache::generate_key92(&key, c_url, t_state.txn_conf->cache_ignore_query, t_state.txn_conf->cache_generation_number); + generate_cache_key92(&key, c_url); } else { - Cache::generate_key(&key, c_url, t_state.txn_conf->cache_ignore_query, t_state.txn_conf->cache_generation_number); + generate_cache_key(&key, c_url); } t_state.hdr_info.cache_request.copy(&t_state.hdr_info.client_request); @@ -5352,8 +5364,7 @@ HttpSM::do_cache_delete_all_alts() SMDbg(dbg_ctl_http_seq, "Issuing cache delete for %s", t_state.cache_info.lookup_url->string_get_ref()); HttpCacheKey key; - Cache::generate_key(&key, t_state.cache_info.lookup_url, t_state.txn_conf->cache_ignore_query, - t_state.txn_conf->cache_generation_number); + generate_cache_key(&key, t_state.cache_info.lookup_url); cacheProcessor.remove(nullptr, &key); } @@ -5430,7 +5441,7 @@ HttpSM::do_cache_prepare_action(HttpCacheSM *c_sm, CacheHTTPInfo *object_read_in SMDbg(dbg_ctl_http_cache_write, "writing to cache with URL %s", s_url->string_get(&t_state.arena)); HttpCacheKey key; - Cache::generate_key(&key, s_url, t_state.txn_conf->cache_ignore_query, t_state.txn_conf->cache_generation_number); + generate_cache_key(&key, s_url); pending_action = c_sm->open_write(&key, s_url, &t_state.hdr_info.cache_request, object_read_info,