MCPcopy
hub / github.com/django/django / validate_host

Function validate_host

django/http/request.py:857–874  ·  view source on GitHub ↗

Validate the given host for this site. Check that the host looks valid and matches a host or host pattern in the given list of ``allowed_hosts``. Any pattern beginning with a period matches a domain and all its subdomains (e.g. ``.example.com`` matches ``example.com`` and any s

(host, allowed_hosts)

Source from the content-addressed store, hash-verified

855
856
857def validate_host(host, allowed_hosts):
858 """
859 Validate the given host for this site.
860
861 Check that the host looks valid and matches a host or host pattern in the
862 given list of ``allowed_hosts``. Any pattern beginning with a period
863 matches a domain and all its subdomains (e.g. ``.example.com`` matches
864 ``example.com`` and any subdomain), ``*`` matches anything, and anything
865 else must match exactly.
866
867 Note: This function assumes that the given host is lowercased and has
868 already had the port, if any, stripped off.
869
870 Return ``True`` for a valid host, ``False`` otherwise.
871 """
872 return any(
873 pattern == "*" or is_same_domain(host, pattern) for pattern in allowed_hosts
874 )

Callers 2

assertRedirectsMethod · 0.90
get_hostMethod · 0.85

Calls 1

is_same_domainFunction · 0.90

Tested by 1

assertRedirectsMethod · 0.72