mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01:00
lib/httpserver: emit X-Forwarded-For additionally to remoteAddr in error logs
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/659
This commit is contained in:
parent
328b52e5ff
commit
67a64c142d
@ -484,7 +484,11 @@ var (
|
||||
// Errorf writes formatted error message to w and to logger.
|
||||
func Errorf(w http.ResponseWriter, r *http.Request, format string, args ...interface{}) {
|
||||
errStr := fmt.Sprintf(format, args...)
|
||||
errStr = fmt.Sprintf("remoteAddr: %s; %s", r.RemoteAddr, errStr)
|
||||
remoteAddr := strconv.Quote(r.RemoteAddr) // quote remoteAddr and X-Forwarded-For, since they may contain untrusted input
|
||||
if addr := r.Header.Get("X-Forwarded-For"); addr != "" {
|
||||
remoteAddr += ", X-Forwarded-For: " + strconv.Quote(addr)
|
||||
}
|
||||
errStr = fmt.Sprintf("remoteAddr: %s; %s", remoteAddr, errStr)
|
||||
logger.WarnfSkipframes(1, "%s", errStr)
|
||||
|
||||
// Extract statusCode from args
|
||||
|
Loading…
Reference in New Issue
Block a user