MCPcopy
hub / github.com/benoitc/gunicorn / _check_trusted_proxy

Function _check_trusted_proxy

gunicorn/asgi/protocol.py:51–67  ·  view source on GitHub ↗

Check if peer address is in the trusted proxy list. Cached at connection start to avoid repeated IP parsing per request.

(peer_addr, allow_list, networks)

Source from the content-addressed store, hash-verified

49
50
51def _check_trusted_proxy(peer_addr, allow_list, networks):
52 """Check if peer address is in the trusted proxy list.
53
54 Cached at connection start to avoid repeated IP parsing per request.
55 """
56 if not isinstance(peer_addr, tuple):
57 return False
58 if '*' in allow_list:
59 return True
60 try:
61 ip = ipaddress.ip_address(peer_addr[0])
62 except ValueError:
63 return False
64 for network in networks:
65 if ip in network:
66 return True
67 return False
68
69
70# Cached response bytes for common cases

Callers 2

_effective_peernameMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected