Fiber version
v2.0.6
Issue description
curl -v http://localhost:3000 -H 'If-None-Match: "9-450763418"' return 304 Not Modified with empty body.
but logger print GET / | status: 200 | bytesSent: 9, the status and bytesSent are wrong.
Code snippet
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
)
func main() {
app := fiber.New(fiber.Config{ETag: true})
app.Use(logger.New(logger.Config{
Format: "${method} ${path} | status: ${status} | bytesSent: ${bytesSent}\n",
}))
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("with etag")
})
app.Listen(":3000")
}
Thanks for opening your first issue here! 馃帀 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord
a possible sulotion
export etag functionality as a middleware, which can be mounted after logger middleware.
for compatibility, we can mount etag middleware inside app.Listen, and add a deprecate warning to etag option.
a possible sulotion
export etag functionality as a middleware, which can be mounted after logger middleware.
for compatibility, we can mount etag middleware inside
app.Listen, and add a deprecate warning to etag option.
@dhcmrlchtdj Maybe we can use etag option to determine whether we should hit etag middleware
for compatibility, we can mount etag middleware inside
app.Listen
hmm, it is infeasible.
package github.com/gofiber/fiber/v2
imports github.com/gofiber/fiber/v2/middleware/etag
imports github.com/gofiber/fiber/v2: import cycle not allowed
etag middleware should be placed in fiber core folder.
I encounter some difficulties.
etag middleware should be mounted at a special time.
app.Listen does not satisfied the requirements.
Thanks @dhcmrlchtdj for this bug report, the idea to add the ETag logic as a middleware to provide more flexibility was spot on.
https://github.com/gofiber/fiber/pull/926 will be tagged in version v2.1.0 and should solve this problem, I will leave this issue open until it's released 馃憤
ETag middleware is now available in v2.1.0, you can place this mw after the logger 馃憤
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/etag"
"github.com/gofiber/fiber/v2/middleware/logger"
)
func main() {
app := fiber.New()
app.Use(logger.New())
app.Use(etag.New())
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("with etag")
})
app.Listen(":3000")
}
Most helpful comment
a possible sulotion
export etag functionality as a middleware, which can be mounted after logger middleware.
for compatibility, we can mount etag middleware inside
app.Listen, and add a deprecate warning to etag option.