mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-12 22:39:34 -05:00
Set proper expires header
This commit is contained in:
@@ -146,6 +146,7 @@ func (p Phoenix) Static(ttl int) http.HandlerFunc {
|
||||
|
||||
// we don't have a last modification date of the static assets, so we use the service start date
|
||||
lastModified := time.Now().UTC().Format(http.TimeFormat)
|
||||
expires := time.Now().Add(time.Second * time.Duration(ttl)).UTC().Format(http.TimeFormat)
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if rootWithSlash != "/" && r.URL.Path == p.config.HTTP.Root {
|
||||
@@ -169,8 +170,8 @@ func (p Phoenix) Static(ttl int) http.HandlerFunc {
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%s", strconv.Itoa(ttl)))
|
||||
w.Header().Set("Expires", expires)
|
||||
w.Header().Set("Last-Modified", lastModified)
|
||||
w.Header().Del("Expires")
|
||||
|
||||
static.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ func Static(root string, fs http.FileSystem, ttl int) func(http.Handler) http.Ha
|
||||
|
||||
// we don't have a last modification date of the static assets, so we use the service start date
|
||||
lastModified := time.Now().UTC().Format(http.TimeFormat)
|
||||
expires := time.Now().Add(time.Second * time.Duration(ttl)).UTC().Format(http.TimeFormat)
|
||||
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -31,8 +32,8 @@ func Static(root string, fs http.FileSystem, ttl int) func(http.Handler) http.Ha
|
||||
next.ServeHTTP(w, r)
|
||||
} else {
|
||||
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%s", strconv.Itoa(ttl)))
|
||||
w.Header().Set("Expires", expires)
|
||||
w.Header().Set("Last-Modified", lastModified)
|
||||
w.Header().Del("Expires")
|
||||
static.ServeHTTP(w, r)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user