mirror of
				https://github.com/gin-gonic/gin.git
				synced 2025-11-04 09:12:12 +08:00 
			
		
		
		
	Check existence of X-Forwarded-For by comparing the length
This commit is contained in:
		
							parent
							
								
									97729696c0
								
							
						
					
					
						commit
						78c7101ff6
					
				@ -44,12 +44,12 @@ func Logger() HandlerFunc {
 | 
				
			|||||||
		// save the IP of the requester
 | 
							// save the IP of the requester
 | 
				
			||||||
		requester := c.Request.Header.Get("X-Real-IP")
 | 
							requester := c.Request.Header.Get("X-Real-IP")
 | 
				
			||||||
		// if the requester-header is empty, check the forwarded-header
 | 
							// if the requester-header is empty, check the forwarded-header
 | 
				
			||||||
		if requester == "" {
 | 
							if len(requester) == 0 {
 | 
				
			||||||
			requester = c.Request.Header.Get("X-Forwarded-For")
 | 
								requester = c.Request.Header.Get("X-Forwarded-For")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// if the requester is still empty, use the hard-coded address from the socket
 | 
							// if the requester is still empty, use the hard-coded address from the socket
 | 
				
			||||||
		if requester == "" {
 | 
							if len(requester) == 0 {
 | 
				
			||||||
			requester = c.Request.RemoteAddr
 | 
								requester = c.Request.RemoteAddr
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user