1
0
mirror of https://github.com/labstack/echo.git synced 2025-10-30 23:57:38 +02:00

Split XFF header only by comma

This commit is contained in:
Oleksandr Savchenko
2021-05-20 17:51:15 +03:00
committed by Martti T
parent 1c24ab8c2b
commit fdacff0d93
2 changed files with 10 additions and 2 deletions

View File

@@ -276,9 +276,9 @@ func (c *context) RealIP() string {
}
// Fall back to legacy behavior
if ip := c.request.Header.Get(HeaderXForwardedFor); ip != "" {
i := strings.IndexAny(ip, ", ")
i := strings.IndexAny(ip, ",")
if i > 0 {
return ip[:i]
return strings.TrimSpace(ip[:i])
}
return ip
}

View File

@@ -888,6 +888,14 @@ func TestContext_RealIP(t *testing.T) {
},
"127.0.0.1",
},
{
&context{
request: &http.Request{
Header: http.Header{HeaderXForwardedFor: []string{"127.0.0.1,127.0.1.1"}},
},
},
"127.0.0.1",
},
{
&context{
request: &http.Request{