1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-03 00:56:59 +02:00

Fixed a problem that returned wrong content-encoding when the gzip compressed content was empty (#1921)

Fixed a problem that returned wrong content-encoding when the gzip compressed content was empty
This commit is contained in:
Nao Yonashiro
2021-12-15 17:15:13 +09:00
committed by GitHub
parent c32fafad68
commit 7bde9aea06
2 changed files with 25 additions and 5 deletions

View File

@ -106,6 +106,27 @@ func TestGzipNoContent(t *testing.T) {
}
}
func TestGzipEmpty(t *testing.T) {
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/", nil)
req.Header.Set(echo.HeaderAcceptEncoding, gzipScheme)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
h := Gzip()(func(c echo.Context) error {
return c.String(http.StatusOK, "")
})
if assert.NoError(t, h(c)) {
assert.Equal(t, gzipScheme, 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) {
var buf bytes.Buffer
buf.ReadFrom(r)
assert.Equal(t, "", buf.String())
}
}
}
func TestGzipErrorReturned(t *testing.T) {
e := echo.New()
e.Use(Gzip())