Use Anchor tag to normalize urls(#1828)
This commit is contained in:
parent
fccc9d1b50
commit
e51852d0fc
|
|
@ -274,20 +274,16 @@ export class HttpConnection implements IConnection {
|
||||||
throw new Error(`Cannot resolve '${url}'.`);
|
throw new Error(`Cannot resolve '${url}'.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parser = window.document.createElement("a");
|
// Setting the url to the href propery of an anchor tag handles normalization
|
||||||
parser.href = url;
|
// for us. There are 3 main cases.
|
||||||
|
// 1. Relative path normalization e.g "b" -> "http://localhost:5000/a/b"
|
||||||
|
// 2. Absolute path normalization e.g "/a/b" -> "http://localhost:5000/a/b"
|
||||||
|
// 3. Networkpath reference normalization e.g "//localhost:5000/a/b" -> "http://localhost:5000/a/b"
|
||||||
|
const aTag = window.document.createElement("a");
|
||||||
|
aTag.href = url;
|
||||||
|
|
||||||
const baseUrl = (!parser.protocol || parser.protocol === ":")
|
this.logger.log(LogLevel.Information, `Normalizing '${url}' to '${aTag.href}'.`);
|
||||||
? `${window.document.location.protocol}//${(parser.host || window.document.location.host)}`
|
return aTag.href;
|
||||||
: `${parser.protocol}//${parser.host}`;
|
|
||||||
|
|
||||||
if (!url || url[0] !== "/") {
|
|
||||||
url = "/" + url;
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizedUrl = baseUrl + url;
|
|
||||||
this.logger.log(LogLevel.Information, `Normalizing '${url}' to '${normalizedUrl}'.`);
|
|
||||||
return normalizedUrl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private resolveNegotiateUrl(url: string): string {
|
private resolveNegotiateUrl(url: string): string {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue