Improved compression test
This commit is contained in:
parent
341bd08d1d
commit
245a085020
@ -40,18 +40,20 @@ func TestResponseCompression(t *testing.T) {
|
|||||||
s := web.NewServer()
|
s := web.NewServer()
|
||||||
uncompressed := bytes.Repeat([]byte("This text should be compressed to a size smaller than the original."), 5)
|
uncompressed := bytes.Repeat([]byte("This text should be compressed to a size smaller than the original."), 5)
|
||||||
|
|
||||||
s.Get("/", func(ctx web.Context) error {
|
s.Use(func(ctx web.Context) error {
|
||||||
response := ctx.Response()
|
err := ctx.Next()
|
||||||
response.Write(uncompressed)
|
body := ctx.Response().Body()
|
||||||
body := response.Body()
|
ctx.Response().SetBody(nil)
|
||||||
response.SetBody(nil)
|
zip := gzip.NewWriter(ctx.Response())
|
||||||
|
zip.Write(body)
|
||||||
writer := gzip.NewWriter(response)
|
zip.Close()
|
||||||
defer writer.Close()
|
|
||||||
_, err := writer.Write(body)
|
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
|
s.Get("/", func(ctx web.Context) error {
|
||||||
|
return ctx.Bytes(uncompressed)
|
||||||
|
})
|
||||||
|
|
||||||
response := s.Request("GET", "/", nil)
|
response := s.Request("GET", "/", nil)
|
||||||
assert.Equal(t, response.Status(), 200)
|
assert.Equal(t, response.Status(), 200)
|
||||||
assert.True(t, len(response.Body()) < len(uncompressed))
|
assert.True(t, len(response.Body()) < len(uncompressed))
|
||||||
|
Loading…
Reference in New Issue
Block a user