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:
		
				
					committed by
					
						 Martti T
						Martti T
					
				
			
			
				
	
			
			
			
						parent
						
							1c24ab8c2b
						
					
				
				
					commit
					fdacff0d93
				
			| @@ -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 | ||||
| 	} | ||||
|   | ||||
| @@ -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{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user