IMGPROXY_CACHE_CONTROL_PASSTHROUGH config

This commit is contained in:
DarthSim
2020-02-04 15:23:41 +06:00
parent 45306adc23
commit 372faba5c1
6 changed files with 46 additions and 7 deletions

View File

@@ -53,11 +53,28 @@ func respondWithImage(ctx context.Context, reqID string, r *http.Request, rw htt
contentDisposition = po.Format.ContentDispositionFromURL(getImageURL(ctx))
}
rw.Header().Set("Expires", time.Now().Add(time.Second*time.Duration(conf.TTL)).Format(http.TimeFormat))
rw.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, public", conf.TTL))
rw.Header().Set("Content-Type", po.Format.Mime())
rw.Header().Set("Content-Disposition", contentDisposition)
var cacheControl, expires string
if conf.CacheControlPassthrough {
cacheControl = getCacheControlHeader(ctx)
expires = getExpiresHeader(ctx)
}
if len(cacheControl) == 0 && len(expires) == 0 {
cacheControl = fmt.Sprintf("max-age=%d, public", conf.TTL)
expires = time.Now().Add(time.Second * time.Duration(conf.TTL)).Format(http.TimeFormat)
}
if len(cacheControl) > 0 {
rw.Header().Set("Cache-Control", cacheControl)
}
if len(expires) > 0 {
rw.Header().Set("Expires", expires)
}
if len(headerVaryValue) > 0 {
rw.Header().Set("Vary", headerVaryValue)
}