realIPFromHdrs extracts the actual client's IP address from the first suitable r's header. It returns an error if r doesn't contain any information about real client's IP address. Current headers priority is: 1. [httphdr.CFConnectingIP] 2. [httphdr.TrueClientIP] 3. [httphdr.XRealIP] 4. [httphdr.X
(r *http.Request)
| 324 | // 3. [httphdr.XRealIP] |
| 325 | // 4. [httphdr.XForwardedFor] |
| 326 | func realIPFromHdrs(r *http.Request) (realIP netip.Addr, err error) { |
| 327 | for _, h := range []string{ |
| 328 | httphdr.CFConnectingIP, |
| 329 | httphdr.TrueClientIP, |
| 330 | httphdr.XRealIP, |
| 331 | } { |
| 332 | realIP, err = netip.ParseAddr(strings.TrimSpace(r.Header.Get(h))) |
| 333 | if err == nil { |
| 334 | return realIP, nil |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | xff := r.Header.Get(httphdr.XForwardedFor) |
| 339 | firstComma := strings.IndexByte(xff, ',') |
| 340 | if firstComma > 0 { |
| 341 | xff = xff[:firstComma] |
| 342 | } |
| 343 | |
| 344 | return netip.ParseAddr(strings.TrimSpace(xff)) |
| 345 | } |
| 346 | |
| 347 | // remoteAddr returns the real client's address and the IP address of the latest |
| 348 | // proxy server if any. |
no outgoing calls
searching dependent graphs…