mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-09-17 00:17:07 -04:00
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 (https://github.com/lightpanda-io/browser/pull/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