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 { | |
| 35 | 35 | ||
| 36 | 36 | func (c *PgsCacheKey) GetCacheKey(r *http.Request) string { | |
| 37 | 37 | 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() | |
| 39 | 44 | } | |
| 40 | 45 | ||
| 41 | 46 | type PromCacheMetrics struct { |
+7,
-1
| ... | ... | @@ -19,7 +19,13 @@ type CacheKey interface { | |
| 19 | 19 | type DefaultCacheKey struct{} | |
| 20 | 20 | ||
| 21 | 21 | 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() | |
| 23 | 29 | } | |
| 24 | 30 | ||
| 25 | 31 | type CacheMetrics interface { |