haf / Http.fs

A simple, functional HTTP client library for F#
322 stars 43 forks source link

Question re. GZip and Decompression #156

Open HoraceGonzalez opened 5 years ago

HoraceGonzalez commented 5 years ago

I noticed that the "autoDecompress" feature from 4.x was removed in 5.x. Does this have to do with the way System.Net.Http.HttpClient handles decompression? It appears, now, that this feature must be flipped on during the initialization of HttpClient, which is sort of obnoxious.

Also, the workaround of using Request.createWithClient with a manually constructed HttpClient requires some knowledge of .NET's brain-damaged API. The following is not so obvious/friendly to newcomers:

let handler = HttpClientHandler()
handler.AutomaticDecompression <- DecompressionMethods.GZip ||| DecompressionMethods.Deflate
let client = new HttpClient(handler)
let createGzipEnabledRequest = Request.createWithClient client

Would it make sense to enable AutoDecompression for GZip and Deflate by default? This could be a potentially breaking change, but it seems like a sensible default. Otherwise, perhaps some sort of "builder" API around and HttpClient HttpClientHandler(s) would suffice.

I'd be willing to submit a PR to re-add "friendly" gzip back to the Http.fs API, but I just wanted to check with you folks first beforehand in case there's already been discussion around it.

haf commented 5 years ago

Yes, please. Enable it. It won't be breaking, because whether it's compressed is negotiated via response headers. It would be good to have in the default http client.