diff --git a/AK/URL.h b/AK/URL.h index 6b75d1239d..98955b2ef6 100644 --- a/AK/URL.h +++ b/AK/URL.h @@ -54,6 +54,22 @@ public: { } + // https://url.spec.whatwg.org/#concept-ipv4 + // An IPv4 address is a 32-bit unsigned integer that identifies a network address. [RFC791] + // FIXME: It would be nice if this were an AK::IPv4Address + using IPv4Address = u32; + + // https://url.spec.whatwg.org/#concept-ipv6 + // An IPv6 address is a 128-bit unsigned integer that identifies a network address. For the purposes of this standard + // it is represented as a list of eight 16-bit unsigned integers, also known as IPv6 pieces. [RFC4291] + // FIXME: It would be nice if this were an AK::IPv6Address + using IPv6Address = Array; + + // https://url.spec.whatwg.org/#concept-host + // A host is a domain, an IP address, an opaque host, or an empty host. Typically a host serves as a network address, + // but it is sometimes used as opaque identifier in URLs where a network address is not necessary. + using Host = Variant; + bool is_valid() const { return m_valid; } enum class ApplyPercentDecoding { diff --git a/AK/URLParser.cpp b/AK/URLParser.cpp index 9e818aaaae..7570d714f0 100644 --- a/AK/URLParser.cpp +++ b/AK/URLParser.cpp @@ -121,7 +121,7 @@ static Optional parse_ipv4_number(StringView input) } // https://url.spec.whatwg.org/#concept-ipv4-parser -static Optional parse_ipv4_address(StringView input) +static Optional parse_ipv4_address(StringView input) { // 1. Let parts be the result of strictly splitting input on U+002E (.). auto parts = input.split_view("."sv, SplitBehavior::KeepEmpty); @@ -201,7 +201,7 @@ static Optional parse_ipv4_address(StringView input) } // https://url.spec.whatwg.org/#concept-ipv4-serializer -static ErrorOr serialize_ipv4_address(u32 address) +static ErrorOr serialize_ipv4_address(URL::IPv4Address address) { // 1. Let output be the empty string. // NOTE: Array to avoid prepend. @@ -227,7 +227,7 @@ static ErrorOr serialize_ipv4_address(u32 address) } // https://url.spec.whatwg.org/#concept-ipv6-serializer -static ErrorOr serialize_ipv6_address(Array const& address) +static ErrorOr serialize_ipv6_address(URL::IPv6Address const& address) { // 1. Let output be the empty string. StringBuilder output; @@ -290,7 +290,7 @@ static ErrorOr serialize_ipv6_address(Array const& address) } // https://url.spec.whatwg.org/#concept-ipv6-parser -static Optional> parse_ipv6_address(StringView input) +static Optional parse_ipv6_address(StringView input) { // 1. Let address be a new IPv6 address whose IPv6 pieces are all 0. Array address {};