diff options
author | Rory& <root@rory.gay> | 2024-02-23 11:23:27 +0000 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-02-23 11:23:27 +0000 |
commit | 3dfb7b81b0fe19d37a7bf1183e248ca10c56277c (patch) | |
tree | 52c36b45c41e32cddd90dfcd110a393158f55675 /LibMatrix/Services | |
parent | Apply syntax style to LibMatrix side projects (diff) | |
download | LibMatrix-3dfb7b81b0fe19d37a7bf1183e248ca10c56277c.tar.xz |
HS emulator
Diffstat (limited to '')
-rw-r--r-- | LibMatrix/Services/HomeserverResolverService.cs | 18 |
1 files changed, 16 insertions, 2 deletions
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(); |