fsprojects / FsHttp

A lightweight F# HTTP library by @SchlenkR and @dawedawe
https://fsprojects.github.io/FsHttp/
Apache License 2.0
424 stars 42 forks source link

Automatic GZip response decompression #104

Closed drhumlen closed 11 months ago

drhumlen commented 2 years ago

We've been struggling with some cryptic responses when trying to parse the json body response from some api we're using. Turned out it was because the response was gzipped. After some trial-and-error, this did the trick:

let! bodyByteStream = resp |> Response.toStreamAsync
use decompressionStream = new GZipStream(bodyByteStream, CompressionMode.Decompress)
let! decompressedBody = decompressionStream |> Stream.readUtf8StringAsync 48_000

The question is, should it be up to each individual FsHttp user to figure out and add decompression steps, or should it be incorporated into the library? Gzip is very common, so maybe there should be an easy way to add it?

I can try to make a PR for it if you can guide me in the general direction. But only if it's in the scope of what FsHttp is supposed to do?

SchlenkR commented 2 years ago

Thank you @drhumlen for the suggestion! This is an interesting idea.

My feeling is:

SchlenkR commented 11 months ago

I changed my opinion which I stated earlier. Since compression is specified on http protocol level, specification of decompression should be the same for all response content functions. Therefore, it's a configuration aspect of the initial request or the returned response.