std::net::urlURL parsing.
Parse URLs into their components (scheme, host, port, path, query, fragment) and reconstruct or join them.
import std.net.url;
fn main() {
let u = url.parse("https://example.com:8080/path?key=val#frag");
println(u.host());
match u.port() {
.Some(port) => println(port),
.None => println("no port"),
}
u.close();
}
parseParse a URL string.
Panics if the string is not a valid URL.
import std.net.url;
fn main() {
let u = url.parse("https://example.com/api/v1");
}
encodePercent-encode a string (RFC 3986 unreserved characters are left unchanged).
import std.net.url;
fn main() {
let encoded = url.encode("hello world"); // "hello%20world"
}
decodeDecode a percent-encoded string.
Returns an empty string on invalid UTF-8. Valid decoded NUL is preserved.
import std.net.url;
fn main() {
let decoded = url.decode("hello%20world"); // "hello world"
}
decode_queryDecode an application/x-www-form-urlencoded query string into
(key, value) pairs.
Entries are separated by &; each entry must contain = and entries
without one are skipped, matching encode_query's invalid-line convention.
Percent-escapes are decoded like [decode], and + decodes to a space.
import std.net.url;
fn main() {
let pairs = url.decode_query("name=hello+world&x=a%2Bb");
// [("name", "hello world"), ("x", "a+b")]
}
encode_queryBuild a percent-encoded query string from a newline-separated list of
key=value pairs.
Each line should be key=value. Lines without = are skipped. Pairs are
joined with &.
import std.net.url;
fn main() {
let qs = url.encode_query("name=hello world\npage=1");
// "name=hello%20world&page=1"
}
UrlUrlMethodsMethods available on a parsed Url.
Return the URL scheme (e.g. "https").
Return the host name.
Return the explicit port number, if specified.
Return the path component.
Return the query string (without the leading ?).
Return the fragment (without the leading #).
Return the full URL as a string.
Resolve a relative path onto this URL, returning a new Url.