-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpExtensions.cs
More file actions
31 lines (24 loc) · 845 Bytes
/
Copy pathHttpExtensions.cs
File metadata and controls
31 lines (24 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Net.Http.Headers;
namespace ZstdHttpClient;
public static class HttpExtensions
{
private static readonly StringWithQualityHeaderValue ZStdHeader = new StringWithQualityHeaderValue("zstd", 1);
public static async Task<HttpResponseMessage> GetAsync(
this HttpClient client,
string url,
CompressionType cp
)
{
if (cp == CompressionType.Zstd)
client.DefaultRequestHeaders.AcceptEncoding.Add(ZStdHeader);
var response = await client.GetAsync(url);
if (cp == CompressionType.Zstd)
{
if (response.Content.Headers.ContentEncoding.LastOrDefault() == "zstd")
{
response.Content = new ZStdHttpContent(response.Content);
}
}
return response;
}
}