Improved compression test
This commit is contained in:
parent
341bd08d1d
commit
245a085020
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user