MCPcopy Index your code
hub / github.com/AdguardTeam/dnsproxy / remoteAddr

Function remoteAddr

proxy/serverhttps.go:349–369  ·  view source on GitHub ↗

remoteAddr returns the real client's address and the IP address of the latest proxy server if any.

(r *http.Request, l *slog.Logger)

Source from the content-addressed store, hash-verified

347// remoteAddr returns the real client's address and the IP address of the latest
348// proxy server if any.
349func 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}

Callers 2

ServeHTTPMethod · 0.85
TestRemoteAddrFunction · 0.85

Calls 1

realIPFromHdrsFunction · 0.85

Tested by 1

TestRemoteAddrFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…