std :: encoding::url
Struct std::Url
struct Url {
struct String scheme;
struct String username;
struct String password;
struct String host;
int port;
struct String path;
struct String query;
struct String fragment;
int has_authority;
int has_query;
int has_fragment;
}A URL split into its RFC 3986 components:
scheme://username:password@host:port/path?query#fragment
Components are stored as they appear in the text (still percent-encoded, so they can be serialized back unchanged), except that the scheme and a registered-name host are lowercased and an IPv6 literal's brackets are dropped from 'host' ("[::1]" is stored as "::1"). 'port' is -1 when the URL has none. has_authority / has_query / has_fragment tell "no query" apart from an empty one ("/p?" vs "/p").
Fields
"https" (no ':'), empty for a relative reference
-1: none given
"/a/b" (may be empty, e.g. "mailto:x" has path "x")
without the '?'
without the '#'
"//" was present
Methods
An empty relative reference (every component empty, port -1).
Parses an absolute URL or a relative reference. Fails (*ok = 0, and an empty Url) on a bad scheme, a non-numeric or > 65535 port, an unterminated '[' IPv6 literal, or a control character/space.
Back to text (the RFC 3986 §5.3 recomposition).
Resolves the reference 'ref' against this (absolute) base URL — RFC 3986 §5.2, including dot-segment removal: base "http://a/b/c/d;p?q" + "../g" = "http://a/b/g". Fails if 'ref' doesn't parse or this base has no scheme.
'port', or the scheme's default (http/ws 80, https/wss 443, ftp 21) when none was given; -1 for an unknown scheme without a port.
"host" or "host:port" (only an explicit port), IPv6 re-bracketed — what an HTTP Host header carries.
"scheme://host[:port]" — the web origin (for CORS, cookies, ...).
path (or "/" when empty) plus "?query" — an HTTP request-target.
The decoded query parameters.
Replaces the query with params.to_string() (has_query = 1, or 0 for an empty params).
The path with each %XX decoded (for file lookups, routing, ...).
has a scheme
= drop()