From 5eb8fb02867421ff034605f221854245db1fc029 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 6 Jul 2016 23:56:48 +0200 Subject: [PATCH] stop rendering badges for HTTP304 responses --- app.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app.go b/app.go index e5dd7a2..889d5a8 100644 --- a/app.go +++ b/app.go @@ -167,16 +167,21 @@ func generateBadge(res http.ResponseWriter, r *http.Request) { } func renderBadgeToResponse(res http.ResponseWriter, r *http.Request, title, text, color string) { - badge, eTag := createBadge(title, text, color) + cacheKey := fmt.Sprintf("%x", sha1.Sum([]byte(fmt.Sprintf("%s::::%s::::%s", title, text, color)))) + storedTag, _ := cacheStore.Get("eTag", cacheKey) res.Header().Add("Cache-Control", "no-cache") - res.Header().Add("ETag", eTag) - if r.Header.Get("If-None-Match") == eTag { + if storedTag != "" && r.Header.Get("If-None-Match") == storedTag { + res.Header().Add("ETag", storedTag) res.WriteHeader(http.StatusNotModified) return } + badge, eTag := createBadge(title, text, color) + cacheStore.Set("eTag", cacheKey, eTag, time.Hour) + + res.Header().Add("ETag", eTag) res.Header().Add("Content-Type", "image/svg+xml") m := minify.New()