mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-06-19 15:12: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
6
flake.lock
generated
6
flake.lock
generated
|
@ -20,11 +20,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1749285348,
|
"lastModified": 1749794982,
|
||||||
"narHash": "sha256-frdhQvPbmDYaScPFiCnfdh3B/Vh81Uuoo0w5TkWmmjU=",
|
"narHash": "sha256-Kh9K4taXbVuaLC0IL+9HcfvxsSUx8dPB5s5weJcc9pc=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "3e3afe5174c561dee0df6f2c2b2236990146329f",
|
"rev": "ee930f9755f58096ac6e8ca94a1887e0534e2d81",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -32,11 +33,18 @@ func Handler(
|
||||||
log := log.With().Str("ReqId", ctx.ReqId).Strs("Handler", []string{req.Host, req.RequestURI}).Logger()
|
log := log.With().Str("ReqId", ctx.ReqId).Strs("Handler", []string{req.Host, req.RequestURI}).Logger()
|
||||||
|
|
||||||
if cfg.LogMostActiveIps {
|
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
|
success := false
|
||||||
for !success {
|
for !success {
|
||||||
value, _ := mostActiveIpMap.LoadOrStore(req.RemoteAddr, uint(0))
|
value, _ := mostActiveIpMap.LoadOrStore(ip, uint(0))
|
||||||
count := value.(uint)
|
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