Commit 3ad9fce

Eric Bower  ·  2026-04-19 11:40:18 -0400 EDT
parent d758032
chore(pgs): HEAD can share same key as GET
2 files changed,  +13, -2
+6, -1
......@@ -35,7 +35,12 @@ type PgsCacheKey struct {
3535
3636 func (c *PgsCacheKey) GetCacheKey(r *http.Request) string {
3737 subdomain := router.GetSubdomainFromRequest(r, c.Domain, c.TxtPrefix)
38- return subdomain + "__" + r.Method + "__" + r.URL.RequestURI()
38+ // RFC 9111 §3: HEAD responses can be served from a stored GET response.
39+ method := r.Method
40+ if method == http.MethodHead {
41+ method = http.MethodGet
42+ }
43+ return subdomain + "__" + method + "__" + r.URL.RequestURI()
3944 }
4045
4146 type PromCacheMetrics struct {
+7, -1
......@@ -19,7 +19,13 @@ type CacheKey interface {
1919 type DefaultCacheKey struct{}
2020
2121 func (p *DefaultCacheKey) GetCacheKey(r *http.Request) string {
22- return r.Host + "__" + r.Method + "__" + r.URL.RequestURI()
22+ // RFC 9111 §3: HEAD responses can be served from a stored GET response.
23+ // Normalize HEAD to GET so both methods share the same cache entry.
24+ method := r.Method
25+ if method == http.MethodHead {
26+ method = http.MethodGet
27+ }
28+ return r.Host + "__" + method + "__" + r.URL.RequestURI()
2329 }
2430
2531 type CacheMetrics interface {