URL

A Unique Resource Locator.

Constructors

this
this(char[] 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).

Members

Variables

fragment
const(char)[] fragment;

The anchor.

host
const(char)[] host;

The hostname.

pass
const(char)[] pass;

The password.

path
const(char)[] path;

The path.

port
ushort port;

The port number.

query
const(char)[] query;

The query string.

scheme
const(char)[] scheme;

The URL scheme.

user
const(char)[] user;

The username.

Examples

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");

Meta