auto random = "http://testdata.org/random".parseUrl; random ~= "int"; writeln(random); // prints "http://testdata.org/random/int"
Convert a relative Url to an absolute Url.
This is designed so that you can scrape a webpage and quickly convert links within the page to Urls you can actually work with, but you're clever; I'm sure you'll find more uses for it.
It's biased toward HTTP family Urls; as one quirk, "//" is interpreted as "same scheme, different everything else", which might not be desirable for all schemes.
This only handles Urls, not URIs; if you pass in 'mailto:bob.dobbs@subgenius.org', for instance, this will give you our best attempt to parse it as a Url.
Examples:
auto base = "https://example.org/passworddb?secure=false".parseUrl; // Download https://example.org/passworddb/by-username/dhasenan download(base.resolve("by-username/dhasenan")); // Download https://example.org/static/style.css download(base.resolve("/static/style.css")); // Download https://cdn.example.net/jquery.js download(base.resolve("https://cdn.example.net/jquery.js"));
auto a = "http://alcyius.com/dndtools/index.html".parseUrl; auto b = a.resolve("contacts/index.html"); assert(b.toString == "http://alcyius.com/dndtools/contacts/index.html");
The append-in-place operator (~=).
The append operator for Urls adds a path element to this Url. It only adds new path elements (or sequences of path elements).
Don't worry about path separators; whether you include them or not, it will just work.