Skip to content

Commit

Permalink
Set cache tag for thumbnail image
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhiFadlillah committed Aug 20, 2019
1 parent 39bf984 commit f62fd30
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/webserver/handler-ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ func (h *handler) serveThumbnailImage(w http.ResponseWriter, r *http.Request, ps
mimeType := http.DetectContentType(buffer)
w.Header().Set("Content-Type", mimeType)

// Set cache value
info, err := img.Stat()
checkError(err)

etag := fmt.Sprintf(`W/"%x-%x"`, info.ModTime().Unix(), info.Size())
w.Header().Set("ETag", etag)
w.Header().Set("Cache-Control", "max-age=86400")

// Serve image
img.Seek(0, 0)
_, err = io.Copy(w, img)
Expand Down

0 comments on commit f62fd30

Please sign in to comment.