LibURL: Promote Host to a proper class

This lets us move a few Host-related functions (like serialization and
checks for what the Host is) into Host instead of having them dotted
around the codebase.

For now, the interface is still very Variant-like, to avoid having to
change quite so much in one go.
This commit is contained in:
Sam Atkins 2024-11-27 15:12:17 +00:00 committed by Andreas Kling
commit 63688148b9
Notes: github-actions[bot] 2024-11-30 11:24:04 +00:00
14 changed files with 212 additions and 134 deletions

View file

@ -88,7 +88,7 @@ void URL::set_host(Host host)
// https://url.spec.whatwg.org/#concept-host-serializer
ErrorOr<String> URL::serialized_host() const
{
return Parser::serialize_host(m_data->host.value());
return m_data->host->serialize();
}
void URL::set_port(Optional<u16> port)
@ -119,7 +119,8 @@ void URL::append_path(StringView path)
bool URL::cannot_have_a_username_or_password_or_port() const
{
// A URL cannot have a username/password/port if its host is null or the empty string, or its scheme is "file".
return !m_data->host.has_value() || m_data->host == String {} || m_data->scheme == "file"sv;
return !m_data->host.has_value() || m_data->host->is_empty_host() || m_data->scheme == "file"sv;
}
// FIXME: This is by no means complete.