(url)
| 74 | |
| 75 | |
| 76 | def _host_from_url(url): |
| 77 | # Given URL, derive value for host header. Ensure that value: |
| 78 | # 1) is lowercase |
| 79 | # 2) excludes port, if it was the default port |
| 80 | # 3) excludes userinfo |
| 81 | url_parts = urlsplit(url) |
| 82 | host = url_parts.hostname # urlsplit's hostname is always lowercase |
| 83 | if is_valid_ipv6_endpoint_url(url): |
| 84 | # Enclose IPv6 Literal addresses in |
| 85 | # brackets as per RFC 3986 3.2.2. |
| 86 | host = f'[{host}]' |
| 87 | |
| 88 | default_ports = {'http': 80, 'https': 443} |
| 89 | if url_parts.port is not None: |
| 90 | if url_parts.port != default_ports.get(url_parts.scheme): |
| 91 | host = '%s:%d' % (host, url_parts.port) |
| 92 | return host |
| 93 | |
| 94 | |
| 95 | def _get_body_as_dict(request): |
no test coverage detected