chris-website/source/nl/netsoj/chris/blog/url.d
2021-11-18 19:28:24 +01:00

28 lines
615 B
D

module nl.netsoj.chris.blog.url;
import std.exception;
import vibe.inet.url;
URL resolveURL(URL source, string other) {
URL otherUrl = URL(other);
if (otherUrl.schema.length > 0 || otherUrl.host.length > 0) {
return otherUrl;
}
if (otherUrl.schema.length == 0) {
enforce(source.schema.length > 0, "Source URL must have a scheme to resolve the other URL");
otherUrl.schema = source.schema;
}
if (otherUrl.host.length == 0) {
otherUrl.host = source.host;
otherUrl.port = source.port;
if (!otherUrl.path.absolute) {
otherUrl.path = source.path ~ otherUrl.path;
}
}
return otherUrl;
}