MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / _get_forwarded_for_ip

Function _get_forwarded_for_ip

apps/base/dependencies.py:31–45  ·  view source on GitHub ↗
(header_value: str, fallback_ip: str)

Source from the content-addressed store, hash-verified

29
30
31def _get_forwarded_for_ip(header_value: str, fallback_ip: str) -> str:
32 forwarded_chain = [
33 item.strip() for item in header_value.split(",") if item.strip()
34 ]
35 if not forwarded_chain:
36 return fallback_ip
37
38 for candidate in reversed(forwarded_chain):
39 try:
40 ip_address(candidate)
41 except ValueError:
42 return fallback_ip
43 if not _is_trusted_proxy(candidate):
44 return candidate
45 return forwarded_chain[0]
46
47
48def get_client_ip(request: Request) -> str:

Callers 1

get_client_ipFunction · 0.85

Calls 1

_is_trusted_proxyFunction · 0.85

Tested by

no test coverage detected