Skip to content

Fix connectUnix and allow passing connections to fetch() #23948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/std/http/Client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1404,26 +1404,27 @@ pub fn connectUnix(client: *Client, path: []const u8) ConnectUnixError!*Connecti
})) |node|
return node;

const conn = try client.allocator.create(ConnectionPool.Node);
const conn = try client.allocator.create(Connection);
errdefer client.allocator.destroy(conn);
conn.* = .{ .data = undefined };

const stream = try std.net.connectUnixSocket(path);
errdefer stream.close();

conn.data = .{
conn.* = .{
.stream = stream,
.tls_client = undefined,
.protocol = .plain,

.host = try client.allocator.dupe(u8, path),
.port = 0,

.pool_node = .{},
};
errdefer client.allocator.free(conn.data.host);
errdefer client.allocator.free(conn.host);

client.connection_pool.addUsed(conn);

return &conn.data;
return conn;
}

/// Connect to `tunnel_host:tunnel_port` using the specified proxy with HTTP
Expand Down Expand Up @@ -1706,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
Expand Down Expand Up @@ -1755,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();

Expand Down
Loading