mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-06-19 23:22:40 +02:00
fix: only track ip without port
This commit is contained in:
parent
b22d3665a9
commit
612a5554d5
2 changed files with 13 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -32,11 +33,18 @@ func Handler(
|
|||
log := log.With().Str("ReqId", ctx.ReqId).Strs("Handler", []string{req.Host, req.RequestURI}).Logger()
|
||||
|
||||
if cfg.LogMostActiveIps {
|
||||
ip, _, err := net.SplitHostPort(req.RemoteAddr)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to get IP address. Using complete remoteAddr string")
|
||||
|
||||
ip = req.RemoteAddr
|
||||
}
|
||||
|
||||
success := false
|
||||
for !success {
|
||||
value, _ := mostActiveIpMap.LoadOrStore(req.RemoteAddr, uint(0))
|
||||
value, _ := mostActiveIpMap.LoadOrStore(ip, uint(0))
|
||||
count := value.(uint)
|
||||
success = mostActiveIpMap.CompareAndSwap(req.RemoteAddr, count, count+1)
|
||||
success = mostActiveIpMap.CompareAndSwap(ip, count, count+1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue