Explicitly set content lenght

This commit is contained in:
Marius Vasile Vușcan 2025-09-10 14:37:07 +03:00
parent dd93c5947b
commit 5a0112fbd6
No known key found for this signature in database
GPG key ID: E0EC75631D902E06

View file

@ -216,6 +216,21 @@ public abstract class SendHttpRequestBase(string? source = null, int? line = nul
async Task<HttpResponseMessage> SendRequestAsyncCore(CancellationToken ct = default)
{
var request = PrepareRequest(context);
if (request.Content != null && request.Content.Headers.ContentLength is null)
{
var bytes = await request.Content.ReadAsByteArrayAsync(ct);
var buffered = new ByteArrayContent(bytes);
foreach (var h in request.Content.Headers)
buffered.Headers.TryAddWithoutValidation(h.Key, h.Value);
buffered.Headers.ContentLength = bytes.Length;
request.Content = buffered;
}
return await httpClient.SendAsync(request, ct);
}
}