URL
URLs as RFC 3986 defines them, for any scheme: https://example.com/a?b,
mailto:someone@example.com, urn:isbn:0451450523.
match URL.parse("https://example.com/search?q=turkey") {
Right(u) -> print(URL.path(u))
Left(e) -> print(e)
}
Two types. A URL is absolute: it has a scheme, so it names something
on its own. A Reference may be relative, ../style.css or /orders/42
or ?page=2, and means something only against a base, which resolve
supplies. Every URL is also a reference, through reference.
Strict. Every byte must be one RFC 3986 allows where it stands, and a
% must start two hexadecimal digits. Spaces, controls, \, and bytes
outside ASCII are refused rather than encoded or dropped, so the text a URL
shows is exactly the text it was parsed from, apart from the scheme and
host, which are case-insensitive and stored lowercase. Nothing else is
normalized: dot segments stay as written until resolve, and
percent-encoding is never added or removed.
Components are encoded. path, query and fragment are as they
appear in the URL, %2F and all. segments decodes the path into its
segments, where a%2Fb is one segment holding a slash, which no reading of
the encoded path can tell apart from two.
An absolute URL: parts.scheme is always Some.
A URL or a relative reference.
The part after //: user@host:port.
Why text is not a URL. Each names the component that was refused.
Returns the absolute URL text writes.
Returns the URL text writes, and panics if it writes none: a URL written
in the program's source that does not parse is a mistake in the program.
Returns the URL or relative reference text writes.
Returns the reference text writes, and panics if it writes none.
Returns the path's segments, decoded: /a%20b/c is ["a b", "c"]. The
empty path has no segments, and / one empty segment. Returns None if
a segment decodes to bytes that are not UTF-8.
Returns text with each %XX replaced by the byte it encodes, or None
if the result is not UTF-8. text comes from a parsed URL, so every %
starts two hexadecimal digits.
Returns the URL reference names when read against base, by the
algorithm of RFC 3986 ยง5.2, dot segments removed.