Don't reuse http messages

This commit is contained in:
Timothy Baldridge 2020-02-15 16:28:20 -07:00
parent 91f717a25d
commit ff55bfec9f
2 changed files with 29 additions and 0 deletions

View File

@ -53,10 +53,21 @@ namespace Wabbajack.Common.Http
retries++; retries++;
Utils.Log($"Http Connect error to {msg.RequestUri} retry {retries}"); Utils.Log($"Http Connect error to {msg.RequestUri} retry {retries}");
await Task.Delay(100 * retries); await Task.Delay(100 * retries);
msg = CloneMessage(msg);
goto TOP; 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;
}
} }
} }

View File

@ -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<HttpRequestException>(async () => await client.GetAsync("http://blerg.blaz.bloz.buz"));
}
}
}