http: handle auth challenge for non-proxy auth

This commit is contained in:
Pierre Tachoire
2026-03-09 19:23:36 +01:00
parent 9172e16e80
commit 37c34351ee
3 changed files with 11 additions and 1 deletions

View File

@@ -377,6 +377,10 @@ pub const Connection = struct {
try libcurl.curl_easy_setopt(self.easy, .proxy_user_pwd, creds.ptr); 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( pub fn setCallbacks(
self: *const Connection, self: *const Connection,
comptime header_cb: libcurl.CurlHeaderFunction, comptime header_cb: libcurl.CurlHeaderFunction,

View File

@@ -718,7 +718,11 @@ fn makeRequest(self: *Client, conn: *Net.Connection, transfer: *Transfer) anyerr
// add credentials // add credentials
if (req.credentials) |creds| { 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);
}
} }
} }

View File

@@ -148,6 +148,7 @@ pub const CurlOption = enum(c.CURLoption) {
cookie = c.CURLOPT_COOKIE, cookie = c.CURLOPT_COOKIE,
private = c.CURLOPT_PRIVATE, private = c.CURLOPT_PRIVATE,
proxy_user_pwd = c.CURLOPT_PROXYUSERPWD, proxy_user_pwd = c.CURLOPT_PROXYUSERPWD,
user_pwd = c.CURLOPT_USERPWD,
header_data = c.CURLOPT_HEADERDATA, header_data = c.CURLOPT_HEADERDATA,
header_function = c.CURLOPT_HEADERFUNCTION, header_function = c.CURLOPT_HEADERFUNCTION,
write_data = c.CURLOPT_WRITEDATA, write_data = c.CURLOPT_WRITEDATA,
@@ -512,6 +513,7 @@ pub fn curl_easy_setopt(easy: *Curl, comptime option: CurlOption, value: anytype
.accept_encoding, .accept_encoding,
.custom_request, .custom_request,
.cookie, .cookie,
.user_pwd,
.proxy_user_pwd, .proxy_user_pwd,
.copy_post_fields, .copy_post_fields,
=> blk: { => blk: {