From c1791edd4d9788d353c618cf1717a88d6c3b547b Mon Sep 17 00:00:00 2001 From: Inex Code Date: Wed, 14 Oct 2020 22:06:13 +0300 Subject: [PATCH] Fix login fail if secondary well-known is invalid --- lib/src/client.dart | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 4abcd23..cdb554c 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -223,28 +223,33 @@ class Client extends MatrixApi { final response = await http .get('https://${MatrixIdOrDomain.domain}/.well-known/matrix/client'); var wellKnown = WellKnownInformations.fromJson(json.decode(response.body)); - if (Uri.parse(wellKnown.mHomeserver.baseUrl).host != MatrixIdOrDomain.domain) { - final response = await http - .get('https://${Uri.parse(wellKnown.mHomeserver.baseUrl).host}/.well-known/matrix/client'); - wellKnown = WellKnownInformations.fromJson(json.decode(response.body)); + if (Uri.parse(wellKnown.mHomeserver.baseUrl).host != + MatrixIdOrDomain.domain) { + final response = await http.get( + 'https://${Uri.parse(wellKnown.mHomeserver.baseUrl).host}/.well-known/matrix/client'); + if (response.statusCode == 200) { + wellKnown = WellKnownInformations.fromJson(json.decode(response.body)); + } } return wellKnown; } - Future getWellKnownInformationsByDomain(dynamic serverUrl) async { + Future getWellKnownInformationsByDomain( + dynamic serverUrl) async { var homeserver = (serverUrl is Uri) ? serverUrl : Uri.parse(serverUrl); - final response = await http - .get('https://${homeserver.host}/.well-known/matrix/client'); + final response = + await http.get('https://${homeserver.host}/.well-known/matrix/client'); var wellKnown = WellKnownInformations.fromJson(json.decode(response.body)); if (Uri.parse(wellKnown.mHomeserver.baseUrl).host != homeserver.host) { - final response = await http - .get('https://${Uri.parse(wellKnown.mHomeserver.baseUrl).host}/.well-known/matrix/client'); - wellKnown = WellKnownInformations.fromJson(json.decode(response.body)); - } + final response = await http.get( + 'https://${Uri.parse(wellKnown.mHomeserver.baseUrl).host}/.well-known/matrix/client'); + if (response.statusCode == 200) { + wellKnown = WellKnownInformations.fromJson(json.decode(response.body)); + } + } return wellKnown; } - /// Checks the supported versions of the Matrix protocol and the supported /// login types. Returns false if the server is not compatible with the /// client.