wangshan vor 6 Monaten
Ursprung
Commit
1d0dd01811
1 geänderte Dateien mit 5 neuen und 0 gelöschten Zeilen
  1. 5 0
      gocaptcha/start.go

+ 5 - 0
gocaptcha/start.go

@@ -52,6 +52,7 @@ func RandLightColor(n int) color.RGBA {
 }
 
 func Get(sess *httpsession.Session, checkCode string, w http.ResponseWriter, r *http.Request) {
+
 	code := RandText(4)
 	log.Println(code)
 	cacheKey := fmt.Sprintf("captcha_times_%s", sess.Id())
@@ -104,5 +105,9 @@ func Get(sess *httpsession.Session, checkCode string, w http.ResponseWriter, r *
 	times++
 	redis.Put("other", cacheKey, times, int(ttl))
 	sess.Set(checkCode, code)
+	w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
+	w.Header().Set("Pragma", "no-cache")
+	w.Header().Set("Expires", "0")
+	w.Header().Set("Content-Type", "image/png")
 	_ = captchaImage.Encode(w, ImageFormatJpeg)
 }