Parse `host_header` into its host and port components. The host preserves brackets around IP literals. Invalid headers produce `None`.
(host_header: str | None)
| 116 | |
| 117 | |
| 118 | def parse_host_header(host_header: str | None) -> ParsedHost | None: |
| 119 | """Parse `host_header` into its host and port components. |
| 120 | |
| 121 | The host preserves brackets around IP literals. Invalid headers produce `None`. |
| 122 | """ |
| 123 | if host_header is None: |
| 124 | return None |
| 125 | |
| 126 | match = _HOST_RE.fullmatch(host_header) |
| 127 | if match is None: |
| 128 | return None |
| 129 | |
| 130 | ipv6 = match["ipv6"] |
| 131 | if ipv6 is not None: |
| 132 | try: |
| 133 | IPv6Address(ipv6) |
| 134 | except AddressValueError: |
| 135 | return None |
| 136 | |
| 137 | return ParsedHost(match["host"], match["port"]) |
| 138 | |
| 139 | |
| 140 | def get_route_path(scope: Scope) -> str: |
no test coverage detected