Server: reload captcha when given ?reload=x in URL.
Dmitry Chestnykh dmitry@codingrobots.com
Tue, 26 Apr 2011 13:04:11 +0200
1 files changed,
10 insertions(+),
1 deletions(-)
jump to
M
captcha.go
→
captcha.go
@@ -29,7 +29,8 @@
// globalStore is a shared storage for captchas, generated by New function. var globalStore = NewMemoryStore(CollectNum, Expiration) -// SetCustomStore sets custom storage for captchas. +// SetCustomStore sets custom storage for captchas, replacing the default +// memory store. This function must be called before generating any captchas. func SetCustomStore(s Store) { globalStore = s }@@ -155,6 +156,11 @@ // with id "B9QTvDV1RXbVJ3Ac", and for "B9QTvDV1RXbVJ3Ac.wav" it serves the
// same captcha in audio format. // // To serve an audio captcha as downloadable file, append "?get" to URL. +// +// To reload captcha (get a different solution for the same captcha id), append +// "?reload=x" to URL, where x may be anything (for example, current time or a +// random number to make browsers refetch an image instead of loading it from +// cache). func Server(w, h int) http.Handler { return &captchaHandler{w, h} } func (h *captchaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {@@ -166,6 +172,9 @@ http.NotFound(w, r)
return } var err os.Error + if r.FormValue("reload") != "" { + Reload(id) + } switch ext { case ".png", ".PNG": w.Header().Set("Content-Type", "image/png")