Commit 8045405
Eric Bower
·
2026-04-20 22:21:20 -0400 EDT
parent 4acf8cc
chore: normalize header keys
2 files changed,
+10,
-2
+8,
-1
| ... | ... | @@ -43,8 +44,14 @@ func (rw *responseWriter) Send() { | |
| 43 | 44 | } | |
| 44 | 45 | ||
| 45 | 46 | func (rw *responseWriter) ToCacheValue() *CacheValue { | |
| 47 | + | // Normalize header keys to lowercase to avoid case-sensitivity issues | |
| 48 | + | // in the cached map (e.g., "ETag" vs "Etag" as separate keys). | |
| 49 | + | headers := make(map[string][]string) | |
| 50 | + | for k, v := range rw.Header() { | |
| 51 | + | headers[strings.ToLower(k)] = v | |
| 52 | + | } | |
| 46 | 53 | cv := &CacheValue{ | |
| 47 | - | Header: rw.Header(), | |
| 54 | + | Header: headers, | |
| 48 | 55 | Body: rw.body, | |
| 49 | 56 | CreatedAt: time.Now(), | |
| 50 | 57 | StatusCode: rw.StatusCode(), |
+2,
-1
| ... | ... | @@ -140,11 +140,12 @@ func (c *HttpCache) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 140 | 140 | } | |
| 141 | 141 | ||
| 142 | 142 | // Merge non-forbidden headers from the 304 response into the cached entry. | |
| 143 | + | // Normalize keys to lowercase to avoid case-sensitivity issues. | |
| 143 | 144 | for key, values := range wrapped.Header() { | |
| 144 | 145 | if isForbiddenHeader(key) { | |
| 145 | 146 | continue | |
| 146 | 147 | } | |
| 147 | - | cacheValue.Header[key] = values | |
| 148 | + | cacheValue.Header[strings.ToLower(key)] = values | |
| 148 | 149 | } | |
| 149 | 150 | // Revalidation refreshes the entry -- reset CreatedAt so it's fresh again. | |
| 150 | 151 | cacheValue.CreatedAt = time.Now() |