private static async Task <HttpContent> GetCompressedContent(HttpContent originalContent) { var ms = new System.IO.MemoryStream(); try { await CompressOriginalContentStream(originalContent, ms).ConfigureAwait(false); ms.Seek(0, System.IO.SeekOrigin.Begin); var compressedContent = new StreamContent(ms); originalContent.CopyHeadersTo(compressedContent); compressedContent.Headers.ContentEncoding.Clear(); compressedContent.Headers.ContentEncoding.Add("gzip"); compressedContent.Headers.ContentLength = ms.Length; originalContent.Dispose(); return(compressedContent); } catch { ms?.Dispose(); throw; } }