Support gzip compressed content for the synchronous http client #601
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It seems like some servers, notably CloudFront, will send gzip content even if we don't specify Accept-Encoding: gzip.
This PR adds a gzip support on synchronous requests. I'll do asynchronous handling separately.
I ran into difficulties implementing this. The core of the issue is that Zig's compression works on Readers, or similar reader-like behavior. Which is to say, they all expect to be given a source of data (a reader), which they can 'read' more data from. This approach doesn't work well with asynchronous code. For example, the TLS library, which is async-friendly, expects to be called when data is available (i.e. we call it with new data, instead of it calling us asking for new data).
I thought I'd at least be able to implement this efficiently with the synchronous-side of our HTTP client, but our body reader, which is shared by the async and sync parts of our code, is also async-friendly; it expects to be given data when available rather than having to ask for more data. I couldn't come up with a good way to bridge these two paradigms.
So, for now at least, when a gzip response is received, we read the body in memory. The existing "peek" feature of our Response is used. The new
CompressedReadercan be thought of as "peeking" the [entire] response body and doing some through a gzip decompressor.The only good thing about this PR is that the new logic is fairly well isolated.