Skip to content

Commit d88242b

Browse files
feat(client): enable gzip decompression
1 parent a00876a commit d88242b

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/Orb/Core/ClientOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public record struct ClientOptions()
2222
/// <summary>
2323
/// The HTTP client to use for making requests in the SDK.
2424
/// </summary>
25-
public HttpClient HttpClient { get; set; } = new();
25+
public HttpClient HttpClient { get; set; } =
26+
new(new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.Available });
2627

2728
Lazy<string> _baseUrl = new(() =>
2829
Environment.GetEnvironmentVariable("ORB_BASE_URL") ?? EnvironmentUrl.Production
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.IO;
2+
using System.IO.Compression;
3+
using Net = System.Net;
4+
5+
namespace Orb.Core;
6+
7+
static class DecompressionMethods
8+
{
9+
internal static readonly Net::DecompressionMethods Available;
10+
11+
static DecompressionMethods()
12+
{
13+
try
14+
{
15+
// Minimal valid GZip payload (empty body).
16+
var gzipPayload = new byte[]
17+
{
18+
0x1f,
19+
0x8b,
20+
0x08,
21+
0x00,
22+
0x00,
23+
0x00,
24+
0x00,
25+
0x00,
26+
0x00,
27+
0x03,
28+
0x03,
29+
0x00,
30+
0x00,
31+
0x00,
32+
0x00,
33+
0x00,
34+
0x00,
35+
0x00,
36+
0x00,
37+
0x00,
38+
};
39+
using var memoryStream = new MemoryStream(gzipPayload);
40+
using var gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress);
41+
gzipStream.CopyTo(Stream.Null);
42+
Available = Net::DecompressionMethods.GZip;
43+
}
44+
catch
45+
{
46+
Available = Net::DecompressionMethods.None;
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)