all repos — captcha @ 1f1174743d98634f77933e5e1298c21024e825d6

Go package captcha implements generation and verification of image and audio CAPTCHAs.

server: fix "multiple response.WriteHeader calls".

The server no does nothing for errors other than ErrNotFound (for which
it calls http.NotFound). This is becase when getting error on writing,
we already wrote headers, so can't respond with status 500.

Possibly log errors in future?
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 15:52:32 +0200
commit

1f1174743d98634f77933e5e1298c21024e825d6

parent

3218681ed3407df1bb387fba3d32cf0d9202787e

1 files changed, 6 insertions(+), 10 deletions(-)

jump to
M server.goserver.go

@@ -43,10 +43,6 @@ w.Header().Set("Content-Type", "image/png")

} return WriteImage(w, id, h.imgWidth, h.imgHeight) case ".wav": - if !download { - w.Header().Set("Content-Type", "audio/x-wav") - } - //return WriteAudio(w, id) //XXX(dchest) Workaround for Chrome: it wants content-length, //or else will start playing NOT from the beginning. //Filed issue: http://code.google.com/p/chromium/issues/detail?id=80565

@@ -55,6 +51,9 @@ if d == nil {

return ErrNotFound } a := NewAudio(d) + if !download { + w.Header().Set("Content-Type", "audio/x-wav") + } w.Header().Set("Content-Length", strconv.Itoa(a.EncodedLen())) _, err := a.WriteTo(w) return err

@@ -74,11 +73,8 @@ if r.FormValue("reload") != "" {

Reload(id) } download := path.Base(dir) == "download" - if err := h.serve(w, id, ext, download); err != nil { - if err == ErrNotFound { - http.NotFound(w, r) - return - } - http.Error(w, "error serving captcha", http.StatusInternalServerError) + if h.serve(w, id, ext, download) == ErrNotFound { + http.NotFound(w, r) } + // Ignore other errors. }