diff --git a/Response_test.go b/Response_test.go index 22a7c3b..ead6599 100644 --- a/Response_test.go +++ b/Response_test.go @@ -40,18 +40,20 @@ func TestResponseCompression(t *testing.T) { s := web.NewServer() uncompressed := bytes.Repeat([]byte("This text should be compressed to a size smaller than the original."), 5) - s.Get("/", func(ctx web.Context) error { - response := ctx.Response() - response.Write(uncompressed) - body := response.Body() - response.SetBody(nil) - - writer := gzip.NewWriter(response) - defer writer.Close() - _, err := writer.Write(body) + s.Use(func(ctx web.Context) error { + err := ctx.Next() + body := ctx.Response().Body() + ctx.Response().SetBody(nil) + zip := gzip.NewWriter(ctx.Response()) + zip.Write(body) + zip.Close() return err }) + s.Get("/", func(ctx web.Context) error { + return ctx.Bytes(uncompressed) + }) + response := s.Request("GET", "/", nil) assert.Equal(t, response.Status(), 200) assert.True(t, len(response.Body()) < len(uncompressed))