about summary refs log tree commit diff
path: root/LibMatrix
diff options
context:
space:
mode:
Diffstat (limited to 'LibMatrix')
-rw-r--r--LibMatrix/Homeservers/RemoteHomeServer.cs2
-rw-r--r--LibMatrix/MatrixException.cs2
-rw-r--r--LibMatrix/Services/HomeserverResolverService.cs18
3 files changed, 18 insertions, 4 deletions
diff --git a/LibMatrix/Homeservers/RemoteHomeServer.cs b/LibMatrix/Homeservers/RemoteHomeServer.cs

index 5c7d254..422a8a9 100644 --- a/LibMatrix/Homeservers/RemoteHomeServer.cs +++ b/LibMatrix/Homeservers/RemoteHomeServer.cs
@@ -35,7 +35,7 @@ public class RemoteHomeserver(string baseUrl) { homeserver.ClientHttpClient = new MatrixHttpClient { BaseAddress = new Uri(proxy ?? homeserver.WellKnownUris.Client ?? throw new InvalidOperationException($"Failed to resolve homeserver client URI for {baseUrl}")), - Timeout = TimeSpan.FromSeconds(120) + Timeout = TimeSpan.FromSeconds(300) }; homeserver.FederationClient = await FederationClient.TryCreate(baseUrl, proxy); diff --git a/LibMatrix/MatrixException.cs b/LibMatrix/MatrixException.cs
index 86dbce4..8ec8fd5 100644 --- a/LibMatrix/MatrixException.cs +++ b/LibMatrix/MatrixException.cs
@@ -20,7 +20,7 @@ public class MatrixException : Exception { public string RawContent { get; set; } - public object GetAsObject() => new { ErrorCode, Error, SoftLogout, RetryAfterMs }; + public object GetAsObject() => new { errcode = ErrorCode, error = Error, soft_logout = SoftLogout, retry_after_ms = RetryAfterMs }; public string GetAsJson() => GetAsObject().ToJson(ignoreNull: true); public override string Message => diff --git a/LibMatrix/Services/HomeserverResolverService.cs b/LibMatrix/Services/HomeserverResolverService.cs
index a4a18e5..bcef541 100644 --- a/LibMatrix/Services/HomeserverResolverService.cs +++ b/LibMatrix/Services/HomeserverResolverService.cs
@@ -34,7 +34,14 @@ public class HomeserverResolverService(ILogger<HomeserverResolverService>? logge } private async Task<string?> _tryResolveFromClientWellknown(string homeserver) { - if (!homeserver.StartsWith("http")) homeserver = "https://" + homeserver; + if (!homeserver.StartsWith("http")) { + if (await _httpClient.CheckSuccessStatus($"https://{homeserver}/.well-known/matrix/client")) + homeserver = "https://" + homeserver; + else if (await _httpClient.CheckSuccessStatus($"http://{homeserver}/.well-known/matrix/client")) { + homeserver = "http://" + homeserver; + } + } + try { var resp = await _httpClient.GetFromJsonAsync<JsonElement>($"{homeserver}/.well-known/matrix/client"); var hs = resp.GetProperty("m.homeserver").GetProperty("base_url").GetString(); @@ -49,7 +56,14 @@ public class HomeserverResolverService(ILogger<HomeserverResolverService>? logge } private async Task<string?> _tryResolveFromServerWellknown(string homeserver) { - if (!homeserver.StartsWith("http")) homeserver = "https://" + homeserver; + if (!homeserver.StartsWith("http")) { + if (await _httpClient.CheckSuccessStatus($"https://{homeserver}/.well-known/matrix/server")) + homeserver = "https://" + homeserver; + else if (await _httpClient.CheckSuccessStatus($"http://{homeserver}/.well-known/matrix/server")) { + homeserver = "http://" + homeserver; + } + } + try { var resp = await _httpClient.GetFromJsonAsync<JsonElement>($"{homeserver}/.well-known/matrix/server"); var hs = resp.GetProperty("m.server").GetString();