Skip to content

Commit

Permalink
✨ Cache middleware: Add Benchmark for additionalHeaders feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
thylong committed Mar 7, 2022
1 parent ca2305d commit 583802e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions middleware/cache/cache_test.go
Expand Up @@ -497,3 +497,31 @@ func Benchmark_Cache_Storage(b *testing.B) {
utils.AssertEqual(b, fiber.StatusTeapot, fctx.Response.Header.StatusCode())
utils.AssertEqual(b, true, len(fctx.Response.Body()) > 30000)
}

func Benchmark_Cache_AdditionalHeaders(b *testing.B) {
app := fiber.New()
app.Use(New(Config{
E2EHeaders: true,
}))

app.Get("/demo", func(c *fiber.Ctx) error {
c.Response().Header.Add("X-Foobar", "foobar")
return c.SendStatus(418)
})

h := app.Handler()

fctx := &fasthttp.RequestCtx{}
fctx.Request.Header.SetMethod("GET")
fctx.Request.SetRequestURI("/demo")

b.ReportAllocs()
b.ResetTimer()

for n := 0; n < b.N; n++ {
h(fctx)
}

utils.AssertEqual(b, fiber.StatusTeapot, fctx.Response.Header.StatusCode())
utils.AssertEqual(b, []byte("foobar"), fctx.Response.Header.Peek("X-Foobar"))
}

0 comments on commit 583802e

Please sign in to comment.