diff --git a/src/Net.zig b/src/Net.zig index bd723be6..c45707e4 100644 --- a/src/Net.zig +++ b/src/Net.zig @@ -377,6 +377,10 @@ pub const Connection = struct { try libcurl.curl_easy_setopt(self.easy, .proxy_user_pwd, creds.ptr); } + pub fn setCredentials(self: *const Connection, creds: [:0]const u8) !void { + try libcurl.curl_easy_setopt(self.easy, .user_pwd, creds.ptr); + } + pub fn setCallbacks( self: *const Connection, comptime header_cb: libcurl.CurlHeaderFunction, diff --git a/src/http/Client.zig b/src/http/Client.zig index 326635f4..5701de27 100644 --- a/src/http/Client.zig +++ b/src/http/Client.zig @@ -718,7 +718,11 @@ fn makeRequest(self: *Client, conn: *Net.Connection, transfer: *Transfer) anyerr // add credentials if (req.credentials) |creds| { - try conn.setProxyCredentials(creds); + if (transfer._auth_challenge != null and transfer._auth_challenge.?.source == .proxy) { + try conn.setProxyCredentials(creds); + } else { + try conn.setCredentials(creds); + } } } diff --git a/src/sys/libcurl.zig b/src/sys/libcurl.zig index ca718ebb..759cba25 100644 --- a/src/sys/libcurl.zig +++ b/src/sys/libcurl.zig @@ -148,6 +148,7 @@ pub const CurlOption = enum(c.CURLoption) { cookie = c.CURLOPT_COOKIE, private = c.CURLOPT_PRIVATE, proxy_user_pwd = c.CURLOPT_PROXYUSERPWD, + user_pwd = c.CURLOPT_USERPWD, header_data = c.CURLOPT_HEADERDATA, header_function = c.CURLOPT_HEADERFUNCTION, write_data = c.CURLOPT_WRITEDATA, @@ -512,6 +513,7 @@ pub fn curl_easy_setopt(easy: *Curl, comptime option: CurlOption, value: anytype .accept_encoding, .custom_request, .cookie, + .user_pwd, .proxy_user_pwd, .copy_post_fields, => blk: {