add -forceCache flag to override no-store and private directives

The httpcache package is intended only to be used in private caches, so
it will cache responses marked `private` like normal.  However,
imageproxy is a shared cache, so these response should not be cached
under normal circumstances.  This change introduces a potentially
breaking change to start respecting the `private` cache directive in
responses.

This also adds a new `-forceCache` flag to ignore the `private` and
`no-store` directives, and cache all responses regardless.
This commit is contained in:
Will Norris 2025-05-01 02:26:20 -07:00
parent 8170536e41
commit b529c116c0
5 changed files with 104 additions and 16 deletions

View file

@ -2,6 +2,7 @@ package httpcache
import (
"net/http"
"sort"
"strings"
)
@ -17,9 +18,9 @@ func ParseCacheControl(headers http.Header) CacheControl {
}
if strings.ContainsRune(part, '=') {
keyval := strings.Split(part, "=")
cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",")
cc[strings.ToLower(strings.Trim(keyval[0], " "))] = strings.Trim(keyval[1], ",")
} else {
cc[part] = ""
cc[strings.ToLower(part)] = ""
}
}
return cc
@ -34,5 +35,6 @@ func (cc CacheControl) String() string {
parts = append(parts, k+"="+v)
}
}
sort.StringSlice(parts).Sort()
return strings.Join(parts, ", ")
}