|
@@ -55,10 +55,16 @@ func initProcessingHandler() {
|
|
headerVaryValue = strings.Join(vary, ", ")
|
|
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 cacheControl, expires string
|
|
var ttl int
|
|
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 config.CacheControlPassthrough && 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
|
|
@@ -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))
|
|
rw.Header().Set("Content-DPR", strconv.FormatFloat(po.Dpr, 'f', 2, 32))
|
|
}
|
|
}
|
|
|
|
|
|
- setCacheControl(rw, originData.Headers)
|
|
|
|
|
|
+ setCacheControl(rw, po.Expires, originData.Headers)
|
|
setVary(rw)
|
|
setVary(rw)
|
|
setCanonical(rw, originURL)
|
|
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) {
|
|
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)
|
|
setVary(rw)
|
|
|
|
|
|
rw.WriteHeader(304)
|
|
rw.WriteHeader(304)
|