diff --git a/flake.lock b/flake.lock index 67407b9..a18f998 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1749285348, - "narHash": "sha256-frdhQvPbmDYaScPFiCnfdh3B/Vh81Uuoo0w5TkWmmjU=", + "lastModified": 1749794982, + "narHash": "sha256-Kh9K4taXbVuaLC0IL+9HcfvxsSUx8dPB5s5weJcc9pc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3e3afe5174c561dee0df6f2c2b2236990146329f", + "rev": "ee930f9755f58096ac6e8ca94a1887e0534e2d81", "type": "github" }, "original": { diff --git a/server/handler/handler.go b/server/handler/handler.go index 7f53a8d..84acd81 100644 --- a/server/handler/handler.go +++ b/server/handler/handler.go @@ -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) } }