#266 automatic decompression

This commit is contained in:
Todd Menier 2018-01-01 12:00:43 -06:00
parent 99331a46fd
commit 9fd1ffefb1
2 changed files with 18 additions and 1 deletions

View File

@ -17,6 +17,19 @@ namespace Flurl.Test.Http
[TestFixture, Parallelizable] [TestFixture, Parallelizable]
public class RealHttpTests 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] [Test]
public async Task can_download_file() { public async Task can_download_file() {
var folder = "c:\\flurl-test-" + Guid.NewGuid(); // random so parallel tests don't trip over each other var folder = "c:\\flurl-test-" + Guid.NewGuid(); // random so parallel tests don't trip over each other

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Net;
using System.Net.Http; using System.Net.Http;
namespace Flurl.Http.Configuration namespace Flurl.Http.Configuration
@ -28,7 +29,10 @@ namespace Flurl.Http.Configuration
/// customize the result. /// customize the result.
/// </summary> /// </summary>
public virtual HttpMessageHandler CreateMessageHandler() { public virtual HttpMessageHandler CreateMessageHandler() {
return new HttpClientHandler(); return new HttpClientHandler {
// #266
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};
} }
} }
} }