-
Notifications
You must be signed in to change notification settings - Fork 287
Replace zig-async-io with a custom HTTP client #482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Drain response prior to redirect.
Switch to non-blocking sockets. Fix TLS handshake/receive/send ordering
Improve test server handshake performance, allowing for a few more fuzz iterations without making tests unbearably slow.
Add more fuzz tests around async tls.
Retry on test timeout for slower machines (i.e. CI build), while also reducing wait time for faster builds.
This was referenced Mar 25, 2025
Closed
krichprollsch
approved these changes
Mar 26, 2025
Member
krichprollsch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome 👏 Thank you so much @karlseguin 🙏
Switch generic http_client error level from warn to err
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
#466
The two main goals are:
1 - Have a single HTTP client that does both sync and async. This makes it easier
to add things like proxy support, and might help with things like cookies.
2 - Maintaining our own HTTP client isn't trivial, especially given that
we're likely to encounter non-conforming servers. But, this removes the need
to maintain zig-async-io, which is a fork of [a small part] of the stdlib and
tls.zig. This itself is non-trivial. Also, if we do run into weird server
behavior, we'd have to maintain that in std.http.Client unless we could get
a PR accepted.
What's currently missing
1 -
Redirect handling (critical to add this)2 -
Chunked encoding response (critical to add this)3 - Connection pooling (could be added after)
4 - Compression (could be added after)
If you try "fetch" or "serve" a page that doesn't do a direct and that doesn't
use chunked encoding, it should work. Puppeteer demo works.
This is built on the zig-0.14 branch. I initially started working against main
(Zig 0.13) but then I noticed that tls.zig has very useful support for a
generic async loop in its master. It's a pretty big game changer and makes the
integration with our event loop trivial (I'm currently pointing to my own fork,
but I'm hopeful that my PR (ianic/tls.zig#8)
will be accepted, and if not, it's a simple change to accommodate tls.zig as-is).
The async API is simpler, with as single callback. A simplified example:
Generally, the integration with browser an XMLHttpRequest was rushed. The focus
has been on
src/http/client.zig.Finally, I've added the tls.zig dependency as a Zig package (build.zig.zon)
rather than a submodule. I assume submodules were chosen back when Zig didn't
have a package manager.