Add cache control header to static content

This commit is contained in:
Las Zenow 2017-07-06 08:13:15 +00:00
parent ab9c5281a5
commit b338cb3393
3 changed files with 4 additions and 1 deletions

View file

@ -52,6 +52,7 @@ func coverHandler(h handler) {
headers := h.w.Header()
headers["Content-Type"] = []string{"image/jpeg"}
addCacheControlHeader(h.w, false)
_, err = io.Copy(h.w, f)
if err != nil {

View file

@ -241,6 +241,8 @@ func openEpubFile(h handler, id string, file string) error {
return err
}
defer html.Close()
addCacheControlHeader(h.w, false)
io.Copy(h.w, html)
return nil
}

View file

@ -93,6 +93,7 @@ func downloadHandler(h handler) {
headers := h.w.Header()
headers["Content-Type"] = []string{"application/epub+zip"}
headers["Content-Disposition"] = []string{"attachment; filename=\"" + book.Title + ".epub\""}
addCacheControlHeader(h.w, false)
io.Copy(h.w, f)
}
@ -207,7 +208,6 @@ func fileServer(servePath string, prefix string) func(w http.ResponseWriter, r *
}
func addCacheControlHeader(w http.ResponseWriter, private bool) {
// FIXME: cache of download and cover don't depends on user login
if private {
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, private", cacheMaxAge))
} else {