Return a (domain, port) tuple from a given host. Returned domain is lowercased. If the host is invalid, the domain will be empty.
(host)
| 841 | |
| 842 | |
| 843 | def split_domain_port(host): |
| 844 | """ |
| 845 | Return a (domain, port) tuple from a given host. |
| 846 | |
| 847 | Returned domain is lowercased. If the host is invalid, the domain will be |
| 848 | empty. |
| 849 | """ |
| 850 | if match := host_validation_re.fullmatch(host.lower()): |
| 851 | domain, port = match.groups(default="") |
| 852 | # Remove a trailing dot (if present) from the domain. |
| 853 | return domain.removesuffix("."), port |
| 854 | return "", "" |
| 855 | |
| 856 | |
| 857 | def validate_host(host, allowed_hosts): |