refactor: rework how httpclient headers work - #3118
Merged
Merged
Conversation
Adding headers to an HTTP request was a bit awkward due to my desire to avoid having an intermediate representation (e.g. an ArrayList(Header)). Going straight to a curl slist avoids double-copying the headers (first to Zig, then to curl). But the CORS work (#3002) showcases that this micro-optimization simply isn't worth it, since it needs that intermediate representation anyways. And, this change isn't just for CORS. Headers have been a silly pain in the past like unclear ownership, and messy APIs used in _a lot_ of places (WebBotAuth, WebSocket, Fetch, ...) This new approach stores headers on the transfer in an ArrayList. The API is: ``` const transfer = try client.newRequest(.{...}, owner); { errdefer transfer.deinit(); try transfer.addHeader("Over", "9000", .{}); } try transfer.submit(); ``` This: 1 - Eliminates ambiguity about errdefer cleanup responsibility 2 - Eliminates a bunch of stringZ concat that Frame, Config, CDP were doing 3 - Transfer.arena is now available for headers
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
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.
Adding headers to an HTTP request was a bit awkward due to my desire to avoid having an intermediate representation (e.g. an ArrayList(Header)). Going straight to a curl slist avoids double-copying the headers (first to Zig, then to curl).
But the CORS work (#3002) showcases that this micro-optimization simply isn't worth it, since it needs that intermediate representation anyways.
And, this change isn't just for CORS. Headers have been a silly pain in the past like unclear ownership, and messy APIs used in a lot of places (WebBotAuth, WebSocket, Fetch, ...)
This new approach stores headers on the transfer in an ArrayList. The API is:
This:
1 - Eliminates ambiguity about errdefer cleanup responsibility
2 - Eliminates a bunch of stringZ concat that Frame, Config, CDP were doing
3 - Transfer.arena is now available for headers