Do not change response code after 204

This commit is contained in:
Hristo Stoychev
2021-09-17 17:08:08 +03:00
parent 643f738b30
commit 6c00fd131c
2 changed files with 10 additions and 0 deletions

View File

@@ -118,6 +118,7 @@ func (w *writerWrapper) Write(data []byte) (int, error) {
}
if !w.shouldCompress {
w.WriteHeaderNow()
return w.OriginWriter.Write(data)
}
if w.bodyBigEnough {

View File

@@ -389,3 +389,12 @@ func Test_writerWrapper_Write_content_type_no_sniff(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, bigPayload, body)
}
func Test_writeWrapper_does_not_change_status_code_after_204(t *testing.T) {
wrapper, recorder := newWrapper()
wrapper.WriteHeader(http.StatusNoContent)
_, _ = wrapper.Write([]byte("something"))
assert.Equal(t, http.StatusNoContent, recorder.Code)
}