1
0
Fork 0
mirror of https://github.com/Luzifer/badge-gen.git synced 2024-11-08 13:20:02 +00:00

stop rendering badges for HTTP304 responses

This commit is contained in:
Knut Ahlers 2016-07-06 23:56:48 +02:00
parent 4550b4d861
commit 5eb8fb0286
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

11
app.go
View file

@ -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()