WriteHeader should be called once

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-11-27 15:28:27 +03:00
parent 1cd636a24b
commit 697d318a6b
2 changed files with 19 additions and 14 deletions

View file

@ -41,11 +41,11 @@ type (
}
responseWrapper struct {
sync.Once
http.ResponseWriter
statusCode int
headWritten bool
startTime time.Time
statusCode int
startTime time.Time
}
)
@ -202,12 +202,10 @@ func (st *HTTPStats) updateStats(api string, w http.ResponseWriter, r *http.Requ
// WriteHeader - writes http status code
func (w *responseWrapper) WriteHeader(code int) {
if !w.headWritten {
w.Do(func() {
w.statusCode = code
w.headWritten = true
w.ResponseWriter.WriteHeader(code)
}
})
}
// Flush - Calls the underlying Flush.