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:
parent
4550b4d861
commit
5eb8fb0286
1 changed files with 8 additions and 3 deletions
11
app.go
11
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()
|
||||
|
|
Loading…
Reference in a new issue