You've already forked imgproxy
mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-12-07 23:32:55 +02:00
Fix IMGPROXY_CACHE_CONTROL_PASSTHROUGH + IMGPROXY_FALLBACK_IMAGE_TTL behavior
This commit is contained in:
@@ -4,6 +4,10 @@
|
|||||||
### Change
|
### Change
|
||||||
- Don't report `The image request is cancelled` errors.
|
- Don't report `The image request is cancelled` errors.
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
- Fix the `Cache-Control` and `Expires` headers behavior when both `IMGPROXY_CACHE_CONTROL_PASSTHROUGH` and `IMGPROXY_FALLBACK_IMAGE_TTL` configs are set.
|
||||||
|
- (pro) Fix the `IMGPROXY_FALLBACK_IMAGE_TTL` config behavior when the `fallback_image_url` processing option is used.
|
||||||
|
|
||||||
## [3.18.2] - 2023-07-13
|
## [3.18.2] - 2023-07-13
|
||||||
### Fix
|
### Fix
|
||||||
- Fix saving to JPEG when using linear colorspace.
|
- Fix saving to JPEG when using linear colorspace.
|
||||||
|
|||||||
@@ -57,15 +57,20 @@ func initProcessingHandler() {
|
|||||||
|
|
||||||
func setCacheControl(rw http.ResponseWriter, force *time.Time, originHeaders map[string]string) {
|
func setCacheControl(rw http.ResponseWriter, force *time.Time, originHeaders map[string]string) {
|
||||||
var cacheControl, expires string
|
var cacheControl, expires string
|
||||||
var ttl int
|
|
||||||
|
|
||||||
if force != nil {
|
ttl := -1
|
||||||
|
|
||||||
|
if _, ok := originHeaders["Fallback-Image"]; ok && config.FallbackImageTTL > 0 {
|
||||||
|
ttl = config.FallbackImageTTL
|
||||||
|
}
|
||||||
|
|
||||||
|
if force != nil && (ttl < 0 || force.Before(time.Now().Add(time.Duration(ttl)*time.Second))) {
|
||||||
rw.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, public", int(time.Until(*force).Seconds())))
|
rw.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, public", int(time.Until(*force).Seconds())))
|
||||||
rw.Header().Set("Expires", force.Format(http.TimeFormat))
|
rw.Header().Set("Expires", force.Format(http.TimeFormat))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.CacheControlPassthrough && originHeaders != nil {
|
if config.CacheControlPassthrough && ttl < 0 && originHeaders != nil {
|
||||||
if val, ok := originHeaders["Cache-Control"]; ok && len(val) > 0 {
|
if val, ok := originHeaders["Cache-Control"]; ok && len(val) > 0 {
|
||||||
cacheControl = val
|
cacheControl = val
|
||||||
}
|
}
|
||||||
@@ -75,9 +80,8 @@ func setCacheControl(rw http.ResponseWriter, force *time.Time, originHeaders map
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(cacheControl) == 0 && len(expires) == 0 {
|
if len(cacheControl) == 0 && len(expires) == 0 {
|
||||||
ttl = config.TTL
|
if ttl < 0 {
|
||||||
if _, ok := originHeaders["Fallback-Image"]; ok && config.FallbackImageTTL > 0 {
|
ttl = config.TTL
|
||||||
ttl = config.FallbackImageTTL
|
|
||||||
}
|
}
|
||||||
cacheControl = fmt.Sprintf("max-age=%d, public", ttl)
|
cacheControl = fmt.Sprintf("max-age=%d, public", ttl)
|
||||||
expires = time.Now().Add(time.Second * time.Duration(ttl)).Format(http.TimeFormat)
|
expires = time.Now().Add(time.Second * time.Duration(ttl)).Format(http.TimeFormat)
|
||||||
|
|||||||
Reference in New Issue
Block a user