wangshan 6 月之前
父节点
当前提交
1d0dd01811
共有 1 个文件被更改,包括 5 次插入0 次删除
  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) {
 func Get(sess *httpsession.Session, checkCode string, w http.ResponseWriter, r *http.Request) {
+
 	code := RandText(4)
 	code := RandText(4)
 	log.Println(code)
 	log.Println(code)
 	cacheKey := fmt.Sprintf("captcha_times_%s", sess.Id())
 	cacheKey := fmt.Sprintf("captcha_times_%s", sess.Id())
@@ -104,5 +105,9 @@ func Get(sess *httpsession.Session, checkCode string, w http.ResponseWriter, r *
 	times++
 	times++
 	redis.Put("other", cacheKey, times, int(ttl))
 	redis.Put("other", cacheKey, times, int(ttl))
 	sess.Set(checkCode, code)
 	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)
 	_ = captchaImage.Encode(w, ImageFormatJpeg)
 }
 }