Struct URL
A Unique Resource Locator.
Constructors
Name | Description |
this
(source)
|
Attempts to parse an URL from a string.
Output string data (scheme, user, etc.) are just slices of input string
(i.e., no memory allocation and copying).
|
Fields
Name | Type | Description |
fragment
|
const(char)[] | The anchor.
|
host
|
const(char)[] | The hostname.
|
pass
|
const(char)[] | The password.
|
path
|
const(char)[] | The path.
|
port
|
ushort | The port number.
|
query
|
const(char)[] | The query string.
|
scheme
|
const(char)[] | The URL scheme.
|
user
|
const(char)[] | The username.
|
Example
auto u = URL("example.org");
assert(u.path == "example.org");
u = URL("relative/path");
assert(u.path == "relative/path");
// Host and scheme
u = URL("https://example.org");
assert(u.scheme == "https");
assert(u.host == "example.org");
assert(u.path is null);
assert(u.port == 0);
assert(u.fragment is null);
// With user and port and path
u = URL("https://hilary:putnam@example.org:443/foo/bar");
assert(u.scheme == "https");
assert(u.host == "example.org");
assert(u.path == "/foo/bar");
assert(u.port == 443);
assert(u.user == "hilary");
assert(u.pass == "putnam");
assert(u.fragment is null);
// With query string
u = URL("https://example.org/?login=true");
assert(u.scheme == "https");
assert(u.host == "example.org");
assert(u.path == "/");
assert(u.query == "login=true");
assert(u.fragment is null);
// With query string and fragment
u = URL("https://example.org/?login=false#label");
assert(u.scheme == "https");
assert(u.host == "example.org");
assert(u.path == "/");
assert(u.query == "login=false");
assert(u.fragment == "label");
u = URL("redis://root:password@localhost:2201/path?query=value#fragment");
assert(u.scheme == "redis");
assert(u.user == "root");
assert(u.pass == "password");
assert(u.host == "localhost");
assert(u.port == 2201);
assert(u.path == "/path");
assert(u.query == "query=value");
assert(u.fragment == "fragment");