legacy: fix banned ip.
This commit is contained in:
parent
3cacb903f3
commit
5c91621223
1 changed files with 5 additions and 9 deletions
|
|
@ -383,21 +383,17 @@ func (h *LegacyHandler) ban(sessionId string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *LegacyHandler) isBanned(r *http.Request) bool {
|
func (h *LegacyHandler) isBanned(r *http.Request) bool {
|
||||||
ipPort := r.RemoteAddr
|
ip := getIp(r)
|
||||||
ip, _, err := net.SplitHostPort(ipPort)
|
|
||||||
if err != nil {
|
|
||||||
h.logger.Error().Err(err).Msg("couldn't split host and port")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
_, ok := h.bannedIPs[ip]
|
_, ok := h.bannedIPs[ip]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIp(r *http.Request) string {
|
func getIp(r *http.Request) string {
|
||||||
ipPort := r.RemoteAddr
|
ip, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||||
ip, _, err := net.SplitHostPort(ipPort)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if e, ok := err.(*net.AddrError); ok && e.Err == "missing port in address" {
|
||||||
|
return r.RemoteAddr
|
||||||
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue