(header_value: str, fallback_ip: str)
| 29 | |
| 30 | |
| 31 | def _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 | |
| 48 | def get_client_ip(request: Request) -> str: |
no test coverage detected