fix: Provide a reasonable well-known fallback
If the well-known look fails (not json, 404, etc.) we should assume a reasonable fallback (domain part with https prepended). As clients are expected to call Client.checkHomeserver on the resulting domain anyways we can safely assume this default, as it is still validated, if there is actually a matrix homeserver running on that endpoint.
This commit is contained in:
parent
2980f6d8e3
commit
e86353a412
|
|
@ -296,16 +296,26 @@ class Client extends MatrixApi {
|
||||||
Future<WellKnownInformation> getWellKnownInformationsByUserId(
|
Future<WellKnownInformation> getWellKnownInformationsByUserId(
|
||||||
String MatrixIdOrDomain,
|
String MatrixIdOrDomain,
|
||||||
) async {
|
) async {
|
||||||
final response = await http
|
|
||||||
.get(Uri.https(MatrixIdOrDomain.domain, '/.well-known/matrix/client'));
|
|
||||||
var respBody = response.body;
|
|
||||||
try {
|
try {
|
||||||
respBody = utf8.decode(response.bodyBytes);
|
final response = await http.get(
|
||||||
|
Uri.https(MatrixIdOrDomain.domain, '/.well-known/matrix/client'));
|
||||||
|
var respBody = response.body;
|
||||||
|
try {
|
||||||
|
respBody = utf8.decode(response.bodyBytes);
|
||||||
|
} catch (_) {
|
||||||
|
// No-OP
|
||||||
|
}
|
||||||
|
final rawJson = json.decode(respBody);
|
||||||
|
return WellKnownInformation.fromJson(rawJson);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// No-OP
|
// we got an error processing or fetching the well-known information, let's
|
||||||
|
// provide a reasonable fallback.
|
||||||
|
return WellKnownInformation.fromJson(<String, dynamic>{
|
||||||
|
'm.homeserver': <String, dynamic>{
|
||||||
|
'base_url': Uri.https(MatrixIdOrDomain.domain, '').toString(),
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
final rawJson = json.decode(respBody);
|
|
||||||
return WellKnownInformation.fromJson(rawJson);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated('Use [checkHomeserver] instead.')
|
@Deprecated('Use [checkHomeserver] instead.')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue