From 8bdb787f2d8c7d3cc534eed27f7951bb560d7626 Mon Sep 17 00:00:00 2001 From: toshinari123 Date: Tue, 9 Jan 2024 13:27:14 +0800 Subject: [PATCH] Fix set Cache-Control header position --- .gitignore | 4 ++-- internal/handler/site/site_handler.go | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index edc180d..8f5ad8b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,8 @@ *.test *.out go.work - +pageship *.local .env dist/ -/book \ No newline at end of file +/book diff --git a/internal/handler/site/site_handler.go b/internal/handler/site/site_handler.go index 04e64ed..4b001c8 100644 --- a/internal/handler/site/site_handler.go +++ b/internal/handler/site/site_handler.go @@ -49,7 +49,6 @@ func (h *SiteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } h.next.ServeHTTP(w, r) - w.Header().Set("Cache-Control", "public, max-age=31536000, no-cache") case http.MethodOptions: w.Header().Set("Allow", options) @@ -72,9 +71,9 @@ func (h *SiteHandler) serveFile(w http.ResponseWriter, r *http.Request) { if info.ContentType != "" { w.Header().Set("Content-Type", info.ContentType) } - w.Header().Set("Cache-Control", "public, max-age=31536000, no-cache") if info.Hash != "" { w.Header().Set("ETag", fmt.Sprintf(`"%s"`, info.Hash)) + w.Header().Set("Cache-Control", "public, max-age=31536000, no-cache") } reader := &lazyReader{