func serveCaptchaAudio(ctx *web.Context, id string) { //tell the user's browser not to cache the audio file //(would cause old audio file to be used even if user has reloaded the CAPTCHA) ctx.SetHeader("Cache-Control", "no-cache", true) err := captcha.WriteAudio(ctx, id, "english") if err != nil { logger.Println("Error, could not write CAPTCHA audio") logger.Println(err.Error()) } }
func (controller *Captcha) serve(w http.ResponseWriter, r *http.Request, id, ext, lang string, download bool) error { w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Header().Set("Pragma", "no-cache") w.Header().Set("Expires", "0") var content bytes.Buffer switch ext { case ".png": w.Header().Set("Content-Type", "image/png") captcha.WriteImage(&content, id, captcha.StdWidth, captcha.StdHeight) case ".wav": w.Header().Set("Content-Type", "audio/x-wav") captcha.WriteAudio(&content, id, lang) default: return captcha.ErrNotFound } if download { w.Header().Set("Content-Type", "application/octet-stream") } http.ServeContent(w, r, id+ext, time.Time{}, bytes.NewReader(content.Bytes())) return nil }
func (o *Captcha) MarshalWAV(w io.Writer) locale.Error { // TODO: generate WAV and write it to w return locale.UntranslatedError(captcha.WriteAudio(w, o.ID, "en")) }