http/Client: Allow passing a connection to fetch()

This allows developers to easily use fetch for unix sockets,
instead of having to use the low-level http.Client API.
This commit is contained in:
Christopher Davis 2025-05-20 22:04:28 -04:00
parent 6bd1f508c9
commit 90fcac603a

View file

@ -1406,7 +1406,7 @@ pub fn connectUnix(client: *Client, path: []const u8) ConnectUnixError!*Connecti
const conn = try client.allocator.create(Connection);
errdefer client.allocator.destroy(conn);
const stream = try std.net.connectUnixSocket(path);
errdefer stream.close();
@ -1707,6 +1707,9 @@ pub const FetchOptions = struct {
raw_uri: bool = false,
keep_alive: bool = true,
/// Must be an already acquired connection.
connection: ?*Connection = null,
/// Standard headers that have default, but overridable, behavior.
headers: Request.Headers = .{},
/// These headers are kept including when following a redirect to a
@ -1756,6 +1759,7 @@ pub fn fetch(client: *Client, options: FetchOptions) !FetchResult {
.extra_headers = options.extra_headers,
.privileged_headers = options.privileged_headers,
.keep_alive = options.keep_alive,
.connection = options.connection,
});
defer req.deinit();