remoteAddr returns the real client's address and the IP address of the latest proxy server if any.
(r *http.Request, l *slog.Logger)
| 347 | // remoteAddr returns the real client's address and the IP address of the latest |
| 348 | // proxy server if any. |
| 349 | func remoteAddr(r *http.Request, l *slog.Logger) (addr, prx netip.AddrPort, err error) { |
| 350 | host, err := netip.ParseAddrPort(r.RemoteAddr) |
| 351 | if err != nil { |
| 352 | return netip.AddrPort{}, netip.AddrPort{}, err |
| 353 | } |
| 354 | |
| 355 | realIP, err := realIPFromHdrs(r) |
| 356 | if err != nil { |
| 357 | l.Debug("getting ip address from http request", slogutil.KeyError, err) |
| 358 | |
| 359 | return host, netip.AddrPort{}, nil |
| 360 | } |
| 361 | |
| 362 | l.Debug("using ip address from http request", "addr", realIP) |
| 363 | |
| 364 | // TODO(a.garipov): Add port if we can get it from headers like X-Real-Port, |
| 365 | // X-Forwarded-Port, etc. |
| 366 | addr = netip.AddrPortFrom(realIP, 0) |
| 367 | |
| 368 | return addr, host, nil |
| 369 | } |
searching dependent graphs…