File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -276,9 +276,9 @@ func (c *context) RealIP() string {
276
276
}
277
277
// Fall back to legacy behavior
278
278
if ip := c .request .Header .Get (HeaderXForwardedFor ); ip != "" {
279
- i := strings .IndexAny (ip , ", " )
279
+ i := strings .IndexAny (ip , "," )
280
280
if i > 0 {
281
- return ip [:i ]
281
+ return strings . TrimSpace ( ip [:i ])
282
282
}
283
283
return ip
284
284
}
Original file line number Diff line number Diff line change @@ -888,6 +888,14 @@ func TestContext_RealIP(t *testing.T) {
888
888
},
889
889
"127.0.0.1" ,
890
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
+ },
891
899
{
892
900
& context {
893
901
request : & http.Request {
You can’t perform that action at this time.
0 commit comments