netio/url.rs#
Source: lib/netio/url.rs
url -- absolute http(s) URLs, references resolved against them, percent encoding, query
strings
Url::parse("https://host:9443/api?x=1") the host checked: a name of letters, digits,
- . _ ~ (no IDN: give its A-label, "xn--..."), an IPv4 address in dotted form, or an IPv6
literal in brackets; a name that ends in a number must be a dotted IPv4 address (no
"0x7f.1" or "2130706433", which some resolvers read as 127.0.0.1); no user:password@
url.join(reference) RFC 3986 5.2 (netpkt::uri): "https://other/x", "//host/x", "/x", "../x"
url.same_origin(&other), url.authority() ("host:port", for CONNECT), url.path()
Bytes beyond ASCII and " < > ` { } in a path or query are percent-encoded; a fragment is
dropped (it never goes to a server).
struct Urlan absolute URL: scheme://host[:port][/path][?query]scheme: String-- "http" or "https" (lower case)host: String-- host name or IP literal (IPv6 without brackets)port: u16target: String-- the path and query ("/" at least)
impl Url
fn parse(s: &str) -> Option<Url>parse; the port defaults to 80 / 443fn is_https(&self) -> boolfn host_header(&self) -> String"host:port" for the Host header (port left out when it is the default)fn with_target(&self, target: &str) -> Urlthe URL with another target ("/api/jobs")fn origin(&self) -> String"https://host:port"fn same_origin(&self, other: &Url) -> boolthe same scheme, host and port (RFC 6454): what a redirect must keep for credentials to go alongfn path(&self) -> &strthe path without the queryfn join(&self, reference: &str) -> Option<Url>a reference resolved against this URL as RFC 3986 5.2 does it (netpkt::uri): absolute ("https://other/x"), network-path ("//host/x"), absolute path ("/x"), relative path ("x", "../x"), query ("?q") or empty; dot segments removed, the fragment dropped. None for another scheme, a reference with spaces or controls, or a URL Url::parse refusesfn percent_encode(s: &str) -> Stringpercent-encode everything but the unreserved characters (RFC 3986)fn percent_decode(s: &str, plus: bool) -> Stringdecode %XX (and '+' as a space in query strings whenplus); invalid escapes stay as they are, invalid UTF-8 becomes U+FFFDfn query_pairs(q: &str) -> Vec<(String, String)>the (key, value) pairs of a query string ("a=1&b=x%20y"), decodedfn split_target(target: &str) -> (&str, &str)split a target into its path and query ("" when there is none)