Skip to content

Commit

Permalink
Rearranged cache headers (#59)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vivekmittal authored Nov 1, 2020
1 parent 5c742f2 commit 06805b3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/handler/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

0 comments on commit 06805b3

Please sign in to comment.