mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CompatApiClient.Compression;
|
|
|
|
public class DecompressedContent : HttpContent
|
|
{
|
|
private readonly HttpContent content;
|
|
private readonly ICompressor compressor;
|
|
|
|
public DecompressedContent(HttpContent content, ICompressor compressor)
|
|
{
|
|
this.content = content;
|
|
this.compressor = compressor;
|
|
RemoveHeaders();
|
|
}
|
|
|
|
protected override bool TryComputeLength(out long length)
|
|
{
|
|
length = -1;
|
|
return false;
|
|
}
|
|
|
|
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext? context)
|
|
{
|
|
var contentStream = await content.ReadAsStreamAsync().ConfigureAwait(false);
|
|
var decompressedLength = await compressor.DecompressAsync(contentStream, stream).ConfigureAwait(false);
|
|
Headers.ContentLength = decompressedLength;
|
|
}
|
|
|
|
private void RemoveHeaders()
|
|
{
|
|
foreach (var (key, value) in content.Headers)
|
|
Headers.TryAddWithoutValidation(key, value);
|
|
Headers.ContentEncoding.Clear();
|
|
Headers.ContentLength = null;
|
|
}
|
|
} |