We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1c24ab8 commit fdacff0Copy full SHA for fdacff0
context.go
@@ -276,9 +276,9 @@ func (c *context) RealIP() string {
276
}
277
// Fall back to legacy behavior
278
if ip := c.request.Header.Get(HeaderXForwardedFor); ip != "" {
279
- i := strings.IndexAny(ip, ", ")
+ i := strings.IndexAny(ip, ",")
280
if i > 0 {
281
- return ip[:i]
+ return strings.TrimSpace(ip[:i])
282
283
return ip
284
context_test.go
@@ -888,6 +888,14 @@ func TestContext_RealIP(t *testing.T) {
888
},
889
"127.0.0.1",
890
891
+ {
892
+ &context{
893
+ request: &http.Request{
894
+ Header: http.Header{HeaderXForwardedFor: []string{"127.0.0.1,127.0.1.1"}},
895
+ },
896
897
+ "127.0.0.1",
898
899
{
900
&context{
901
request: &http.Request{
0 commit comments