Skip to content

Commit 79b783c

Browse files
authored
feat: support sending gzip-encoded buffers (#54)
1 parent e68a909 commit 79b783c

File tree

6 files changed

+456
-263
lines changed

6 files changed

+456
-263
lines changed

src/dummy-http-server/IlpEndpoint.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626

2727
using System.Diagnostics.CodeAnalysis;
28+
using System.IO.Compression;
2829
using System.Text;
2930
using FastEndpoints;
3031

@@ -61,6 +62,15 @@ public async ValueTask<Request> BindAsync(BinderContext ctx, CancellationToken c
6162
// populate and return a request dto object however you please...
6263
var ms = new MemoryStream();
6364
await ctx.HttpContext.Request.Body.CopyToAsync(ms, ct);
65+
var encoding = ctx.HttpContext.Request.Headers.ContentEncoding.FirstOrDefault();
66+
if (encoding != null && encoding == "gzip")
67+
{
68+
ms.Seek(0, SeekOrigin.Begin);
69+
using var gzipStream = new GZipStream(ms, CompressionMode.Decompress);
70+
var outStream = new MemoryStream();
71+
await gzipStream.CopyToAsync(outStream, ct);
72+
ms = outStream;
73+
}
6474
return new Request
6575
{
6676
ByteContent = ms.ToArray(),

0 commit comments

Comments
 (0)