mirror of https://github.com/gofiber/fiber.git
Use utils Trim functions instead of the strings/bytes functions (#3087)
* Use utils Trim functions instead of the strings/bytes functions * rename Test and Benchmark functions with same namepull/3090/head
parent
e2cd1000ea
commit
fadedcb5be
|
@ -8,7 +8,6 @@ import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/gofiber/utils/v2"
|
"github.com/gofiber/utils/v2"
|
||||||
|
@ -68,7 +67,7 @@ func (r *Response) Body() []byte {
|
||||||
|
|
||||||
// String method returns the body of the server response as String.
|
// String method returns the body of the server response as String.
|
||||||
func (r *Response) String() string {
|
func (r *Response) String() string {
|
||||||
return strings.TrimSpace(string(r.Body()))
|
return utils.Trim(string(r.Body()), ' ')
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON method will unmarshal body to json.
|
// JSON method will unmarshal body to json.
|
||||||
|
|
10
ctx.go
10
ctx.go
|
@ -778,7 +778,7 @@ iploop:
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
s := strings.TrimRight(headerValue[i:j], " ")
|
s := utils.TrimRight(headerValue[i:j], ' ')
|
||||||
|
|
||||||
if c.app.config.EnableIPValidation {
|
if c.app.config.EnableIPValidation {
|
||||||
// Skip validation if IP is clearly not IPv4/IPv6, otherwise validate without allocations
|
// Skip validation if IP is clearly not IPv4/IPv6, otherwise validate without allocations
|
||||||
|
@ -828,7 +828,7 @@ func (c *DefaultCtx) extractIPFromHeader(header string) string {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
s := strings.TrimRight(headerValue[i:j], " ")
|
s := utils.TrimRight(headerValue[i:j], ' ')
|
||||||
|
|
||||||
if c.app.config.EnableIPValidation {
|
if c.app.config.EnableIPValidation {
|
||||||
if (!v6 && !v4) || (v6 && !utils.IsIPv6(s)) || (v4 && !utils.IsIPv4(s)) {
|
if (!v6 && !v4) || (v6 && !utils.IsIPv6(s)) || (v4 && !utils.IsIPv4(s)) {
|
||||||
|
@ -862,7 +862,7 @@ func (c *DefaultCtx) Is(extension string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.HasPrefix(
|
return strings.HasPrefix(
|
||||||
strings.TrimLeft(utils.UnsafeString(c.fasthttp.Request.Header.ContentType()), " "),
|
utils.TrimLeft(utils.UnsafeString(c.fasthttp.Request.Header.ContentType()), ' '),
|
||||||
extensionHeader,
|
extensionHeader,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -939,7 +939,7 @@ func (c *DefaultCtx) Links(link ...string) {
|
||||||
bb.WriteString(`; rel="` + link[i] + `",`)
|
bb.WriteString(`; rel="` + link[i] + `",`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.setCanonical(HeaderLink, strings.TrimRight(c.app.getString(bb.Bytes()), ","))
|
c.setCanonical(HeaderLink, utils.TrimRight(c.app.getString(bb.Bytes()), ','))
|
||||||
bytebufferpool.Put(bb)
|
bytebufferpool.Put(bb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1810,7 +1810,7 @@ func (c *DefaultCtx) configDependentPaths() {
|
||||||
}
|
}
|
||||||
// If StrictRouting is disabled, we strip all trailing slashes
|
// If StrictRouting is disabled, we strip all trailing slashes
|
||||||
if !c.app.config.StrictRouting && len(c.detectionPathBuffer) > 1 && c.detectionPathBuffer[len(c.detectionPathBuffer)-1] == '/' {
|
if !c.app.config.StrictRouting && len(c.detectionPathBuffer) > 1 && c.detectionPathBuffer[len(c.detectionPathBuffer)-1] == '/' {
|
||||||
c.detectionPathBuffer = bytes.TrimRight(c.detectionPathBuffer, "/")
|
c.detectionPathBuffer = utils.TrimRight(c.detectionPathBuffer, '/')
|
||||||
}
|
}
|
||||||
c.detectionPath = c.app.getString(c.detectionPathBuffer)
|
c.detectionPath = c.app.getString(c.detectionPathBuffer)
|
||||||
|
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module github.com/gofiber/fiber/v3
|
||||||
go 1.21
|
go 1.21
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gofiber/utils/v2 v2.0.0-beta.5
|
github.com/gofiber/utils/v2 v2.0.0-beta.6
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/mattn/go-colorable v0.1.13
|
github.com/mattn/go-colorable v0.1.13
|
||||||
github.com/mattn/go-isatty v0.0.20
|
github.com/mattn/go-isatty v0.0.20
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -2,8 +2,8 @@ github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1
|
||||||
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/gofiber/utils/v2 v2.0.0-beta.5 h1:zbDIU8gVAlZ2Ak9Fk8APlis4S7wUiQFbcvv6UASkm6A=
|
github.com/gofiber/utils/v2 v2.0.0-beta.6 h1:ED62bOmpRXdgviPlfTmf0Q+AXzhaTUAFtdWjgx+XkYI=
|
||||||
github.com/gofiber/utils/v2 v2.0.0-beta.5/go.mod h1:3Kz8Px3jInKFvqxDzDeoSygwEOO+3uyubTmUa6PqY+0=
|
github.com/gofiber/utils/v2 v2.0.0-beta.6/go.mod h1:3Kz8Px3jInKFvqxDzDeoSygwEOO+3uyubTmUa6PqY+0=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||||
|
|
|
@ -222,7 +222,7 @@ func getGroupPath(prefix, path string) string {
|
||||||
path = "/" + path
|
path = "/" + path
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.TrimRight(prefix, "/") + path
|
return utils.TrimRight(prefix, '/') + path
|
||||||
}
|
}
|
||||||
|
|
||||||
// acceptsOffer This function determines if an offer matches a given specification.
|
// acceptsOffer This function determines if an offer matches a given specification.
|
||||||
|
@ -336,7 +336,7 @@ func getSplicedStrList(headerValue string, dst []string) []string {
|
||||||
dst = make([]string, len(dst)+(len(dst)>>1)+2)
|
dst = make([]string, len(dst)+(len(dst)>>1)+2)
|
||||||
copy(dst, oldSlice)
|
copy(dst, oldSlice)
|
||||||
}
|
}
|
||||||
dst[insertIndex] = strings.TrimLeft(headerValue[lastElementEndsAt:index], " ")
|
dst[insertIndex] = utils.TrimLeft(headerValue[lastElementEndsAt:index], ' ')
|
||||||
lastElementEndsAt = uint8(index + 1)
|
lastElementEndsAt = uint8(index + 1)
|
||||||
insertIndex++
|
insertIndex++
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ func forEachMediaRange(header []byte, functor func([]byte)) {
|
||||||
|
|
||||||
for len(header) > 0 {
|
for len(header) > 0 {
|
||||||
n := 0
|
n := 0
|
||||||
header = bytes.TrimLeft(header, " ")
|
header = utils.TrimLeft(header, ' ')
|
||||||
quotes := 0
|
quotes := 0
|
||||||
escaping := false
|
escaping := false
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ func getOffer(header []byte, isAccepted func(spec, offer string, specParams head
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
spec = bytes.TrimSpace(spec)
|
spec = utils.Trim(spec, ' ')
|
||||||
|
|
||||||
// Determine specificity
|
// Determine specificity
|
||||||
var specificity int
|
var specificity int
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/tinylib/msgp/msgp"
|
"github.com/tinylib/msgp/msgp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_MarshalUnmarshalitem(t *testing.T) {
|
func Test_Cache_MarshalUnmarshalitem(t *testing.T) {
|
||||||
v := item{}
|
v := item{}
|
||||||
bts, err := v.MarshalMsg(nil)
|
bts, err := v.MarshalMsg(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -31,7 +31,7 @@ func Test_MarshalUnmarshalitem(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_MarshalMsgitem(b *testing.B) {
|
func Benchmark_Cache_MarshalMsgitem(b *testing.B) {
|
||||||
v := item{}
|
v := item{}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
@ -40,7 +40,7 @@ func Benchmark_MarshalMsgitem(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_AppendMsgitem(b *testing.B) {
|
func Benchmark_Cache_AppendMsgitem(b *testing.B) {
|
||||||
v := item{}
|
v := item{}
|
||||||
bts := make([]byte, 0, v.Msgsize())
|
bts := make([]byte, 0, v.Msgsize())
|
||||||
bts, _ = v.MarshalMsg(bts[0:0])
|
bts, _ = v.MarshalMsg(bts[0:0])
|
||||||
|
@ -52,7 +52,7 @@ func Benchmark_AppendMsgitem(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_Unmarshalitem(b *testing.B) {
|
func Benchmark_Cache_Unmarshalitem(b *testing.B) {
|
||||||
v := item{}
|
v := item{}
|
||||||
bts, _ := v.MarshalMsg(nil)
|
bts, _ := v.MarshalMsg(nil)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
"github.com/gofiber/fiber/v3/log"
|
"github.com/gofiber/fiber/v3/log"
|
||||||
|
"github.com/gofiber/utils/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// New creates a new middleware handler
|
// New creates a new middleware handler
|
||||||
|
@ -44,7 +45,7 @@ func New(config ...Config) fiber.Handler {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if i := strings.Index(origin, "://*."); i != -1 {
|
if i := strings.Index(origin, "://*."); i != -1 {
|
||||||
trimmedOrigin := strings.TrimSpace(origin[:i+3] + origin[i+4:])
|
trimmedOrigin := utils.Trim(origin[:i+3]+origin[i+4:], ' ')
|
||||||
isValid, normalizedOrigin := normalizeOrigin(trimmedOrigin)
|
isValid, normalizedOrigin := normalizeOrigin(trimmedOrigin)
|
||||||
if !isValid {
|
if !isValid {
|
||||||
panic("[CORS] Invalid origin format in configuration: " + trimmedOrigin)
|
panic("[CORS] Invalid origin format in configuration: " + trimmedOrigin)
|
||||||
|
@ -52,7 +53,7 @@ func New(config ...Config) fiber.Handler {
|
||||||
sd := subdomain{prefix: normalizedOrigin[:i+3], suffix: normalizedOrigin[i+3:]}
|
sd := subdomain{prefix: normalizedOrigin[:i+3], suffix: normalizedOrigin[i+3:]}
|
||||||
allowSOrigins = append(allowSOrigins, sd)
|
allowSOrigins = append(allowSOrigins, sd)
|
||||||
} else {
|
} else {
|
||||||
trimmedOrigin := strings.TrimSpace(origin)
|
trimmedOrigin := utils.Trim(origin, ' ')
|
||||||
isValid, normalizedOrigin := normalizeOrigin(trimmedOrigin)
|
isValid, normalizedOrigin := normalizeOrigin(trimmedOrigin)
|
||||||
if !isValid {
|
if !isValid {
|
||||||
panic("[CORS] Invalid origin format in configuration: " + trimmedOrigin)
|
panic("[CORS] Invalid origin format in configuration: " + trimmedOrigin)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
|
"github.com/gofiber/utils/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -62,7 +63,7 @@ func New(config ...Config) fiber.Handler {
|
||||||
|
|
||||||
for _, origin := range cfg.TrustedOrigins {
|
for _, origin := range cfg.TrustedOrigins {
|
||||||
if i := strings.Index(origin, "://*."); i != -1 {
|
if i := strings.Index(origin, "://*."); i != -1 {
|
||||||
trimmedOrigin := strings.TrimSpace(origin[:i+3] + origin[i+4:])
|
trimmedOrigin := utils.Trim(origin[:i+3]+origin[i+4:], ' ')
|
||||||
isValid, normalizedOrigin := normalizeOrigin(trimmedOrigin)
|
isValid, normalizedOrigin := normalizeOrigin(trimmedOrigin)
|
||||||
if !isValid {
|
if !isValid {
|
||||||
panic("[CSRF] Invalid origin format in configuration:" + origin)
|
panic("[CSRF] Invalid origin format in configuration:" + origin)
|
||||||
|
@ -70,7 +71,7 @@ func New(config ...Config) fiber.Handler {
|
||||||
sd := subdomain{prefix: normalizedOrigin[:i+3], suffix: normalizedOrigin[i+3:]}
|
sd := subdomain{prefix: normalizedOrigin[:i+3], suffix: normalizedOrigin[i+3:]}
|
||||||
trustedSubOrigins = append(trustedSubOrigins, sd)
|
trustedSubOrigins = append(trustedSubOrigins, sd)
|
||||||
} else {
|
} else {
|
||||||
trimmedOrigin := strings.TrimSpace(origin)
|
trimmedOrigin := utils.Trim(origin, ' ')
|
||||||
isValid, normalizedOrigin := normalizeOrigin(trimmedOrigin)
|
isValid, normalizedOrigin := normalizeOrigin(trimmedOrigin)
|
||||||
if !isValid {
|
if !isValid {
|
||||||
panic("[CSRF] Invalid origin format in configuration:" + origin)
|
panic("[CSRF] Invalid origin format in configuration:" + origin)
|
||||||
|
|
|
@ -139,7 +139,7 @@ func Test_CSRF_WithSession(t *testing.T) {
|
||||||
h(ctx)
|
h(ctx)
|
||||||
token := string(ctx.Response.Header.Peek(fiber.HeaderSetCookie))
|
token := string(ctx.Response.Header.Peek(fiber.HeaderSetCookie))
|
||||||
for _, header := range strings.Split(token, ";") {
|
for _, header := range strings.Split(token, ";") {
|
||||||
if strings.Split(strings.TrimSpace(header), "=")[0] == ConfigDefault.CookieName {
|
if strings.Split(utils.Trim(header, ' '), "=")[0] == ConfigDefault.CookieName {
|
||||||
token = strings.Split(header, "=")[1]
|
token = strings.Split(header, "=")[1]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ func Test_CSRF_ExpiredToken_WithSession(t *testing.T) {
|
||||||
h(ctx)
|
h(ctx)
|
||||||
token := string(ctx.Response.Header.Peek(fiber.HeaderSetCookie))
|
token := string(ctx.Response.Header.Peek(fiber.HeaderSetCookie))
|
||||||
for _, header := range strings.Split(token, ";") {
|
for _, header := range strings.Split(token, ";") {
|
||||||
if strings.Split(strings.TrimSpace(header), "=")[0] == ConfigDefault.CookieName {
|
if strings.Split(utils.Trim(header, ' '), "=")[0] == ConfigDefault.CookieName {
|
||||||
token = strings.Split(header, "=")[1]
|
token = strings.Split(header, "=")[1]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/tinylib/msgp/msgp"
|
"github.com/tinylib/msgp/msgp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_MarshalUnmarshalitem(t *testing.T) {
|
func Test_Csrf_MarshalUnmarshalitem(t *testing.T) {
|
||||||
v := item{}
|
v := item{}
|
||||||
bts, err := v.MarshalMsg(nil)
|
bts, err := v.MarshalMsg(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -31,7 +31,7 @@ func Test_MarshalUnmarshalitem(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_MarshalMsgitem(b *testing.B) {
|
func Benchmark_Csrf_MarshalMsgitem(b *testing.B) {
|
||||||
v := item{}
|
v := item{}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
@ -40,7 +40,7 @@ func Benchmark_MarshalMsgitem(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_AppendMsgitem(b *testing.B) {
|
func Benchmark_Csrf_AppendMsgitem(b *testing.B) {
|
||||||
v := item{}
|
v := item{}
|
||||||
bts := make([]byte, 0, v.Msgsize())
|
bts := make([]byte, 0, v.Msgsize())
|
||||||
bts, _ = v.MarshalMsg(bts[0:0])
|
bts, _ = v.MarshalMsg(bts[0:0])
|
||||||
|
@ -52,7 +52,7 @@ func Benchmark_AppendMsgitem(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_Unmarshalitem(b *testing.B) {
|
func Benchmark_Csrf_Unmarshalitem(b *testing.B) {
|
||||||
v := item{}
|
v := item{}
|
||||||
bts, _ := v.MarshalMsg(nil)
|
bts, _ := v.MarshalMsg(nil)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/tinylib/msgp/msgp"
|
"github.com/tinylib/msgp/msgp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_MarshalUnmarshalitem(t *testing.T) {
|
func Test_Limiter_MarshalUnmarshalitem(t *testing.T) {
|
||||||
v := item{}
|
v := item{}
|
||||||
bts, err := v.MarshalMsg(nil)
|
bts, err := v.MarshalMsg(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -31,7 +31,7 @@ func Test_MarshalUnmarshalitem(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_MarshalMsgitem(b *testing.B) {
|
func Benchmark_Limiter_MarshalMsgitem(b *testing.B) {
|
||||||
v := item{}
|
v := item{}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
@ -40,7 +40,7 @@ func Benchmark_MarshalMsgitem(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_AppendMsgitem(b *testing.B) {
|
func Benchmark_Limiter_AppendMsgitem(b *testing.B) {
|
||||||
v := item{}
|
v := item{}
|
||||||
bts := make([]byte, 0, v.Msgsize())
|
bts := make([]byte, 0, v.Msgsize())
|
||||||
bts, _ = v.MarshalMsg(bts[0:0])
|
bts, _ = v.MarshalMsg(bts[0:0])
|
||||||
|
@ -52,7 +52,7 @@ func Benchmark_AppendMsgitem(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_Unmarshalitem(b *testing.B) {
|
func Benchmark_Limiter_Unmarshalitem(b *testing.B) {
|
||||||
v := item{}
|
v := item{}
|
||||||
bts, _ := v.MarshalMsg(nil)
|
bts, _ := v.MarshalMsg(nil)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
|
"github.com/gofiber/utils/v2"
|
||||||
"github.com/valyala/fasthttp/fasthttpadaptor"
|
"github.com/valyala/fasthttp/fasthttpadaptor"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ func New(config ...Config) fiber.Handler {
|
||||||
default:
|
default:
|
||||||
// pprof index only works with trailing slash
|
// pprof index only works with trailing slash
|
||||||
if strings.HasSuffix(path, "/") {
|
if strings.HasSuffix(path, "/") {
|
||||||
path = strings.TrimRight(path, "/")
|
path = utils.TrimRight(path, '/')
|
||||||
} else {
|
} else {
|
||||||
path = prefix + "/"
|
path = prefix + "/"
|
||||||
}
|
}
|
||||||
|
|
7
mount.go
7
mount.go
|
@ -6,9 +6,10 @@ package fiber
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/gofiber/utils/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Put fields related to mounting.
|
// Put fields related to mounting.
|
||||||
|
@ -39,7 +40,7 @@ func newMountFields(app *App) *mountFields {
|
||||||
// any of the fiber's sub apps are added to the application's error handlers
|
// any of the fiber's sub apps are added to the application's error handlers
|
||||||
// to be invoked on errors that happen within the prefix route.
|
// to be invoked on errors that happen within the prefix route.
|
||||||
func (app *App) mount(prefix string, subApp *App) Router {
|
func (app *App) mount(prefix string, subApp *App) Router {
|
||||||
prefix = strings.TrimRight(prefix, "/")
|
prefix = utils.TrimRight(prefix, '/')
|
||||||
if prefix == "" {
|
if prefix == "" {
|
||||||
prefix = "/"
|
prefix = "/"
|
||||||
}
|
}
|
||||||
|
@ -69,7 +70,7 @@ func (app *App) mount(prefix string, subApp *App) Router {
|
||||||
// compose them as a single service using Mount.
|
// compose them as a single service using Mount.
|
||||||
func (grp *Group) mount(prefix string, subApp *App) Router {
|
func (grp *Group) mount(prefix string, subApp *App) Router {
|
||||||
groupPath := getGroupPath(grp.Prefix, prefix)
|
groupPath := getGroupPath(grp.Prefix, prefix)
|
||||||
groupPath = strings.TrimRight(groupPath, "/")
|
groupPath = utils.TrimRight(groupPath, '/')
|
||||||
if groupPath == "" {
|
if groupPath == "" {
|
||||||
groupPath = "/"
|
groupPath = "/"
|
||||||
}
|
}
|
||||||
|
|
6
path.go
6
path.go
|
@ -51,7 +51,7 @@ const (
|
||||||
optionalParam byte = '?' // concludes a parameter by name and makes it optional
|
optionalParam byte = '?' // concludes a parameter by name and makes it optional
|
||||||
paramStarterChar byte = ':' // start character for a parameter with name
|
paramStarterChar byte = ':' // start character for a parameter with name
|
||||||
slashDelimiter byte = '/' // separator for the route, unlike the other delimiters this character at the end can be optional
|
slashDelimiter byte = '/' // separator for the route, unlike the other delimiters this character at the end can be optional
|
||||||
slashDelimiterStr = "/" // separator for the route, unlike the other delimiters this character at the end can be optional
|
slashDelimiterStr byte = '/' // separator for the route, unlike the other delimiters this character at the end can be optional
|
||||||
escapeChar byte = '\\' // escape character
|
escapeChar byte = '\\' // escape character
|
||||||
paramConstraintStart byte = '<' // start of type constraint for a parameter
|
paramConstraintStart byte = '<' // start of type constraint for a parameter
|
||||||
paramConstraintEnd byte = '>' // end of type constraint for a parameter
|
paramConstraintEnd byte = '>' // end of type constraint for a parameter
|
||||||
|
@ -161,7 +161,7 @@ func RoutePatternMatch(path, pattern string, cfg ...Config) bool {
|
||||||
}
|
}
|
||||||
// Strict routing, remove trailing slashes
|
// Strict routing, remove trailing slashes
|
||||||
if !config.StrictRouting && len(patternPretty) > 1 {
|
if !config.StrictRouting && len(patternPretty) > 1 {
|
||||||
patternPretty = strings.TrimRight(patternPretty, "/")
|
patternPretty = utils.TrimRight(patternPretty, '/')
|
||||||
}
|
}
|
||||||
|
|
||||||
parser := parseRoute(patternPretty)
|
parser := parseRoute(patternPretty)
|
||||||
|
@ -233,7 +233,7 @@ func addParameterMetaInfo(segs []*routeSegment) []*routeSegment {
|
||||||
} else {
|
} else {
|
||||||
comparePart = segs[i].Const
|
comparePart = segs[i].Const
|
||||||
if len(comparePart) > 1 {
|
if len(comparePart) > 1 {
|
||||||
comparePart = strings.TrimRight(comparePart, slashDelimiterStr)
|
comparePart = utils.TrimRight(comparePart, slashDelimiterStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,10 +249,10 @@ func (r *Redirect) parseAndClearFlashMessages() {
|
||||||
for {
|
for {
|
||||||
commaPos = findNextNonEscapedCharsetPosition(cookieValue, []byte(CookieDataSeparator))
|
commaPos = findNextNonEscapedCharsetPosition(cookieValue, []byte(CookieDataSeparator))
|
||||||
if commaPos == -1 {
|
if commaPos == -1 {
|
||||||
r.c.redirectionMessages = append(r.c.redirectionMessages, strings.Trim(cookieValue, " "))
|
r.c.redirectionMessages = append(r.c.redirectionMessages, utils.Trim(cookieValue, ' '))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.c.redirectionMessages = append(r.c.redirectionMessages, strings.Trim(cookieValue[:commaPos], " "))
|
r.c.redirectionMessages = append(r.c.redirectionMessages, utils.Trim(cookieValue[:commaPos], ' '))
|
||||||
cookieValue = cookieValue[commaPos+1:]
|
cookieValue = cookieValue[commaPos+1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -253,7 +253,7 @@ func (app *App) addPrefixToRoute(prefix string, route *Route) *Route {
|
||||||
}
|
}
|
||||||
// Strict routing, remove trailing slashes
|
// Strict routing, remove trailing slashes
|
||||||
if !app.config.StrictRouting && len(prettyPath) > 1 {
|
if !app.config.StrictRouting && len(prettyPath) > 1 {
|
||||||
prettyPath = strings.TrimRight(prettyPath, "/")
|
prettyPath = utils.TrimRight(prettyPath, '/')
|
||||||
}
|
}
|
||||||
|
|
||||||
route.Path = prefixedPath
|
route.Path = prefixedPath
|
||||||
|
@ -324,7 +324,7 @@ func (app *App) register(methods []string, pathRaw string, group *Group, handler
|
||||||
}
|
}
|
||||||
// Strict routing, remove trailing slashes
|
// Strict routing, remove trailing slashes
|
||||||
if !app.config.StrictRouting && len(pathPretty) > 1 {
|
if !app.config.StrictRouting && len(pathPretty) > 1 {
|
||||||
pathPretty = strings.TrimRight(pathPretty, "/")
|
pathPretty = utils.TrimRight(pathPretty, '/')
|
||||||
}
|
}
|
||||||
// Is layer a middleware?
|
// Is layer a middleware?
|
||||||
isUse := method == methodUse
|
isUse := method == methodUse
|
||||||
|
|
Loading…
Reference in New Issue