allow overriding cache directives in responses

Add a new `-minCacheDuration` flag to specify a minimum duration to
cache images for.

Updates #28
Updates #144
Fixes #207
Fixes #208
This commit is contained in:
Will Norris 2025-04-28 23:43:10 -07:00
parent 82ce506905
commit 7502adde1c
6 changed files with 181 additions and 4 deletions

View file

@ -5,10 +5,10 @@ import (
"strings"
)
type cacheControl map[string]string
type CacheControl map[string]string
func parseCacheControl(headers http.Header) cacheControl {
cc := cacheControl{}
func ParseCacheControl(headers http.Header) CacheControl {
cc := CacheControl{}
ccHeader := headers.Get("Cache-Control")
for _, part := range strings.Split(ccHeader, ",") {
part = strings.Trim(part, " ")
@ -24,3 +24,15 @@ func parseCacheControl(headers http.Header) cacheControl {
}
return cc
}
func (cc CacheControl) String() string {
parts := make([]string, 0, len(cc))
for k, v := range cc {
if v == "" {
parts = append(parts, k)
} else {
parts = append(parts, k+"="+v)
}
}
return strings.Join(parts, ", ")
}