Fix brotli response status code when compression is disabled
This commit is contained in:
parent
9be523d772
commit
85039e0d54
2 changed files with 5 additions and 2 deletions
|
@ -138,6 +138,7 @@ func (r *responseWriter) Write(p []byte) (int, error) {
|
|||
// If we detect a contentEncoding, we know we are never going to compress.
|
||||
if r.rw.Header().Get(contentEncoding) != "" {
|
||||
r.compressionDisabled = true
|
||||
r.rw.WriteHeader(r.statusCode)
|
||||
return r.rw.Write(p)
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ func Test_Vary(t *testing.T) {
|
|||
rw := httptest.NewRecorder()
|
||||
h.ServeHTTP(rw, req)
|
||||
|
||||
assert.Equal(t, http.StatusOK, rw.Code)
|
||||
assert.Equal(t, http.StatusAccepted, rw.Code)
|
||||
assert.Equal(t, acceptEncoding, rw.Header().Get(vary))
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ func Test_SmallBodyNoCompression(t *testing.T) {
|
|||
h.ServeHTTP(rw, req)
|
||||
|
||||
// With less than 1024 bytes the response should not be compressed.
|
||||
assert.Equal(t, http.StatusOK, rw.Code)
|
||||
assert.Equal(t, http.StatusAccepted, rw.Code)
|
||||
assert.Empty(t, rw.Header().Get(contentEncoding))
|
||||
assert.Equal(t, smallTestBody, rw.Body.Bytes())
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ func Test_AlreadyCompressed(t *testing.T) {
|
|||
rw := httptest.NewRecorder()
|
||||
h.ServeHTTP(rw, req)
|
||||
|
||||
assert.Equal(t, http.StatusAccepted, rw.Code)
|
||||
assert.Equal(t, bigTestBody, rw.Body.Bytes())
|
||||
}
|
||||
|
||||
|
@ -749,6 +750,7 @@ func newTestHandler(t *testing.T, body []byte) http.Handler {
|
|||
rw.Header().Set("Content-Encoding", "br")
|
||||
}
|
||||
|
||||
rw.WriteHeader(http.StatusAccepted)
|
||||
_, err := rw.Write(body)
|
||||
require.NoError(t, err)
|
||||
}),
|
||||
|
|
Loading…
Reference in a new issue