mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-06-22 22:37:41 +02:00
Make the expires
option set Expires and Cache-Control headers
This commit is contained in:
@ -55,10 +55,16 @@ func initProcessingHandler() {
|
||||
headerVaryValue = strings.Join(vary, ", ")
|
||||
}
|
||||
|
||||
func setCacheControl(rw http.ResponseWriter, originHeaders map[string]string) {
|
||||
func setCacheControl(rw http.ResponseWriter, force *time.Time, originHeaders map[string]string) {
|
||||
var cacheControl, expires string
|
||||
var ttl int
|
||||
|
||||
if force != nil {
|
||||
rw.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, public", int(time.Until(*force).Seconds())))
|
||||
rw.Header().Set("Expires", force.Format(http.TimeFormat))
|
||||
return
|
||||
}
|
||||
|
||||
if config.CacheControlPassthrough && originHeaders != nil {
|
||||
if val, ok := originHeaders["Cache-Control"]; ok && len(val) > 0 {
|
||||
cacheControl = val
|
||||
@ -115,7 +121,7 @@ func respondWithImage(reqID string, r *http.Request, rw http.ResponseWriter, sta
|
||||
rw.Header().Set("Content-DPR", strconv.FormatFloat(po.Dpr, 'f', 2, 32))
|
||||
}
|
||||
|
||||
setCacheControl(rw, originData.Headers)
|
||||
setCacheControl(rw, po.Expires, originData.Headers)
|
||||
setVary(rw)
|
||||
setCanonical(rw, originURL)
|
||||
|
||||
@ -143,7 +149,7 @@ func respondWithImage(reqID string, r *http.Request, rw http.ResponseWriter, sta
|
||||
}
|
||||
|
||||
func respondWithNotModified(reqID string, r *http.Request, rw http.ResponseWriter, po *options.ProcessingOptions, originURL string, originHeaders map[string]string) {
|
||||
setCacheControl(rw, originHeaders)
|
||||
setCacheControl(rw, po.Expires, originHeaders)
|
||||
setVary(rw)
|
||||
|
||||
rw.WriteHeader(304)
|
||||
|
Reference in New Issue
Block a user