diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-12-23 08:54:11 +0100 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-12-23 08:54:11 +0100 |
commit | 14bcb748a853f7cd2afce40477bd2b0cb14ad7e6 (patch) | |
tree | 16dc78593288d715c93b5aee2903318c15a3e201 /LibMatrix/Extensions | |
parent | Cleanup (diff) | |
download | LibMatrix-14bcb748a853f7cd2afce40477bd2b0cb14ad7e6.tar.xz |
User impersonation support (appservice identity assertion), non-AsyncEnumerable room member lookup
Diffstat (limited to 'LibMatrix/Extensions')
-rw-r--r-- | LibMatrix/Extensions/HttpClientExtensions.cs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/LibMatrix/Extensions/HttpClientExtensions.cs b/LibMatrix/Extensions/HttpClientExtensions.cs index 93e1441..17cc31d 100644 --- a/LibMatrix/Extensions/HttpClientExtensions.cs +++ b/LibMatrix/Extensions/HttpClientExtensions.cs @@ -25,6 +25,7 @@ public static class HttpClientExtensions { } public class MatrixHttpClient : HttpClient { + public Dictionary<string, string> AdditionalQueryParameters { get; set; } = new(); internal string? AssertedUserId { get; set; } private JsonSerializerOptions GetJsonSerializerOptions(JsonSerializerOptions? options = null) { @@ -38,7 +39,11 @@ public class MatrixHttpClient : HttpClient { public override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (request.RequestUri is null) throw new NullReferenceException("RequestUri is null"); - if (AssertedUserId is not null) request.RequestUri = request.RequestUri.AddQuery("user_id", AssertedUserId); + if (!request.RequestUri.IsAbsoluteUri) request.RequestUri = new Uri(BaseAddress, request.RequestUri); + // if (AssertedUserId is not null) request.RequestUri = request.RequestUri.AddQuery("user_id", AssertedUserId); + foreach (var (key, value) in AdditionalQueryParameters) { + request.RequestUri = request.RequestUri.AddQuery(key, value); + } Console.WriteLine($"Sending request to {request.RequestUri}"); @@ -86,6 +91,11 @@ public class MatrixHttpClient : HttpClient { return await SendAsync(request, cancellationToken); } + // GetAsync + public Task<HttpResponseMessage> GetAsync([StringSyntax("Uri")] string? requestUri, CancellationToken? cancellationToken = null) { + return SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUri), cancellationToken ?? CancellationToken.None); + } + // GetFromJsonAsync public async Task<T> GetFromJsonAsync<T>(string requestUri, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default) { options = GetJsonSerializerOptions(options); @@ -175,4 +185,4 @@ public class JsonDecimalStringConverter : JsonConverter<decimal> { public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerOptions options) => writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); -} +} \ No newline at end of file |