async Task AppendBody(HttpRequestMessage requestMessage, Stream body, CancellationToken cancellationToken) { if (!body.CanSeek) { // we need to compute the ContentHash for this body meaning that we need to have seekable version, hence copy to a memory stream first var memoryStream = new MemoryStream(); await body.CopyToAsync(memoryStream, 81920, cancellationToken); memoryStream.Position = 0; body = memoryStream; } var bodyStartPosition = body.Position; var contentHashBytes = await ContentHashHelper.ComputeMD5HashBytes(body, cancellationToken); body.Position = bodyStartPosition; requestMessage.Content = new StreamContent(body); requestMessage.Content.Headers.ContentMD5 = contentHashBytes; }