summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/labstack/echo/v4/context.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-03-20 22:40:23 +0100
committerGitHub <noreply@github.com>2021-03-20 22:40:23 +0100
commitee5d9b43b54a3becf3cb4025198f24608d35500d (patch)
treedd3614db7423da52f5a71da3001e48d1e4195ea1 /vendor/github.com/labstack/echo/v4/context.go
parent3a8857c8c9efb2c67fb8c175f31d2b9c617b771b (diff)
downloadmatterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.tar.gz
matterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.tar.bz2
matterbridge-msglm-ee5d9b43b54a3becf3cb4025198f24608d35500d.zip
Update vendor (#1414)
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/context.go')
-rw-r--r--vendor/github.com/labstack/echo/v4/context.go34
1 files changed, 29 insertions, 5 deletions
diff --git a/vendor/github.com/labstack/echo/v4/context.go b/vendor/github.com/labstack/echo/v4/context.go
index 99ef03bc..0cee48ce 100644
--- a/vendor/github.com/labstack/echo/v4/context.go
+++ b/vendor/github.com/labstack/echo/v4/context.go
@@ -246,7 +246,7 @@ func (c *context) IsTLS() bool {
func (c *context) IsWebSocket() bool {
upgrade := c.request.Header.Get(HeaderUpgrade)
- return strings.ToLower(upgrade) == "websocket"
+ return strings.EqualFold(upgrade, "websocket")
}
func (c *context) Scheme() string {
@@ -276,7 +276,11 @@ func (c *context) RealIP() string {
}
// Fall back to legacy behavior
if ip := c.request.Header.Get(HeaderXForwardedFor); ip != "" {
- return strings.Split(ip, ", ")[0]
+ i := strings.IndexAny(ip, ", ")
+ if i > 0 {
+ return ip[:i]
+ }
+ return ip
}
if ip := c.request.Header.Get(HeaderXRealIP); ip != "" {
return ip
@@ -310,7 +314,19 @@ func (c *context) ParamNames() []string {
func (c *context) SetParamNames(names ...string) {
c.pnames = names
- *c.echo.maxParam = len(names)
+
+ l := len(names)
+ if *c.echo.maxParam < l {
+ *c.echo.maxParam = l
+ }
+
+ if len(c.pvalues) < l {
+ // Keeping the old pvalues just for backward compatibility, but it sounds that doesn't make sense to keep them,
+ // probably those values will be overriden in a Context#SetParamValues
+ newPvalues := make([]string, l)
+ copy(newPvalues, c.pvalues)
+ c.pvalues = newPvalues
+ }
}
func (c *context) ParamValues() []string {
@@ -318,7 +334,15 @@ func (c *context) ParamValues() []string {
}
func (c *context) SetParamValues(values ...string) {
- c.pvalues = values
+ // NOTE: Don't just set c.pvalues = values, because it has to have length c.echo.maxParam at all times
+ // It will brake the Router#Find code
+ limit := len(values)
+ if limit > *c.echo.maxParam {
+ limit = *c.echo.maxParam
+ }
+ for i := 0; i < limit; i++ {
+ c.pvalues[i] = values[i]
+ }
}
func (c *context) QueryParam(name string) string {
@@ -361,7 +385,7 @@ func (c *context) FormFile(name string) (*multipart.FileHeader, error) {
if err != nil {
return nil, err
}
- defer f.Close()
+ f.Close()
return fh, nil
}