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
1 files changed,
6 insertions(+),
10 deletions(-)
jump to
M
server.go
→
server.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. }