Compare commits

...

2 Commits

Author SHA1 Message Date
Julio Guerra
44eff01dda
Merge 4ea7d51deac965727d145929eb0e8f812fb334f8 into c0048f645ee945c4db30593afdea10123e2c30a6 2025-10-22 09:31:09 -03: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) {