Skip to content

Conversation

@karlseguin
Copy link
Collaborator

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 CompressedReader can 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.

@karlseguin karlseguin merged commit 17ed502 into main May 8, 2025
14 of 15 checks passed
@karlseguin karlseguin deleted the http_gzip branch May 8, 2025 05:52
@github-actions github-actions bot locked and limited conversation to collaborators May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants