Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 3d8d4c7

Browse files
committed
Merge pull request #2651 from kapilash/AutoDecompression
Merged. Thanks all.
2 parents b9fc9e6 + 18aec34 commit 3d8d4c7

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/Common/src/Interop/Unix/libcurl/Interop.libcurl_types.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal static partial class CURLoption
2222
internal const int CURLOPT_WRITEDATA = CurlOptionObjectPointBase + 1;
2323
internal const int CURLOPT_PROXY = CurlOptionObjectPointBase + 4;
2424
internal const int CURLOPT_PROXYUSERPWD = CurlOptionObjectPointBase + 6;
25+
internal const int CURLOPT_ACCEPTENCODING = CurlOptionObjectPointBase + 102;
2526
}
2627

2728
// Class for constants defined for the enum CURLINFO in curl.h

src/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using System.Net.Http;
77
using System.Runtime.InteropServices;
8+
using System.Text;
89
using System.Threading;
910
using System.Threading.Tasks;
1011

@@ -21,6 +22,8 @@ internal class CurlHandler : HttpMessageHandler
2122
#region Constants
2223

2324
private const string UriSchemeHttps = "https";
25+
private const string EncodingNameGzip = "gzip";
26+
private const string EncodingNameDeflate = "deflate";
2427
private readonly static string[] AuthenticationSchemes = { "Negotiate", "Digest", "Basic" }; // the order in which libcurl goes over authentication schemes
2528
#endregion
2629

@@ -32,6 +35,7 @@ internal class CurlHandler : HttpMessageHandler
3235
private IWebProxy _proxy = null;
3336
private ICredentials _serverCredentials = null;
3437
private ProxyUsePolicy _proxyPolicy = ProxyUsePolicy.UseDefaultProxy;
38+
private DecompressionMethods _automaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
3539

3640
#endregion
3741

@@ -123,6 +127,27 @@ internal ClientCertificateOption ClientCertificateOptions
123127
}
124128
}
125129

130+
internal bool SupportsAutomaticDecompression
131+
{
132+
get
133+
{
134+
return true;
135+
}
136+
}
137+
138+
internal DecompressionMethods AutomaticDecompression
139+
{
140+
get
141+
{
142+
return _automaticDecompression;
143+
}
144+
set
145+
{
146+
CheckDisposedOrStarted();
147+
_automaticDecompression = value;
148+
}
149+
}
150+
126151
#endregion
127152

128153
protected override void Dispose(bool disposing)
@@ -245,11 +270,26 @@ private SafeCurlHandle CreateRequestHandle(RequestCompletionSource state)
245270
}
246271

247272
SetProxyOptions(state, requestHandle);
273+
SetRequestHandleDecompressionOptions(requestHandle);
248274
// TODO: Handle headers and other options
249275

250276
return requestHandle;
251277
}
252278

279+
private void SetRequestHandleDecompressionOptions(SafeCurlHandle requestHandle)
280+
{
281+
bool gzip = (AutomaticDecompression & DecompressionMethods.GZip) != 0;
282+
bool deflate = (AutomaticDecompression & DecompressionMethods.Deflate) != 0;
283+
if (gzip || deflate)
284+
{
285+
string encoding = (gzip && deflate) ?
286+
EncodingNameGzip + "," + EncodingNameDeflate :
287+
gzip ? EncodingNameGzip :
288+
EncodingNameDeflate ;
289+
Interop.libcurl.curl_easy_setopt(requestHandle, CURLoption.CURLOPT_ACCEPTENCODING, encoding);
290+
}
291+
}
292+
253293
private static void SetProxyOptions(RequestCompletionSource state, SafeCurlHandle requestHandle)
254294
{
255295
var requestUri = state.RequestMessage.RequestUri;

src/System.Net.Http/src/System/Net/Http/Unix/HttpClientHandler.Unix.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class HttpClientHandler : HttpMessageHandler
1212

1313
public virtual bool SupportsAutomaticDecompression
1414
{
15-
get { throw NotImplemented.ByDesignWithMessage("HTTP stack not implemented"); }
15+
get { return _curlHandler.SupportsAutomaticDecompression; }
1616
}
1717

1818
public virtual bool SupportsProxy
@@ -51,8 +51,8 @@ public ClientCertificateOption ClientCertificateOptions
5151

5252
public DecompressionMethods AutomaticDecompression
5353
{
54-
get { throw NotImplemented.ByDesignWithMessage("HTTP stack not implemented"); }
55-
set { throw NotImplemented.ByDesignWithMessage("HTTP stack not implemented"); }
54+
get { return _curlHandler.AutomaticDecompression; }
55+
set { _curlHandler.AutomaticDecompression = value; }
5656
}
5757

5858
public bool UseProxy

0 commit comments

Comments
 (0)