Skip to content

Commit

Permalink
std.http: remove Headers API
Browse files Browse the repository at this point in the history
I originally removed these in 402f967.
I allowed them to be added back in #15299 because they were smuggled in
alongside a bug fix, however, I wasn't kidding when I said that I wanted
to take the design of std.http in a different direction than using this
data structure.

Instead, some headers are provided via explicit field names populated
while parsing the HTTP request/response, and some are provided via
new fields that support passing extra, arbitrary headers.

This resulted in simplification of logic in many places, as well as
elimination of the possibility of failure in many places. There is
less deinitialization code happening now.

Furthermore, it made it no longer necessary to clone the headers data
structure in order to handle redirects.

http_proxy and https_proxy fields are now pointers since it is common
for them to be unpopulated.

loadDefaultProxies is changed into initDefaultProxies to communicate
that it does not actually load anything from disk or from the network.
The function now is leaky; the API user must pass an already
instantiated arena allocator. Removes the need to deinitialize proxies.

Before, proxies stored arbitrary sets of headers. Now they only store
the authorization value.

Removed the duplicated code between https_proxy and http_proxy. Finally,
parsing failures of the environment variables result in errors being
emitted rather than silently ignoring the proxy.

error.CompressionNotSupported is renamed to
error.CompressionUnsupported, matching the naming convention from all
the other errors in the same set.

Removed documentation comments that were redundant with field and type
names.

Disabling zstd decompression in the server for now; see #18937.

I found some apparently dead code in src/Package/Fetch/git.zig. I want
to check with Ian about this.

I discovered that test/standalone/http.zig is dead code, it is only
being compiled but not being run. Furthermore it hangs at the end if you
run it manually. The previous commits in this branch were written under
the assumption that this test was being run with
`zig build test-standalone`.
  • Loading branch information
andrewrk committed Feb 17, 2024
1 parent 828f0c6 commit 973d604
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 1,108 deletions.
11 changes: 6 additions & 5 deletions lib/std/http.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ const std = @import("std.zig");
pub const Client = @import("http/Client.zig");
pub const Server = @import("http/Server.zig");
pub const protocol = @import("http/protocol.zig");
const headers = @import("http/Headers.zig");

pub const Headers = headers.Headers;
pub const Field = headers.Field;

pub const Version = enum {
@"HTTP/1.0",
Expand All @@ -18,7 +14,7 @@ pub const Version = enum {
/// https://datatracker.ietf.org/doc/html/rfc7231#section-4 Initial definition
///
/// https://datatracker.ietf.org/doc/html/rfc5789#section-2 PATCH
pub const Method = enum(u64) { // TODO: should be u192 or u256, but neither is supported by the C backend, and therefore cannot pass CI
pub const Method = enum(u64) {
GET = parse("GET"),
HEAD = parse("HEAD"),
POST = parse("POST"),
Expand Down Expand Up @@ -309,6 +305,11 @@ pub const Connection = enum {
close,
};

pub const Header = struct {
name: []const u8,
value: []const u8,
};

test {
_ = Client;
_ = Method;
Expand Down
Loading

0 comments on commit 973d604

Please sign in to comment.