repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
8045405
parent
4acf8cc
author
Eric Bower
date
2026-04-20 22:21:20 -0400 EDT
chore: normalize header keys
2 files changed,  +10, -2
M pkg/httpcache/rw.go
+8, -1
 1@@ -2,6 +2,7 @@ package httpcache
 2 
 3 import (
 4 	"net/http"
 5+	"strings"
 6 	"time"
 7 )
 8 
 9@@ -43,8 +44,14 @@ func (rw *responseWriter) Send() {
10 }
11 
12 func (rw *responseWriter) ToCacheValue() *CacheValue {
13+	// Normalize header keys to lowercase to avoid case-sensitivity issues
14+	// in the cached map (e.g., "ETag" vs "Etag" as separate keys).
15+	headers := make(map[string][]string)
16+	for k, v := range rw.Header() {
17+		headers[strings.ToLower(k)] = v
18+	}
19 	cv := &CacheValue{
20-		Header:     rw.Header(),
21+		Header:     headers,
22 		Body:       rw.body,
23 		CreatedAt:  time.Now(),
24 		StatusCode: rw.StatusCode(),
M pkg/httpcache/serve.go
+2, -1
 1@@ -140,11 +140,12 @@ func (c *HttpCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 2 		}
 3 
 4 		// Merge non-forbidden headers from the 304 response into the cached entry.
 5+		// Normalize keys to lowercase to avoid case-sensitivity issues.
 6 		for key, values := range wrapped.Header() {
 7 			if isForbiddenHeader(key) {
 8 				continue
 9 			}
10-			cacheValue.Header[key] = values
11+			cacheValue.Header[strings.ToLower(key)] = values
12 		}
13 		// Revalidation refreshes the entry -- reset CreatedAt so it's fresh again.
14 		cacheValue.CreatedAt = time.Now()