From 06805b3a7224aa7d54cf718457c689cb8b03d800 Mon Sep 17 00:00:00 2001 From: Vivek Mittal Date: Sun, 1 Nov 2020 13:27:46 +0530 Subject: [PATCH] Rearranged cache headers (#59) Cache headers are not set predictably. The cache headers are not being returned when deployed on an EC2. https://stackoverflow.com/questions/43202919/http-headers-not-returned-on-ec2 --- internal/handler/image.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/handler/image.go b/internal/handler/image.go index 3bcc947..59259d7 100644 --- a/internal/handler/image.go +++ b/internal/handler/image.go @@ -55,10 +55,11 @@ func ImageHandler(deps *service.Dependencies) http.HandlerFunc { } } - cl, _ := w.Write(data) - w.Header().Set(ContentLengthHeader, fmt.Sprintf("%d", cl)) w.Header().Set(CacheControlHeader, fmt.Sprintf("public,max-age=%d", config.CacheTime())) // Ref to Google CDN we support: https://cloud.google.com/cdn/docs/caching#cacheability w.Header().Set(VaryHeader, "Accept") + + cl, _ := w.Write(data) + w.Header().Set(ContentLengthHeader, fmt.Sprintf("%d", cl)) } }