Releases: gofiber/fiber
Releases · gofiber/fiber
v2.1.0
🔥 New
- Add ETag middleware #926
- Add child PID's to startup message when Prefork is enabled #902
- Add
MaxAge
setting toStatic
which sets aCache-Control
header #896 - Add
ReduceMemoryUsage
toConfig
#892
🧹 Updates
- Refactor proxy mw and increase coverage #924
- Refactor basicauth mw #922
- Refactor requestid mw #921
- Add cache benchmark #898
- Add custom types to compress middleware #897
- Add basicauth benchmark #895
- Make SendFile return status code 404 on file not found #908
- Avoid magic numbers in compress mw #893
- Use constants in unit tests #891
- Update dependencies #930
🩹 Fixes
v2.0.6
v2.0.5
🔥 New
- middleware/cache supports a
CacheControl
option to enable client-side caching #865 - fiber.Cookie now supports the
MaxAge
option #860
🩹 Fixes
v2.0.4
🔥 New
- expvar middleware provides a standardized interface to public variables, such as operation counters in servers #841
- monitor middleware is currently in beta and API design might change! #844
🧹 Updates
- Logger contains a formatted structure with colors if no custom
Format
orio.Writer
are provided in the config #856
- Add snyk.io workflow #838
🩹 Fixes
v2.0.3
🔥 New
func (a *App) Mount(prefix string, app *fiber.App) fiber.Router
micro := fiber.New()
micro.Get("/doe", func(c *fiberCtx) error {
return c.SendStatus(StatusOK)
})
app := fiber.New()
app.Mount("/john", micro) // GET /john/doe -> 200 OK
- utils.UnsafeString replaces utils.GetString #833
- utils.UnsafeBytes replaces utils.GetBytes #833
- middleware/cache middleware introduction by @codemicro #829
🧹 Updates
- csrf middleware now sets
SameSite=Lax
by default #825 - c.QueryParser now supports splitting comma-separated values into slices #817 #782
🩹 Fixes
v2.0.2
🔥 New
- ctx.WriteString appends s to response body. #810
func (c *Ctx) WriteString(s string) (int, error)
- utils.GetArgument checks if key is in arguments 803
func GetArgument(arg string) bool
🧹 Updates
🩹 Fixes
- bind master process to 1 thread when enabling prefork #800
- accept
time.Duration
for cookie expiration in csrf
🚀 Improvements
- improve error handling chain/flow #812
show updated util benchmarks
Benchmark_ToLowerBytes/fiber-16 42847654 25.7 ns/op 0 B/op 0 allocs/op
Benchmark_ToLowerBytes/fiber-16 46143196 25.7 ns/op 0 B/op 0 allocs/op
Benchmark_ToLowerBytes/default-16 17387322 67.4 ns/op 48 B/op 1 allocs/op
Benchmark_ToLowerBytes/default-16 17906491 67.4 ns/op 48 B/op 1 allocs/op
Benchmark_ToUpperBytes/fiber-16 46143729 25.7 ns/op 0 B/op 0 allocs/op
Benchmark_ToUpperBytes/fiber-16 47989250 25.6 ns/op 0 B/op 0 allocs/op
Benchmark_ToUpperBytes/default-16 15580854 76.7 ns/op 48 B/op 1 allocs/op
Benchmark_ToUpperBytes/default-16 15381202 76.9 ns/op 48 B/op 1 allocs/op
Benchmark_TrimRightBytes/fiber-16 70572459 16.3 ns/op 8 B/op 1 allocs/op
Benchmark_TrimRightBytes/fiber-16 74983597 16.3 ns/op 8 B/op 1 allocs/op
Benchmark_TrimRightBytes/default-16 16212578 74.1 ns/op 40 B/op 2 allocs/op
Benchmark_TrimRightBytes/default-16 16434686 74.1 ns/op 40 B/op 2 allocs/op
Benchmark_TrimLeftBytes/fiber-16 74983128 16.3 ns/op 8 B/op 1 allocs/op
Benchmark_TrimLeftBytes/fiber-16 74985002 16.3 ns/op 8 B/op 1 allocs/op
Benchmark_TrimLeftBytes/default-16 21047868 56.5 ns/op 40 B/op 2 allocs/op
Benchmark_TrimLeftBytes/default-16 21048015 56.5 ns/op 40 B/op 2 allocs/op
Benchmark_TrimBytes/fiber-16 54533307 21.9 ns/op 16 B/op 1 allocs/op
Benchmark_TrimBytes/fiber-16 54532812 21.9 ns/op 16 B/op 1 allocs/op
Benchmark_TrimBytes/default-16 14282517 84.6 ns/op 48 B/op 2 allocs/op
Benchmark_TrimBytes/default-16 14114508 84.7 ns/op 48 B/op 2 allocs/op
Benchmark_EqualFolds/fiber-16 36355153 32.6 ns/op 0 B/op 0 allocs/op
Benchmark_EqualFolds/fiber-16 36355593 32.6 ns/op 0 B/op 0 allocs/op
Benchmark_EqualFolds/default-16 15186220 78.1 ns/op 0 B/op 0 allocs/op
Benchmark_EqualFolds/default-16 15186412 78.3 ns/op 0 B/op 0 allocs/op
Benchmark_UUID/fiber-16 23994625 49.8 ns/op 48 B/op 1 allocs/op
Benchmark_UUID/fiber-16 23994768 50.1 ns/op 48 B/op 1 allocs/op
Benchmark_UUID/default-16 3233772 371 ns/op 208 B/op 6 allocs/op
Benchmark_UUID/default-16 3251295 370 ns/op 208 B/op 6 allocs/op
Benchmark_GetString/unsafe-16 1000000000 0.709 ns/op 0 B/op 0 allocs/op
Benchmark_GetString/unsafe-16 1000000000 0.713 ns/op 0 B/op 0 allocs/op
Benchmark_GetString/default-16 59986202 19.0 ns/op 16 B/op 1 allocs/op
Benchmark_GetString/default-16 63142939 19.0 ns/op 16 B/op 1 allocs/op
Benchmark_GetBytes/unsafe-16 508360195 2.36 ns/op 0 B/op 0 allocs/op
Benchmark_GetBytes/unsafe-16 508359979 2.35 ns/op 0 B/op 0 allocs/op
Benchmark_GetBytes/default-16 46143019 25.7 ns/op 16 B/op 1 allocs/op
Benchmark_GetBytes/default-16 44434734 25.6 ns/op 16 B/op 1 allocs/op
Benchmark_GetMIME/fiber-16 21423750 56.3 ns/op 0 B/op 0 allocs/op
Benchmark_GetMIME/fiber-16 21423559 55.4 ns/op 0 B/op 0 allocs/op
Benchmark_GetMIME/default-16 6735282 173 ns/op 0 B/op 0 allocs/op
Benchmark_GetMIME/default-16 6895002 172 ns/op 0 B/op 0 allocs/op
Benchmark_StatusMessage/fiber-16 1000000000 0.766 ns/op 0 B/op 0 allocs/op
Benchmark_StatusMessage/fiber-16 1000000000 0.767 ns/op 0 B/op 0 allocs/op
Benchmark_StatusMessage/default-16 159538528 7.50 ns/op 0 B/op 0 allocs/op
Benchmark_StatusMessage/default-16 159750830 7.51 ns/op 0 B/op 0 allocs/op
Benchmark_ToUpper/fiber-16 22217408 53.3 ns/op 48 B/op 1 allocs/op
Benchmark_ToUpper/fiber-16 22636554 53.2 ns/op 48 B/op 1 allocs/op
Benchmark_ToUpper/default-16 11108600 108 ns/op 48 B/op 1 allocs/op
Benchmark_ToUpper/default-16 11108580 108 ns/op 48 B/op 1 allocs/op
Benchmark_ToLower/fiber-16 23994720 49.8 ns/op 48 B/op 1 allocs/op
Benchmark_ToLower/fiber-16 23994768 50.1 ns/op 48 B/op 1 allocs/op
Benchmark_ToLower/default-16 10808376 110 ns/op 48 B/op 1 allocs/op
Benchmark_ToLower/default-16 10617034 110 ns/op 48 B/op 1 allocs/op
Benchmark_TrimRight/fiber-16 413699521 2.94 ns/op 0 B/op 0 allocs/op
Benchmark_TrimRight/fiber-16 415131687 2.91 ns/op 0 B/op 0 allocs/op
Benchmark_TrimRight/default-16 23994577 49.1 ns/op 32 B/op 1 allocs/op
Benchmark_TrimRight/default-16 24484249 49.4 ns/op 32 B/op 1 allocs/op
Benchmark_TrimLeft/fiber-16 379661170 3.13 ns/op 0 B/op 0 allocs/op
Benchmark_TrimLeft/fiber-16 382079941 3.16 ns/op 0 B/op 0 allocs/op
Benchmark_TrimLeft/default-16 27900877 41.9 ns/op 32 B/op 1 allocs/op
Benchmark_TrimLeft/default-16 28564898 42.0 ns/op 32 B/op 1 allocs/op
Benchmark_Trim/fiber-16 236632856 4.96 ns/op 0 B/op 0 allocs/op
Benchmark_Trim/fiber-16 237570085 4.93 ns/op 0 B/op 0 allocs/op
Benchmark_Trim/default-16 18457221 66.0 ns/op 32 B/op 1 allocs/op
Benchmark_Trim/default-16 18177328 65.9 ns/op 32 B/op 1 allocs/op
Benchmark_Trim/default.trimspace-16 188933770 6.33 ns/op 0 B/op 0 allocs/op
Benchmark_Trim/default.trimspace-16 184007649 6.42 ns/op 0 B/op 0 allocs/op
v2.0.1
🩹 Fixes
- limiter middleware did not expire blocked keys due to race conditions, this required some patching. #789 thnx @ReneWerner87
- utils.UUID() had a possibility to generate a duplicate key with multiple threads, this is now safe. #786
📦 Updates
v2.0.0
⚠ Breaking Changes
- func(c *fiber.Ctx) error is the new Handler type accepting an error return, this will simplify error handling and create cleaner code because you can directly return outgoing methods like c.Send(), c.Next(), c.SendStatus(), c.Redirect() etc... #218
// func(c *fiber.Ctx) {}
func(c *fiber.Ctx) error {}
app.Use(func(c *fiber.Ctx) error {
if c.Get("x-john") == "doe" {
return c.Next()
}
return c.SendStatus(fiber.StatusForbidden)
})
app.Use("/teapot", func(c *fiber.Ctx) error {
return c.Send([]byte("Helllo, Teapot ☕!"))
})
app.Get("/world", func(c *fiber.Ctx) error {
return c.SendString("Hello, World 👋!")
})
app.Get("/redirect", func(c *fiber.Ctx) error {
return c.Redirect("https://google.com")
})
- fiber.New() takes an optional Config struct as value that will replace the *Settings pointer.
// func New(settings ...*Settings) *App {}
func New(config... Config) *App {}
- app.Listen() now contains a strong typed signature accepting an
string
addr argument.
To enable TLS, provide your own listener app.Listener(ln net.Listener) #555
// func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {}
func (app *App) Listen(addr string) error {}
- app.Listener() will remove the optional *tls.Config argument, this should be set within the given listener.
Prefork
will be compatible with custom listeners.
// func (app *App) Listener(ln net.Listener, tlsconfig ...*tls.Config) error {}
func (app *App) Listener(ln net.Listener) error {}
- c.Next() returns an error to be used with the new Ctx handler signature. Passing an error through c.Next is not necessary anymore since we return all errors within the handler.
// func (c *Ctx) Next(err ...error) {}
func (c *Ctx) Next() error {}
- c.Body() now returns []byte type instead of a string
// func (c *Ctx) Body() string {}
func (c *Ctx) Body() []byte {}
- c.Write() will comply with the io.Writer interface.
// func (c *Ctx) Write(bodies ...interface{}) {}
func (c *Ctx) Write(p []byte) (n int, err error) {}
- c.Context() returns the original
*fasthttp.RequestCtx
and is still compatible with thecontext.Context
interface.
// func (c *Ctx) Context() context.Context
func (c *Ctx) Context() *fasthttp.RequestCtx
- app.IsChild() will be available on the package layer
// func (app *App) IsChild() bool {}
func IsChild() bool {}
🧹 Updates
- c.Send() now contains a strong typed signature accepting a single []byte type
Other outgoing Send methods also return an error to comply with the new Handler signature
// func (c *Ctx) Send(bodies ...interface{}) {}
func (c *Ctx) Send(body []byte) error {}
// func (c *Ctx) SendStatus(status int) {}
func (c *Ctx) SendStatus(status int) error {}
// func (c *Ctx) SendString(body string) {}
func (c *Ctx) SendString(body string) error {}
// func (c *Ctx) SendStream(stream io.Reader, size ...int) {}
func (c *Ctx) SendStream(stream io.Reader, size ...int) error {}
- c.Redirect() now returns an error
// func (c *Ctx) Redirect(location string, status ...int) {}
func (c *Ctx) Redirect(location string, status ...int) error {}
- c.FormValue() now supports the optional
defaultValue
argument
// func (c *Ctx) FormValue(key string) string {}
func (c *Ctx) FormValue(key string, defaultValue ...string) string {}
⚠ Removed
- c.SendBytes() will be removed and is replaced by c.Send
// func (c *Ctx) SendBytes(body []byte) {}
- c.Error() will be removed because errors can be accessed using the error return in c.Next() error
// func (c *Ctx) Error() error {}
🔥 New
- c.Request() is a replacing method to access
*fasthttp.Request
.
// c.Fasthttp.Request.Header.Peek("x-version")
c.Request().Header.Peek("x-version")
- c.Response() is a replacing method to access
*fasthttp.Response
.
// c.Fasthttp.Response.Header.Peek("x-version")
c.Response().Header.Peek("x-version")
- app.Config.ErrorHandler will replace the app.Settings.ErrorHandler to override the default error handler.
app := fiber.New(fiber.Config{
ErrorHandler: func(c *fiber.Ctx, err error) error {
return c.Status(404).SendString("hi, i'm an custom error")
},
})
app.Get("/", func(c *fiber.Ctx) error {
return c.SendFile("../there/is/nothing/here")
})
- Config.ProxyHeader will enable
c.IP()
to return the value of the given header key. By defaultc.IP()
will return the Remote IP from the tcp connection, this property can be useful if you are behind a load balancer e.g. X-Forwarded-*.
app := fiber.New(fiber.Config{
ProxyHeader: "CF-Connecting-IP",
})
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString(c.IP()) // value from CF-Connecting-IP header
})
- Config.GETOnly rejects all non-GET requests if set to true. This option is useful as anti-DoS protection for servers accepting only GET requests and will return an
ErrMethodNotAllowed
to the error handler. The request size is limited by ReadBufferSize if GETOnly is set. Server accepts all the requests by default.
app := fiber.New(fiber.Config{
GETOnly: true,
})
app.Post("/", func(c *fiber.Ctx) error {
return c.SendString("This method is not allowed")
})
🚀 Routing
- The logic for parsing the route now better recognizes the parts which are not parameters, so the parameter can be placed anywhere, it is only important that the normal non-optional parameters are terminated by a delimiter character:
// Route
app.Get("/test::param/", handler)
// GET /test:fiber/
// Route
app.Get("/shop/product/color::color/size::size", handler)
// GET /shop/product/color:blue/size:xs
// Route
app.Get("/@:name", handler)
// GET /@Fiber
- Added support for the plus parameter, this is greedy like the wildcard parameter with the difference that it is required:
// Route
app.Get("/config/+.json", func(c *fiber.Ctx) error {
ctx.Params("+1") // abc
ctx.Params("+") // abc
})
// GET /config/abc.json // match
// GET /config/.json // no match
- Support for multiple wildcard and plus parameters has been added, they can now be accessed via wildcard or plus character with the counter in the route or normally for the first as in the current fiber version:
// GET /customer/v1/cart/proxy
app.Get("/*v1*/proxy", func(c *fiber.Ctx) error {
c.Params("*") // customer/
c.Params("*1") // customer/
c.Params("*2") // /cart
})
📦 Middleware
- github.com/gofiber/fiber/v2/middleware/basicauth
- github.com/gofiber/fiber/v2/middleware/compress
- github.com/gofiber/fiber/v2/middleware/cors
- github.com/gofiber/fiber/v2/middleware/csrf
- github.com/gofiber/fiber/v2/middleware/favicon
- github.com/gofiber/fiber/v2/middleware/filesystem
- github.com/gofiber/fiber/v2/middleware/limiter
- github.com/gofiber/fiber/v2/middleware/logger
- github.com/gofiber/fiber/v2/middleware/pprof
- github.com/gofiber/fiber/v2/middleware/proxy
- github.com/gofiber/fiber/v2/middleware/recover
- github.com/gofiber/fiber/v2/middleware/requestid
- github.com/gofiber/fiber/v2/middleware/timeout
🚀 Improvements
- The new version will use the segmentio/encoding package to encode JSON, this will improve performance drastically.
// v1.14.x
Benchmark_Ctx_JSON-16 4596667 260 ns/op 64 B/op 2 allocs/op
Benchmark_Ctx_JSON-16 4603731 259 ns/op 64 B/op 2 allocs/op
Benchmark_Ctx_JSON-16 4652700 259 ns/op 64 B/op 2 allocs/op
Benchmark_Ctx_JSON-16 4598620 259 ns/op 64 B/op 2 allocs/op
// v2.0.0
Benchmark_Ctx_JSON-16 7186842 165 ns/op 64 B/op 2 allocs/op
Benchmark_Ctx_JSON-16 7214056 164 ns/op 64 B/op 2 allocs/op
Benchmark_Ctx_JSON-16 7227295 164 ns/op 64 B/op 2 allocs/op
Benchmark_Ctx_JSON-16 7227291 165 ns/op 64 B/op 2 allocs/op
405 Method Not Allowed
will be passed to the global error handler, in the old version this beha...
v1.14.6
v2
will be released on 15 September 2020!
Please visit https://gofiber.io/v2 for more information.