Fix incorrect source IP
This commit is contained in:
@@ -16,32 +16,7 @@ limitations under the License.
|
||||
|
||||
package net
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 0 is considered as a non valid port
|
||||
func IsValidPort(port int) bool {
|
||||
return port > 0 && port < 65535
|
||||
}
|
||||
|
||||
func GetRequestIP(req *http.Request) string {
|
||||
address := strings.Trim(req.Header.Get("X-Real-Ip"), " ")
|
||||
if address != "" {
|
||||
return address
|
||||
}
|
||||
|
||||
address = strings.Trim(req.Header.Get("X-Forwarded-For"), " ")
|
||||
if address != "" {
|
||||
return address
|
||||
}
|
||||
|
||||
address, _, err := net.SplitHostPort(req.RemoteAddr)
|
||||
if err != nil {
|
||||
return req.RemoteAddr
|
||||
}
|
||||
|
||||
return address
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user