about summary refs log tree commit diff
path: root/LibMatrix/Extensions/HttpClientExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--LibMatrix/Extensions/HttpClientExtensions.cs14
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