Add cache control header to static content
This commit is contained in:
parent
ab9c5281a5
commit
b338cb3393
3 changed files with 4 additions and 1 deletions
|
@ -52,6 +52,7 @@ func coverHandler(h handler) {
|
||||||
|
|
||||||
headers := h.w.Header()
|
headers := h.w.Header()
|
||||||
headers["Content-Type"] = []string{"image/jpeg"}
|
headers["Content-Type"] = []string{"image/jpeg"}
|
||||||
|
addCacheControlHeader(h.w, false)
|
||||||
|
|
||||||
_, err = io.Copy(h.w, f)
|
_, err = io.Copy(h.w, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -241,6 +241,8 @@ func openEpubFile(h handler, id string, file string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer html.Close()
|
defer html.Close()
|
||||||
|
|
||||||
|
addCacheControlHeader(h.w, false)
|
||||||
io.Copy(h.w, html)
|
io.Copy(h.w, html)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@ func downloadHandler(h handler) {
|
||||||
headers := h.w.Header()
|
headers := h.w.Header()
|
||||||
headers["Content-Type"] = []string{"application/epub+zip"}
|
headers["Content-Type"] = []string{"application/epub+zip"}
|
||||||
headers["Content-Disposition"] = []string{"attachment; filename=\"" + book.Title + ".epub\""}
|
headers["Content-Disposition"] = []string{"attachment; filename=\"" + book.Title + ".epub\""}
|
||||||
|
addCacheControlHeader(h.w, false)
|
||||||
|
|
||||||
io.Copy(h.w, f)
|
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) {
|
func addCacheControlHeader(w http.ResponseWriter, private bool) {
|
||||||
// FIXME: cache of download and cover don't depends on user login
|
|
||||||
if private {
|
if private {
|
||||||
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, private", cacheMaxAge))
|
w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, private", cacheMaxAge))
|
||||||
} else {
|
} else {
|
||||||
|
|
Reference in a new issue