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)
| 49 | |
| 50 | |
| 51 | def _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 |
no outgoing calls
no test coverage detected