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

Prevent long-time caching for GitHub

This commit is contained in:
Knut Ahlers 2016-06-28 21:15:41 +02:00
parent af87192ec9
commit 6cc67340f3
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

16
app.go
View file

@ -68,7 +68,7 @@ func generateServiceBadge(res http.ResponseWriter, r *http.Request) {
return
}
renderBadgeToResponse(res, title, text, color)
renderBadgeToResponse(res, r, title, text, color)
}
func generateBadge(res http.ResponseWriter, r *http.Request) {
@ -85,16 +85,22 @@ func generateBadge(res http.ResponseWriter, r *http.Request) {
color = defaultColor
}
renderBadgeToResponse(res, title, text, color)
renderBadgeToResponse(res, r, title, text, color)
}
func renderBadgeToResponse(res http.ResponseWriter, title, text, color string) {
func renderBadgeToResponse(res http.ResponseWriter, r *http.Request, title, text, color string) {
badge, eTag := createBadge(title, text, color)
res.Header().Add("Content-Type", "image/svg+xml")
res.Header().Add("Cache-Control", "public, max-age=31536000")
res.Header().Add("Cache-Control", "no-cache")
res.Header().Add("ETag", eTag)
if r.Header.Get("If-None-Match") == eTag {
res.WriteHeader(http.StatusNotModified)
return
}
res.Header().Add("Content-Type", "image/svg+xml")
m := minify.New()
m.AddFunc("image/svg+xml", svg.Minify)