about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs
diff options
context:
space:
mode:
authorEmma@Rory& <root@rory.gay>2023-07-26 21:02:50 +0200
committerEmma@Rory& <root@rory.gay>2023-07-26 21:02:50 +0200
commit2e89a0717a60598904c92499adb7e01b2075fbb9 (patch)
tree56b9b7f07180154d9d98dafa91d7c16a0a872100 /MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs
parentStart of nix flake (diff)
downloadMatrixUtils-2e89a0717a60598904c92499adb7e01b2075fbb9.tar.xz
MRU desktop start
Diffstat (limited to 'MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs')
-rw-r--r--MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs11
1 files changed, 10 insertions, 1 deletions
diff --git a/MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs b/MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs
index 9ac9c6b..009338a 100644
--- a/MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs
+++ b/MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs
@@ -38,7 +38,7 @@ public class MatrixHttpClient : HttpClient {
             if (content.StartsWith('{')) {
                 var ex = JsonSerializer.Deserialize<MatrixException>(content);
                 ex.RawContent = content;
-                Console.WriteLine($"Failed to send request: {ex}");
+                // Console.WriteLine($"Failed to send request: {ex}");
                 if (ex?.RetryAfterMs is not null) {
                     await Task.Delay(ex.RetryAfterMs.Value, cancellationToken);
                     typeof(HttpRequestMessage).GetField("_sendStatus", BindingFlags.NonPublic | BindingFlags.Instance)
@@ -64,4 +64,13 @@ public class MatrixHttpClient : HttpClient {
         await using var responseStream = await response.Content.ReadAsStreamAsync(cancellationToken);
         return await JsonSerializer.DeserializeAsync<T>(responseStream, cancellationToken: cancellationToken);
     }
+
+    // GetStreamAsync
+    public async Task<Stream> GetStreamAsync(string requestUri, CancellationToken cancellationToken = default) {
+        var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
+        request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
+        var response = await SendAsync(request, cancellationToken);
+        response.EnsureSuccessStatusCode();
+        return await response.Content.ReadAsStreamAsync(cancellationToken);
+    }
 }