http
http copied to clipboard
Implement a correct header multimap
The http core types must define a correct header multimap.
Some good work has already been done by @daurnimator and other contributors in the standard library, and I feel like it would be great to embed it within the Zig HTTP core types library.
Pros:
- Do not rewrite something from scratch
Cons:
- Does not have yet a non-allocating API (reported in https://github.com/ziglang/zig/issues/5875)
- Some implementation details feels unecessary to me (cf: never-indexed fields), but I my understanding of the HTTP protocol is very limited to be really confident here :/
First rework step made with the PR https://github.com/ducdetronquito/http/pull/7.
The idea is to avoid the complexity of a proper multimap implementation by providing a simple list of headers.
Advantages:
- Very simple implementation
- Preserve headers order (cool for proxies)
Drawbacks:
- Probably a performance penalty, but I haven't benchmark it. I imagine it will only have an impact compared to a hashmap for high number of items.
- No API to remove a header: I have no use-case for it yet
Remarks:
As of yet, lookup and addition of headers are case-insensitive for standard headers, but case sensitive for custom headers.
var headers = Headers.init(std.testing.allocator);
defer headers.deinit();
try headers.add("Content-Length", "10");
try headers.add("Gotta-Go", "Fast");
headers.get("Content-Lenght"); // --> OK
headers.get("content-length"); // --> OK
headers.get("Gotta-Go"); // --> OK
headers.get("gotta-go"); // --> KO