about summary refs log tree commit diff
path: root/LibMatrix/Extensions/HttpClientExtensions.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-04-19 15:54:30 +0200
committerRory& <root@rory.gay>2024-04-19 15:54:30 +0200
commit440807e02393410327cd86d5ffa007dee98f8954 (patch)
treee750b0bab55a9ee7b507cd48eaa4ccb2ddd25fc0 /LibMatrix/Extensions/HttpClientExtensions.cs
parentFix homeserver resolution, rewrite homeserver initialisation, HSE work (diff)
downloadLibMatrix-440807e02393410327cd86d5ffa007dee98f8954.tar.xz
Partial User-Interactive Authentication, allow skipping homeserver typing
Diffstat (limited to 'LibMatrix/Extensions/HttpClientExtensions.cs')
-rw-r--r--LibMatrix/Extensions/HttpClientExtensions.cs21
1 files changed, 7 insertions, 14 deletions
diff --git a/LibMatrix/Extensions/HttpClientExtensions.cs b/LibMatrix/Extensions/HttpClientExtensions.cs
index 598f8e5..01ce6ea 100644
--- a/LibMatrix/Extensions/HttpClientExtensions.cs
+++ b/LibMatrix/Extensions/HttpClientExtensions.cs
@@ -38,7 +38,7 @@ public class MatrixHttpClient : HttpClient {
         return options;
     }
 
-    public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
+    public async Task<HttpResponseMessage> SendUnhandledAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
         Console.WriteLine($"Sending {request.Method} {BaseAddress}{request.RequestUri} ({Util.BytesToString(request.Content?.Headers.ContentLength ?? 0)})");
         if (request.RequestUri is null) throw new NullReferenceException("RequestUri is null");
         if (!request.RequestUri.IsAbsoluteUri) request.RequestUri = new Uri(BaseAddress, request.RequestUri);
@@ -57,20 +57,13 @@ public class MatrixHttpClient : HttpClient {
             Console.WriteLine(e);
         }
 
-        HttpResponseMessage responseMessage;
-        // try {
-        responseMessage = await base.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
-        // }
-        // catch (Exception e) {
-        // if (requestSettings is { Retries: 0 }) throw;
-        // typeof(HttpRequestMessage).GetField("_sendStatus", BindingFlags.NonPublic | BindingFlags.Instance)
-        // ?.SetValue(request, 0);
-        // await Task.Delay(requestSettings?.RetryDelay ?? 2500, cancellationToken);
-        // if(requestSettings is not null) requestSettings.Retries--;
-        // return await SendAsync(request, cancellationToken);
-        // throw;
-        // }
+        var responseMessage = await base.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
+
+        return responseMessage;
+    }
 
+    public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
+        var responseMessage = await SendUnhandledAsync(request, cancellationToken);
         if (responseMessage.IsSuccessStatusCode) return responseMessage;
 
         //error handling