diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-11-05 18:17:11 +0100 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-11-05 18:17:11 +0100 |
commit | 1d6399d7f4649472333da946669ce9f1fa349b89 (patch) | |
tree | 95baedad8e42956de6d4d339d5c4fdc44ae2396b /LibMatrix/Extensions/HttpClientExtensions.cs | |
parent | split client and server http client for homeservers (diff) | |
download | LibMatrix-1d6399d7f4649472333da946669ce9f1fa349b89.tar.xz |
Cleanup, fixes, fix proxy support
Diffstat (limited to 'LibMatrix/Extensions/HttpClientExtensions.cs')
-rw-r--r-- | LibMatrix/Extensions/HttpClientExtensions.cs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/LibMatrix/Extensions/HttpClientExtensions.cs b/LibMatrix/Extensions/HttpClientExtensions.cs index 5bb0dc2..913864e 100644 --- a/LibMatrix/Extensions/HttpClientExtensions.cs +++ b/LibMatrix/Extensions/HttpClientExtensions.cs @@ -53,11 +53,21 @@ public class MatrixHttpClient : HttpClient { Console.WriteLine(e); } - var a = await base.SendAsync(request, cancellationToken); - if (a.IsSuccessStatusCode) return a; + HttpResponseMessage responseMessage; + try { + responseMessage = await base.SendAsync(request, cancellationToken); + } + catch (Exception e) { + typeof(HttpRequestMessage).GetField("_sendStatus", BindingFlags.NonPublic | BindingFlags.Instance) + ?.SetValue(request, 0); + await Task.Delay(2500); + return await SendAsync(request, cancellationToken); + } + + if (responseMessage.IsSuccessStatusCode) return responseMessage; //error handling - var content = await a.Content.ReadAsStringAsync(cancellationToken); + var content = await responseMessage.Content.ReadAsStringAsync(cancellationToken); if (content.Length == 0) throw new MatrixException() { ErrorCode = "M_UNKNOWN", |