Merge pull request #309 from vector-im/bwindels/add-protocol-to-hs

add https to homeserver if not already a valid url
This commit is contained in:
Bruno Windels 2021-04-01 15:54:57 +00:00 committed by GitHub
commit cd93077731
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,6 +43,14 @@ export const LoginFailure = createEnum(
"Unknown", "Unknown",
); );
function normalizeHomeserver(homeServer) {
try {
return new URL(homeServer).origin;
} catch (err) {
return new URL(`https://${homeServer}`).origin;
}
}
export class SessionContainer { export class SessionContainer {
constructor({platform, olmPromise, workerPromise}) { constructor({platform, olmPromise, workerPromise}) {
this._platform = platform; this._platform = platform;
@ -96,6 +104,7 @@ export class SessionContainer {
} }
await this._platform.logger.run("login", async log => { await this._platform.logger.run("login", async log => {
this._status.set(LoadStatus.Login); this._status.set(LoadStatus.Login);
homeServer = normalizeHomeserver(homeServer);
const clock = this._platform.clock; const clock = this._platform.clock;
let sessionInfo; let sessionInfo;
try { try {