diff --git a/Test/Flurl.Test/Http/RealHttpTests.cs b/Test/Flurl.Test/Http/RealHttpTests.cs index 2c26539..181fa78 100644 --- a/Test/Flurl.Test/Http/RealHttpTests.cs +++ b/Test/Flurl.Test/Http/RealHttpTests.cs @@ -17,6 +17,19 @@ namespace Flurl.Test.Http [TestFixture, Parallelizable] public class RealHttpTests { + [TestCase("gzip")] + [TestCase("deflate")] + public async Task decompresses_automatically(string encoding) { + var page = DateTime.Now.Ticks % 10 + 1; // vary it a bit to avoid possible rate limit errors + Console.WriteLine(page); + dynamic d2 = await $"https://api.stackexchange.com/2.2/answers?site=stackoverflow&pagesize=10&page={page}" + .WithHeader("Accept-Encoding", encoding) + .GetJsonAsync(); + + Assert.AreEqual(10, d2.items.Count); + Assert.IsTrue(d2.has_more); + } + [Test] public async Task can_download_file() { var folder = "c:\\flurl-test-" + Guid.NewGuid(); // random so parallel tests don't trip over each other diff --git a/src/Flurl.Http/Configuration/DefaultHttpClientFactory.cs b/src/Flurl.Http/Configuration/DefaultHttpClientFactory.cs index 4439676..0e5fc95 100644 --- a/src/Flurl.Http/Configuration/DefaultHttpClientFactory.cs +++ b/src/Flurl.Http/Configuration/DefaultHttpClientFactory.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Net.Http; namespace Flurl.Http.Configuration @@ -28,7 +29,10 @@ namespace Flurl.Http.Configuration /// customize the result. /// public virtual HttpMessageHandler CreateMessageHandler() { - return new HttpClientHandler(); + return new HttpClientHandler { + // #266 + AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate + }; } } } \ No newline at end of file