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

Function realIPFromHdrs

proxy/serverhttps.go:326–345  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

324// 3. [httphdr.XRealIP]
325// 4. [httphdr.XForwardedFor]
326func 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.

Callers 2

remoteAddrFunction · 0.85
TestAddrsFromRequestFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestAddrsFromRequestFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…