mirror of
https://github.com/glanceapp/glance.git
synced 2025-02-23 05:40:52 +01:00
Optimize cache control header assignment in file server
This commit is contained in:
parent
b3e73ce86a
commit
f68e5ae9ef
@ -147,10 +147,11 @@ func titleToSlug(s string) string {
|
||||
|
||||
func fileServerWithCache(fs http.FileSystem, cacheDuration time.Duration) http.Handler {
|
||||
server := http.FileServer(fs)
|
||||
cacheControlValue := fmt.Sprintf("public, max-age=%d", int(cacheDuration.Seconds()))
|
||||
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO: fix always setting cache control even if the file doesn't exist
|
||||
w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", int(cacheDuration.Seconds())))
|
||||
w.Header().Set("Cache-Control", cacheControlValue)
|
||||
server.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user