Compare commits

...

2 Commits

Author SHA1 Message Date
Julio Guerra
78f4c57b64
Merge 4ea7d51deac965727d145929eb0e8f812fb334f8 into d1a15347b1e45a8ee816193d3578a93bfd73b70f 2025-12-22 17:14:32 +08:00
Julio Guerra
4ea7d51dea
Avoid overwriting the written status code
When the response has been written, the status code saved in `responseWriter`
should no longer be changed by subsequent calls to `WriteHeader()`.

This fixes for example the logging possibly showing the wrong status code, or
any other middleware function checking the status code.
2021-02-03 23:35:39 +01:00

View File

@ -84,6 +84,10 @@ func TestResponseWriterWriteHeadersNow(t *testing.T) {
writer.size = 10
w.WriteHeaderNow()
assert.Equal(t, 10, w.Size())
w.WriteHeader(http.StatusOK)
assert.Equal(t, http.StatusMultipleChoices, w.Status())
assert.Equal(t, http.StatusMultipleChoices, testWriter.Code)
}
func TestResponseWriterWrite(t *testing.T) {