add icon caching

This commit is contained in:
Aaron Bieber 2022-12-05 20:45:42 -07:00
parent 4cb49f9d83
commit 706275cc71
No known key found for this signature in database
2 changed files with 8 additions and 0 deletions

View File

@ -42,6 +42,13 @@ func OwnerCtx(next http.Handler) http.Handler {
}) })
} }
func IconCacher(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=604800")
next.ServeHTTP(w, r)
})
}
func iconGET(w http.ResponseWriter, r *http.Request) { func iconGET(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
ownerID, ok := ctx.Value(ownerKey).(int64) ownerID, ok := ctx.Value(ownerKey).(int64)

View File

@ -123,6 +123,7 @@ func main() {
r.Post("/", prignorePOST) r.Post("/", prignorePOST)
}) })
r.Route("/icons", func(r chi.Router) { r.Route("/icons", func(r chi.Router) {
r.Use(IconCacher)
r.Get("/{linkID:[0-9]+}", iconGET) r.Get("/{linkID:[0-9]+}", iconGET)
}) })