mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-31 11:52:41 +00:00
v3: remove deprecations
This commit is contained in:
parent
c7f45ec38e
commit
edd89de2d6
12
app.go
12
app.go
@ -163,12 +163,6 @@ type Config struct {
|
||||
// Default: false
|
||||
UnescapePath bool `json:"unescape_path"`
|
||||
|
||||
// Enable or disable ETag header generation, since both weak and strong etags are generated
|
||||
// using the same hashing method (CRC-32). Weak ETags are the default when enabled.
|
||||
//
|
||||
// Default: false
|
||||
ETag bool `json:"etag"`
|
||||
|
||||
// Max body size that the server accepts.
|
||||
// -1 will decline any body size
|
||||
//
|
||||
@ -475,12 +469,6 @@ func New(config ...Config) *App {
|
||||
app.config = config[0]
|
||||
}
|
||||
|
||||
if app.config.ETag {
|
||||
if !IsChild() {
|
||||
fmt.Println("[Warning] Config.ETag is deprecated since v2.0.6, please use 'middleware/etag'.")
|
||||
}
|
||||
}
|
||||
|
||||
// Override default values
|
||||
if app.config.BodyLimit == 0 {
|
||||
app.config.BodyLimit = DefaultBodyLimit
|
||||
|
24
app_test.go
24
app_test.go
@ -1256,30 +1256,6 @@ func Benchmark_AcquireCtx(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
// go test -v -run=^$ -bench=Benchmark_App_ETag -benchmem -count=4
|
||||
func Benchmark_App_ETag(b *testing.B) {
|
||||
app := New()
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.Send([]byte("Hello, World!"))
|
||||
for n := 0; n < b.N; n++ {
|
||||
setETag(c, false)
|
||||
}
|
||||
utils.AssertEqual(b, `"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag)))
|
||||
}
|
||||
|
||||
// go test -v -run=^$ -bench=Benchmark_App_ETag_Weak -benchmem -count=4
|
||||
func Benchmark_App_ETag_Weak(b *testing.B) {
|
||||
app := New()
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.Send([]byte("Hello, World!"))
|
||||
for n := 0; n < b.N; n++ {
|
||||
setETag(c, true)
|
||||
}
|
||||
utils.AssertEqual(b, `W/"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag)))
|
||||
}
|
||||
|
||||
// go test -run Test_NewError
|
||||
func Test_NewError(t *testing.T) {
|
||||
err := NewError(StatusForbidden, "permission denied")
|
||||
|
50
helpers.go
50
helpers.go
@ -7,8 +7,6 @@ package fiber
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
@ -175,52 +173,6 @@ func defaultString(value string, defaultValue []string) string {
|
||||
|
||||
const normalizedHeaderETag = "Etag"
|
||||
|
||||
// Generate and set ETag header to response
|
||||
func setETag(c *Ctx, weak bool) {
|
||||
// Don't generate ETags for invalid responses
|
||||
if c.fasthttp.Response.StatusCode() != StatusOK {
|
||||
return
|
||||
}
|
||||
body := c.fasthttp.Response.Body()
|
||||
// Skips ETag if no response body is present
|
||||
if len(body) == 0 {
|
||||
return
|
||||
}
|
||||
// Get ETag header from request
|
||||
clientEtag := c.Get(HeaderIfNoneMatch)
|
||||
|
||||
// Generate ETag for response
|
||||
crc32q := crc32.MakeTable(0xD5828281)
|
||||
etag := fmt.Sprintf("\"%d-%v\"", len(body), crc32.Checksum(body, crc32q))
|
||||
|
||||
// Enable weak tag
|
||||
if weak {
|
||||
etag = "W/" + etag
|
||||
}
|
||||
|
||||
// Check if client's ETag is weak
|
||||
if strings.HasPrefix(clientEtag, "W/") {
|
||||
// Check if server's ETag is weak
|
||||
if clientEtag[2:] == etag || clientEtag[2:] == etag[2:] {
|
||||
// W/1 == 1 || W/1 == W/1
|
||||
_ = c.SendStatus(StatusNotModified)
|
||||
c.fasthttp.ResetBody()
|
||||
return
|
||||
}
|
||||
// W/1 != W/2 || W/1 != 2
|
||||
c.setCanonical(normalizedHeaderETag, etag)
|
||||
return
|
||||
}
|
||||
if strings.Contains(clientEtag, etag) {
|
||||
// 1 == 1
|
||||
_ = c.SendStatus(StatusNotModified)
|
||||
c.fasthttp.ResetBody()
|
||||
return
|
||||
}
|
||||
// 1 != 2
|
||||
c.setCanonical(normalizedHeaderETag, etag)
|
||||
}
|
||||
|
||||
func getGroupPath(prefix, path string) string {
|
||||
if len(path) == 0 || path == "/" {
|
||||
return prefix
|
||||
@ -624,8 +576,6 @@ const (
|
||||
HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only"
|
||||
HeaderCrossOriginResourcePolicy = "Cross-Origin-Resource-Policy"
|
||||
HeaderExpectCT = "Expect-CT"
|
||||
// Deprecated: use HeaderPermissionsPolicy instead
|
||||
HeaderFeaturePolicy = "Feature-Policy"
|
||||
HeaderPermissionsPolicy = "Permissions-Policy"
|
||||
HeaderPublicKeyPins = "Public-Key-Pins"
|
||||
HeaderPublicKeyPinsReportOnly = "Public-Key-Pins-Report-Only"
|
||||
|
@ -16,89 +16,6 @@ import (
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// go test -v -run=Test_Utils_ -count=3
|
||||
func Test_Utils_ETag(t *testing.T) {
|
||||
app := New()
|
||||
t.Run("Not Status OK", func(t *testing.T) {
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
c.Status(201)
|
||||
setETag(c, false)
|
||||
utils.AssertEqual(t, "", string(c.Response().Header.Peek(HeaderETag)))
|
||||
})
|
||||
|
||||
t.Run("No Body", func(t *testing.T) {
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
setETag(c, false)
|
||||
utils.AssertEqual(t, "", string(c.Response().Header.Peek(HeaderETag)))
|
||||
})
|
||||
|
||||
t.Run("Has HeaderIfNoneMatch", func(t *testing.T) {
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
c.Request().Header.Set(HeaderIfNoneMatch, `"13-1831710635"`)
|
||||
setETag(c, false)
|
||||
utils.AssertEqual(t, 304, c.Response().StatusCode())
|
||||
utils.AssertEqual(t, "", string(c.Response().Header.Peek(HeaderETag)))
|
||||
utils.AssertEqual(t, "", string(c.Response().Body()))
|
||||
})
|
||||
|
||||
t.Run("No HeaderIfNoneMatch", func(t *testing.T) {
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
setETag(c, false)
|
||||
utils.AssertEqual(t, `"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag)))
|
||||
})
|
||||
}
|
||||
|
||||
// go test -v -run=^$ -bench=Benchmark_App_ETag -benchmem -count=4
|
||||
func Benchmark_Utils_ETag(b *testing.B) {
|
||||
app := New()
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
for n := 0; n < b.N; n++ {
|
||||
setETag(c, false)
|
||||
}
|
||||
utils.AssertEqual(b, `"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag)))
|
||||
}
|
||||
|
||||
// go test -v -run=Test_Utils_ETag_Weak -count=1
|
||||
func Test_Utils_ETag_Weak(t *testing.T) {
|
||||
app := New()
|
||||
t.Run("Set Weak", func(t *testing.T) {
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
setETag(c, true)
|
||||
utils.AssertEqual(t, `W/"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag)))
|
||||
})
|
||||
|
||||
t.Run("Match Weak ETag", func(t *testing.T) {
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
c.Request().Header.Set(HeaderIfNoneMatch, `W/"13-1831710635"`)
|
||||
setETag(c, true)
|
||||
utils.AssertEqual(t, 304, c.Response().StatusCode())
|
||||
utils.AssertEqual(t, "", string(c.Response().Header.Peek(HeaderETag)))
|
||||
utils.AssertEqual(t, "", string(c.Response().Body()))
|
||||
})
|
||||
|
||||
t.Run("Not Match Weak ETag", func(t *testing.T) {
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
c.Request().Header.Set(HeaderIfNoneMatch, `W/"13-1831710635xx"`)
|
||||
setETag(c, true)
|
||||
utils.AssertEqual(t, `W/"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag)))
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Utils_UniqueRouteStack(t *testing.T) {
|
||||
route1 := &Route{}
|
||||
route2 := &Route{}
|
||||
@ -127,18 +44,6 @@ func Test_Utils_UniqueRouteStack(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
// go test -v -run=^$ -bench=Benchmark_App_ETag_Weak -benchmem -count=4
|
||||
func Benchmark_Utils_ETag_Weak(b *testing.B) {
|
||||
app := New()
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
for n := 0; n < b.N; n++ {
|
||||
setETag(c, true)
|
||||
}
|
||||
utils.AssertEqual(b, `W/"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag)))
|
||||
}
|
||||
|
||||
func Test_Utils_getGroupPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
res := getGroupPath("/v1", "/")
|
||||
|
15
middleware/cache/config.go
vendored
15
middleware/cache/config.go
vendored
@ -1,7 +1,6 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
@ -49,12 +48,6 @@ type Config struct {
|
||||
// Default: an in memory store for this process only
|
||||
Storage fiber.Storage
|
||||
|
||||
// Deprecated, use Storage instead
|
||||
Store fiber.Storage
|
||||
|
||||
// Deprecated, use KeyGenerator instead
|
||||
Key func(*fiber.Ctx) string
|
||||
|
||||
// allows you to store additional headers generated by next middlewares & handler
|
||||
//
|
||||
// Default: false
|
||||
@ -94,14 +87,6 @@ func configDefault(config ...Config) Config {
|
||||
cfg := config[0]
|
||||
|
||||
// Set default values
|
||||
if cfg.Store != nil {
|
||||
fmt.Println("[CACHE] Store is deprecated, please use Storage")
|
||||
cfg.Storage = cfg.Store
|
||||
}
|
||||
if cfg.Key != nil {
|
||||
fmt.Println("[CACHE] Key is deprecated, please use KeyGenerator")
|
||||
cfg.KeyGenerator = cfg.Key
|
||||
}
|
||||
if cfg.Next == nil {
|
||||
cfg.Next = ConfigDefault.Next
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package csrf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/textproto"
|
||||
"strings"
|
||||
"time"
|
||||
@ -78,15 +77,6 @@ type Config struct {
|
||||
// Optional. Default: utils.UUID
|
||||
KeyGenerator func() string
|
||||
|
||||
// Deprecated, please use Expiration
|
||||
CookieExpires time.Duration
|
||||
|
||||
// Deprecated, please use Cookie* related fields
|
||||
Cookie *fiber.Cookie
|
||||
|
||||
// Deprecated, please use KeyLookup
|
||||
TokenLookup string
|
||||
|
||||
// ErrorHandler is executed when an error is returned from fiber.Handler.
|
||||
//
|
||||
// Optional. Default: DefaultErrorHandler
|
||||
@ -123,31 +113,6 @@ func configDefault(config ...Config) Config {
|
||||
cfg := config[0]
|
||||
|
||||
// Set default values
|
||||
if cfg.TokenLookup != "" {
|
||||
fmt.Println("[CSRF] TokenLookup is deprecated, please use KeyLookup")
|
||||
cfg.KeyLookup = cfg.TokenLookup
|
||||
}
|
||||
if int(cfg.CookieExpires.Seconds()) > 0 {
|
||||
fmt.Println("[CSRF] CookieExpires is deprecated, please use Expiration")
|
||||
cfg.Expiration = cfg.CookieExpires
|
||||
}
|
||||
if cfg.Cookie != nil {
|
||||
fmt.Println("[CSRF] Cookie is deprecated, please use Cookie* related fields")
|
||||
if cfg.Cookie.Name != "" {
|
||||
cfg.CookieName = cfg.Cookie.Name
|
||||
}
|
||||
if cfg.Cookie.Domain != "" {
|
||||
cfg.CookieDomain = cfg.Cookie.Domain
|
||||
}
|
||||
if cfg.Cookie.Path != "" {
|
||||
cfg.CookiePath = cfg.Cookie.Path
|
||||
}
|
||||
cfg.CookieSecure = cfg.Cookie.Secure
|
||||
cfg.CookieHTTPOnly = cfg.Cookie.HTTPOnly
|
||||
if cfg.Cookie.SameSite != "" {
|
||||
cfg.CookieSameSite = cfg.Cookie.SameSite
|
||||
}
|
||||
}
|
||||
if cfg.KeyLookup == "" {
|
||||
cfg.KeyLookup = ConfigDefault.KeyLookup
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package limiter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
@ -57,15 +56,6 @@ type Config struct {
|
||||
//
|
||||
// Default: a new Fixed Window Rate Limiter
|
||||
LimiterMiddleware LimiterHandler
|
||||
|
||||
// DEPRECATED: Use Expiration instead
|
||||
Duration time.Duration
|
||||
|
||||
// DEPRECATED, use Storage instead
|
||||
Store fiber.Storage
|
||||
|
||||
// DEPRECATED, use KeyGenerator instead
|
||||
Key func(*fiber.Ctx) string
|
||||
}
|
||||
|
||||
// ConfigDefault is the default config
|
||||
@ -94,18 +84,6 @@ func configDefault(config ...Config) Config {
|
||||
cfg := config[0]
|
||||
|
||||
// Set default values
|
||||
if int(cfg.Duration.Seconds()) > 0 {
|
||||
fmt.Println("[LIMITER] Duration is deprecated, please use Expiration")
|
||||
cfg.Expiration = cfg.Duration
|
||||
}
|
||||
if cfg.Key != nil {
|
||||
fmt.Println("[LIMITER] Key is deprecated, please us KeyGenerator")
|
||||
cfg.KeyGenerator = cfg.Key
|
||||
}
|
||||
if cfg.Store != nil {
|
||||
fmt.Println("[LIMITER] Store is deprecated, please use Storage")
|
||||
cfg.Storage = cfg.Store
|
||||
}
|
||||
if cfg.Next == nil {
|
||||
cfg.Next = ConfigDefault.Next
|
||||
}
|
||||
|
@ -42,8 +42,6 @@ const (
|
||||
TagBytesReceived = "bytesReceived"
|
||||
TagRoute = "route"
|
||||
TagError = "error"
|
||||
// DEPRECATED: Use TagReqHeader instead
|
||||
TagHeader = "header:"
|
||||
TagReqHeader = "reqHeader:"
|
||||
TagRespHeader = "respHeader:"
|
||||
TagLocals = "locals:"
|
||||
@ -286,8 +284,6 @@ func New(config ...Config) fiber.Handler {
|
||||
switch {
|
||||
case strings.HasPrefix(tag, TagReqHeader):
|
||||
return buf.WriteString(c.Get(tag[10:]))
|
||||
case strings.HasPrefix(tag, TagHeader):
|
||||
return buf.WriteString(c.Get(tag[7:]))
|
||||
case strings.HasPrefix(tag, TagRespHeader):
|
||||
return buf.WriteString(c.GetRespHeader(tag[11:]))
|
||||
case strings.HasPrefix(tag, TagQuery):
|
||||
|
@ -3,7 +3,6 @@ package proxy
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
@ -12,12 +11,6 @@ import (
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// New is deprecated
|
||||
func New(config Config) fiber.Handler {
|
||||
fmt.Println("proxy.New is deprecated, please use proxy.Balancer instead")
|
||||
return Balancer(config)
|
||||
}
|
||||
|
||||
// Balancer creates a load balancer among multiple upstream servers
|
||||
func Balancer(config Config) fiber.Handler {
|
||||
// Set default config
|
||||
|
@ -1,7 +1,6 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -49,9 +48,6 @@ type Config struct {
|
||||
// Optional. Default value utils.UUIDv4
|
||||
KeyGenerator func() string
|
||||
|
||||
// Deprecated, please use KeyLookup
|
||||
CookieName string
|
||||
|
||||
// Source defines where to obtain the session id
|
||||
source Source
|
||||
|
||||
@ -90,10 +86,6 @@ func configDefault(config ...Config) Config {
|
||||
if int(cfg.Expiration.Seconds()) <= 0 {
|
||||
cfg.Expiration = ConfigDefault.Expiration
|
||||
}
|
||||
if cfg.CookieName != "" {
|
||||
fmt.Println("[session] CookieName is deprecated, please use KeyLookup")
|
||||
cfg.KeyLookup = fmt.Sprintf("cookie:%s", cfg.CookieName)
|
||||
}
|
||||
if cfg.KeyLookup == "" {
|
||||
cfg.KeyLookup = ConfigDefault.KeyLookup
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
|
||||
// Router defines all router handle interface includes app and group router.
|
||||
type Router interface {
|
||||
Use(args ...any) Router
|
||||
Use(args ...interface{}) Router
|
||||
|
||||
Get(path string, handlers ...Handler) Router
|
||||
Head(path string, handlers ...Handler) Router
|
||||
@ -156,16 +156,12 @@ func (app *App) handler(rctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
|
||||
// Find match in stack
|
||||
match, err := app.next(c)
|
||||
_, err := app.next(c)
|
||||
if err != nil {
|
||||
if catch := c.app.ErrorHandler(c, err); catch != nil {
|
||||
_ = c.SendStatus(StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
// Generate ETag if enabled
|
||||
if match && app.config.ETag {
|
||||
setETag(c, false)
|
||||
}
|
||||
|
||||
// Release Ctx
|
||||
app.ReleaseCtx(c)
|
||||
|
@ -292,21 +292,6 @@ func Test_Ensure_Router_Interface_Implementation(t *testing.T) {
|
||||
utils.AssertEqual(t, true, ok)
|
||||
}
|
||||
|
||||
func Test_Router_Handler_SetETag(t *testing.T) {
|
||||
app := New()
|
||||
app.config.ETag = true
|
||||
|
||||
app.Get("/", func(c *Ctx) error {
|
||||
return c.SendString("Hello, World!")
|
||||
})
|
||||
|
||||
c := &fasthttp.RequestCtx{}
|
||||
|
||||
app.Handler()(c)
|
||||
|
||||
utils.AssertEqual(t, `"13-1831710635"`, string(c.Response.Header.Peek(HeaderETag)))
|
||||
}
|
||||
|
||||
func Test_Router_Handler_Catch_Error(t *testing.T) {
|
||||
app := New()
|
||||
app.config.ErrorHandler = func(ctx *Ctx, err error) error {
|
||||
|
@ -1,18 +0,0 @@
|
||||
package utils
|
||||
|
||||
// #nosec G103
|
||||
// DEPRECATED, Please use UnsafeString instead
|
||||
func GetString(b []byte) string {
|
||||
return UnsafeString(b)
|
||||
}
|
||||
|
||||
// #nosec G103
|
||||
// DEPRECATED, Please use UnsafeBytes instead
|
||||
func GetBytes(s string) []byte {
|
||||
return UnsafeBytes(s)
|
||||
}
|
||||
|
||||
// DEPRECATED, Please use CopyString instead
|
||||
func ImmutableString(s string) string {
|
||||
return CopyString(s)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user