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 {
276276 }
277277 // Fall back to legacy behavior
278278 if ip := c .request .Header .Get (HeaderXForwardedFor ); ip != "" {
279- i := strings .IndexAny (ip , ", " )
279+ i := strings .IndexAny (ip , "," )
280280 if i > 0 {
281- return ip [:i ]
281+ return strings . TrimSpace ( ip [:i ])
282282 }
283283 return ip
284284 }
Original file line number Diff line number Diff line change @@ -888,6 +888,14 @@ func TestContext_RealIP(t *testing.T) {
888888 },
889889 "127.0.0.1" ,
890890 },
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+ },
891899 {
892900 & context {
893901 request : & http.Request {
You can’t perform that action at this time.
0 commit comments