std/uri/authority
std/uri/src/authority.trb
Authority and Host: the [userInfo "@"] host [":" port] of a URI, read and normalized (RFC 3986 section 3.2).
A host is one of three things, and the first that fits decides (section 3.2.2): an IP literal in brackets, an IPv4
address in dotted decimal, or a registered name. The addresses are std/ip's, so a URI whose host is an IP literal
answers a SocketAddress without a resolver - and without the network capability.
type Host
type Host with Show, Equals, Hash
Where an authority points. Name("") is a value: file:///x has an authority whose host is empty.
Examples
const uri: Uri = "http://[::1]:8080/"
print uri.host()
case Name
case Name(name: String)
A registered name, lower case: example.test. Resolving it into addresses is std/network's.
case Address
case Address(address: IpAddress)
An IP literal: 127.0.0.1, or ::1 from [::1], in the text form of std/ip (RFC 5952 for IPv6).
case Future
case Future(text: String)
RFC 3986's IPvFuture, v7.anything, lower case: an IP version nobody has defined yet.
fn domainName
fn domainName(): DomainName?
The registered name as the DomainName a resolver is asked for, where it is one. None for an IP literal, an
IPvFuture literal, the empty host of file:///x, and a registered name that is no host name: a sub-delimiter or
a percent escape in it, an empty label, a label longer than 63 bytes (RFC 3986 allows every one of them in a
reg-name; the DNS does not).
Examples
const uri = Uri.tryFrom("https://www.Example.test/")?
print uri.host()?.domainName()
fn show
fn show(): String
The host as a URI writes it: example.test, 127.0.0.1, [::1], [v7.x].
type Authority
type Authority with Show, Equals, Hash
The [userInfo "@"] host [":" port] of a URI. Its absence is not an empty one: mailto:ada@example.test has no
authority, and file:///x has one whose host is Name("").
Ordinary data: the fields are public, and a URI that holds one has already normalized it.
field userInfo
userInfo: String?
Everything before the @, normalized. None where the authority has no @.
field host
host: Host
The registered name or the IP literal.
field port
port: Int?
The port, where one is written out. It is not the port a scheme defaults to.
fn text
fn text(): String
[userInfo "@"] host [":" port], with every part of it: a password in the user information is in this text.
fn show
fn show(): String
The same text with everything after the first : of the user information replaced by ***.
fn hostAndPort
fn hostAndPort(): String
host [":" port], which carries no secret either way.
fn socketAddress
fn socketAddress(defaultPort: Int? = None): SocketAddress?
Where to connect without a resolver: the host where it is an IP literal, with the written port or defaultPort.
None for a registered name, which has to be resolved first, and where neither port is known.