1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

fix: ctx.Record and then iris.Compression flow

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-30 20:13:59 +03:00
parent 53c6f46941
commit eacbcea653
5 changed files with 119 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ import (
"strings"
"testing"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"github.com/kataras/iris/v12/httptest"
)
@@ -15,7 +16,49 @@ func TestCompression(t *testing.T) {
e := httptest.New(t, app)
var expectedReply = payload{Username: "Makis"}
body := e.GET("/").WithHeader(context.AcceptEncodingHeaderKey, context.GZIP).Expect().
testBody(t, e.GET("/"), expectedReply)
}
func TestCompressionAfterRecorder(t *testing.T) {
var expectedReply = payload{Username: "Makis"}
app := iris.New()
app.Use(func(ctx iris.Context) {
ctx.Record()
ctx.Next()
})
app.Use(iris.Compression)
app.Get("/", func(ctx iris.Context) {
ctx.JSON(expectedReply)
})
e := httptest.New(t, app)
testBody(t, e.GET("/"), expectedReply)
}
func TestCompressionBeforeRecorder(t *testing.T) {
var expectedReply = payload{Username: "Makis"}
app := iris.New()
app.Use(iris.Compression)
app.Use(func(ctx iris.Context) {
ctx.Record()
ctx.Next()
})
app.Get("/", func(ctx iris.Context) {
ctx.JSON(expectedReply)
})
e := httptest.New(t, app)
testBody(t, e.GET("/"), expectedReply)
}
func testBody(t *testing.T, req *httptest.Request, expectedReply interface{}) {
t.Helper()
body := req.WithHeader(context.AcceptEncodingHeaderKey, context.GZIP).Expect().
Status(httptest.StatusOK).
ContentEncoding(context.GZIP).
ContentType(context.ContentJSONHeaderValue).Body().Raw()