[chore] Update gin to v1.9.0 (#1553)

This commit is contained in:
Daenney 2023-02-25 13:12:40 +01:00 committed by GitHub
commit ecdc8379fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
347 changed files with 166814 additions and 3671 deletions

View file

@ -11,6 +11,7 @@ import (
"net/http"
"os"
"path"
"regexp"
"strings"
"sync"
@ -40,6 +41,9 @@ var defaultTrustedCIDRs = []*net.IPNet{
},
}
var regSafePrefix = regexp.MustCompile("[^a-zA-Z0-9/-]+")
var regRemoveRepeatedChar = regexp.MustCompile("/{2,}")
// HandlerFunc defines the handler used by gin middleware as return value.
type HandlerFunc func(*Context)
@ -166,7 +170,7 @@ type Engine struct {
trustedCIDRs []*net.IPNet
}
var _ IRouter = &Engine{}
var _ IRouter = (*Engine)(nil)
// New returns a new blank Engine instance without any middleware attached.
// By default, the configuration is:
@ -668,6 +672,9 @@ func redirectTrailingSlash(c *Context) {
req := c.Request
p := req.URL.Path
if prefix := path.Clean(c.Request.Header.Get("X-Forwarded-Prefix")); prefix != "." {
prefix = regSafePrefix.ReplaceAllString(prefix, "")
prefix = regRemoveRepeatedChar.ReplaceAllString(prefix, "/")
p = prefix + "/" + req.URL.Path
}
req.URL.Path = p + "/"