http: add creds into request

This commit is contained in:
Pierre Tachoire
2025-08-26 10:48:16 +02:00
parent 6962cfb91a
commit bb381e522c

View File

@@ -325,6 +325,11 @@ fn makeRequest(self: *Client, handle: *Handle, transfer: *Transfer) !void {
} }
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_PRIVATE, transfer)); try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_PRIVATE, transfer));
// add credentials
if (req.credentials) |creds| {
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_PROXYUSERPWD, creds.ptr));
}
} }
// Once soon as this is called, our "perform" loop is responsible for // Once soon as this is called, our "perform" loop is responsible for
@@ -542,6 +547,7 @@ pub const Request = struct {
body: ?[]const u8 = null, body: ?[]const u8 = null,
cookie_jar: *CookieJar, cookie_jar: *CookieJar,
resource_type: ResourceType, resource_type: ResourceType,
credentials: ?[:0]const u8 = null,
// arbitrary data that can be associated with this request // arbitrary data that can be associated with this request
ctx: *anyopaque = undefined, ctx: *anyopaque = undefined,
@@ -633,6 +639,10 @@ pub const Transfer = struct {
self.req.url = url; self.req.url = url;
} }
pub fn updateCredentials(self: *Transfer, userpwd: [:0]const u8) void {
self.req.credentials = userpwd;
}
pub fn replaceRequestHeaders(self: *Transfer, allocator: Allocator, headers: []const Http.Header) !void { pub fn replaceRequestHeaders(self: *Transfer, allocator: Allocator, headers: []const Http.Header) !void {
self.req.headers.deinit(); self.req.headers.deinit();