use fallback if not x-forwarded-for is present

This commit is contained in:
2022-05-17 23:47:24 +02:00
parent 2300d740d2
commit b8b9f82067
2 changed files with 9 additions and 2 deletions

View File

@@ -1105,10 +1105,9 @@ func main() {
go housekeeping()
r := gin.New()
r.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
return fmt.Sprintf("%s - \"%s %s %s %d %s \"%s\" %s\"\n",
param.Request.Header.Get("X-Forwarded-For"),
utils.RealIP(&param.Request.Header, param.Request.RemoteAddr),
param.Method,
param.Path,
param.Request.Proto,

View File

@@ -815,3 +815,11 @@ func PlayerFromSteam(players []*ent.Player, db *ent.Client, apiKey string, rl *r
return nPlayers, nil
}
func RealIP(header *http.Header, fallback string) string {
if header.Get("X-Forwarded-For") != "" {
return header.Get("X-Forwarded-For")
} else {
return fallback
}
}