Skip to content

Commit

Permalink
Do not set content-type on empty content for compress middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
lammel committed Dec 5, 2022
1 parent 2647a0f commit 23dcd29
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion middleware/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func GzipWithConfig(config GzipConfig) echo.MiddlewareFunc {
w.Reset(rw)
grw := &gzipResponseWriter{Writer: w, ResponseWriter: rw}
defer func() {
if !grw.wroteBody {
if !grw.wroteBody || res.Size == 0 {
if res.Header().Get(echo.HeaderContentEncoding) == gzipScheme {
res.Header().Del(echo.HeaderContentEncoding)
}
Expand Down
2 changes: 1 addition & 1 deletion middleware/compress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestGzipEmpty(t *testing.T) {
return c.String(http.StatusOK, "")
})
if assert.NoError(t, h(c)) {
assert.Equal(t, gzipScheme, rec.Header().Get(echo.HeaderContentEncoding))
assert.Empty(t, rec.Header().Get(echo.HeaderContentEncoding))
assert.Equal(t, "text/plain; charset=UTF-8", rec.Header().Get(echo.HeaderContentType))
r, err := gzip.NewReader(rec.Body)
if assert.NoError(t, err) {
Expand Down

0 comments on commit 23dcd29

Please sign in to comment.