diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-30 03:36:58 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-30 03:36:58 +0200 |
commit | bb8c2637af3b7982e7a4b2fd15e2fbec613d0848 (patch) | |
tree | b8075ba7e507aad3f96f354712ad920ac421e474 /MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs | |
parent | Update stuff (diff) | |
download | MatrixUtils-bb8c2637af3b7982e7a4b2fd15e2fbec613d0848.tar.xz |
Todays progress
Diffstat (limited to 'MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs')
-rw-r--r-- | MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs b/MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs index 47b3121..852e1d8 100644 --- a/MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs +++ b/MatrixRoomUtils.Core/Extensions/HttpClientExtensions.cs @@ -1,3 +1,4 @@ +using System.Reflection; using System.Text.Json; namespace MatrixRoomUtils.Core.Extensions; @@ -18,23 +19,35 @@ public static class HttpClientExtensions { public class MatrixHttpClient : HttpClient { public override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { + try + { + HttpRequestOptionsKey<bool> WebAssemblyEnableStreamingResponseKey = new HttpRequestOptionsKey<bool>("WebAssemblyEnableStreamingResponse"); + request.Options.Set(WebAssemblyEnableStreamingResponseKey, true); + // var asm = Assembly.Load("Microsoft.AspNetCore.Components.WebAssembly"); + // var browserHttpHandlerType = asm.GetType("Microsoft.AspNetCore.Components.WebAssembly.Http.WebAssemblyHttpRequestMessageExtensions", true); + // var browserHttpHandlerMethod = browserHttpHandlerType.GetMethod("SetBrowserResponseStreamingEnabled", BindingFlags.Public | BindingFlags.Static); + // browserHttpHandlerMethod?.Invoke(null, new object[] {request, true}); + } + catch (Exception e) + { + Console.WriteLine("Failed to set browser response streaming:"); + Console.WriteLine(e); + } var a = await base.SendAsync(request, cancellationToken); if (!a.IsSuccessStatusCode) { Console.WriteLine($"Failed to send request: {a.StatusCode}"); var content = await a.Content.ReadAsStringAsync(cancellationToken); if (content.StartsWith('{')) { var ex = JsonSerializer.Deserialize<MatrixException>(content); - if (ex?.RetryAfterMs != null) { + if (ex?.RetryAfterMs is not null) { await Task.Delay(ex.RetryAfterMs.Value, cancellationToken); + typeof(HttpRequestMessage).GetField("_sendStatus", BindingFlags.NonPublic | BindingFlags.Instance)?.SetValue(request, 0); return await SendAsync(request, cancellationToken); } - throw ex!; } - throw new InvalidDataException("Encountered invalid data:\n" + content); } - return a; } } \ No newline at end of file |