about summary refs log tree commit diff
path: root/LibMatrix/Extensions/HttpClientExtensions.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-11 15:52:28 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-11 15:52:28 +0200
commita98f16f1aaa72aa68278420a61d8ce897639416f (patch)
tree959044674e30b9fe16dc909e8e44af1483c99bc8 /LibMatrix/Extensions/HttpClientExtensions.cs
parentFix bug with event sending, make initial sync detection deterministic (diff)
downloadLibMatrix-a98f16f1aaa72aa68278420a61d8ce897639416f.tar.xz
Added options to skip inviting already invited/joined/left users, added option to join room if it already exists when trying to create
Diffstat (limited to 'LibMatrix/Extensions/HttpClientExtensions.cs')
-rw-r--r--LibMatrix/Extensions/HttpClientExtensions.cs9
1 files changed, 9 insertions, 0 deletions
diff --git a/LibMatrix/Extensions/HttpClientExtensions.cs b/LibMatrix/Extensions/HttpClientExtensions.cs
index 6f1eab6..2faf0d5 100644
--- a/LibMatrix/Extensions/HttpClientExtensions.cs
+++ b/LibMatrix/Extensions/HttpClientExtensions.cs
@@ -98,4 +98,13 @@ public class MatrixHttpClient : HttpClient {
             Encoding.UTF8, "application/json");
         return await SendAsync(request, cancellationToken);
     }
+
+    public async Task<HttpResponseMessage> PostAsJsonAsync<T>([StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, T value, JsonSerializerOptions? options = null,
+        CancellationToken cancellationToken = default) {
+        var request = new HttpRequestMessage(HttpMethod.Post, requestUri);
+        request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
+        request.Content = new StringContent(JsonSerializer.Serialize(value, value.GetType(), options ?? new() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }),
+            Encoding.UTF8, "application/json");
+        return await SendAsync(request, cancellationToken);
+    }
 }