X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7db3ceda16742b65d73ebbc05d02351a5e0496bd..b334b065b36357dd08099adad9835f4aa7075337:/sdk/go/httpserver/responsewriter.go diff --git a/sdk/go/httpserver/responsewriter.go b/sdk/go/httpserver/responsewriter.go index 26aee65c5c..049a3f1aae 100644 --- a/sdk/go/httpserver/responsewriter.go +++ b/sdk/go/httpserver/responsewriter.go @@ -22,7 +22,7 @@ type ResponseWriter interface { // error. type responseWriter struct { http.ResponseWriter - wroteStatus int // Last status given to WriteHeader() + wroteStatus int // First status given to WriteHeader() wroteBodyBytes int // Bytes successfully written err error // Last error returned from Write() sniffed []byte @@ -40,15 +40,21 @@ func (w *responseWriter) CloseNotify() <-chan bool { } func (w *responseWriter) WriteHeader(s int) { - w.wroteStatus = s + if w.wroteStatus == 0 { + w.wroteStatus = s + } + // ...else it's too late to change the status seen by the + // client -- but we call the wrapped WriteHeader() anyway so + // it can log a warning. w.ResponseWriter.WriteHeader(s) } func (w *responseWriter) Write(data []byte) (n int, err error) { if w.wroteStatus == 0 { w.WriteHeader(http.StatusOK) + } else if w.wroteStatus >= 400 { + w.sniff(data) } - w.sniff(data) n, err = w.ResponseWriter.Write(data) w.wroteBodyBytes += n w.err = err