From ff55bfec9f7c3215ab06e52917d4cf9d1c3e3079 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Sat, 15 Feb 2020 16:28:20 -0700 Subject: [PATCH] Don't reuse http messages --- Wabbajack.Common/Http/Client.cs | 11 +++++++++++ Wabbajack.Test/HttpClientTests.cs | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 Wabbajack.Test/HttpClientTests.cs diff --git a/Wabbajack.Common/Http/Client.cs b/Wabbajack.Common/Http/Client.cs index d6393820..20058004 100644 --- a/Wabbajack.Common/Http/Client.cs +++ b/Wabbajack.Common/Http/Client.cs @@ -53,10 +53,21 @@ namespace Wabbajack.Common.Http retries++; Utils.Log($"Http Connect error to {msg.RequestUri} retry {retries}"); await Task.Delay(100 * retries); + msg = CloneMessage(msg); goto TOP; } } + + private HttpRequestMessage CloneMessage(HttpRequestMessage msg) + { + var new_message = new HttpRequestMessage(msg.Method, msg.RequestUri); + foreach (var header in msg.Headers) + new_message.Headers.Add(header.Key, header.Value); + new_message.Content = msg.Content; + return new_message; + + } } } diff --git a/Wabbajack.Test/HttpClientTests.cs b/Wabbajack.Test/HttpClientTests.cs new file mode 100644 index 00000000..f43715ba --- /dev/null +++ b/Wabbajack.Test/HttpClientTests.cs @@ -0,0 +1,18 @@ +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Wabbajack.Test +{ + [TestClass] + public class HttpClientTests + { + [TestMethod] + public async Task DoesntReuseHttpMessages() + { + var client = new Common.Http.Client(); + // If we reuse the HTTP message this will throw a invalid operation exception + await Assert.ThrowsExceptionAsync(async () => await client.GetAsync("http://blerg.blaz.bloz.buz")); + } + } +}