http: add use_proxy bool in connection

This commit is contained in:
Pierre Tachoire
2025-08-21 12:03:46 +02:00
parent bc7e1e07f4
commit 159bd06a56
2 changed files with 10 additions and 2 deletions

View File

@@ -278,9 +278,11 @@ fn requestFailed(self: *Client, transfer: *Transfer, err: anyerror) void {
pub fn changeProxy(self: *Client, proxy: [:0]const u8) !void {
try self.ensureNoActiveConnection();
for (self.handles.handles) |h| {
for (self.handles.handles) |*h| {
h.conn.opts.use_proxy = true;
try errorCheck(c.curl_easy_setopt(h.conn.easy, c.CURLOPT_PROXY, proxy.ptr));
}
self.blocking.conn.opts.use_proxy = true;
try errorCheck(c.curl_easy_setopt(self.blocking.conn.easy, c.CURLOPT_PROXY, proxy.ptr));
}
@@ -290,10 +292,12 @@ pub fn restoreOriginalProxy(self: *Client) !void {
try self.ensureNoActiveConnection();
const proxy = if (self.http_proxy) |p| p.ptr else null;
for (self.handles.handles) |h| {
for (self.handles.handles) |*h| {
h.conn.opts.use_proxy = proxy != null;
try errorCheck(c.curl_easy_setopt(h.conn.easy, c.CURLOPT_PROXY, proxy));
}
try errorCheck(c.curl_easy_setopt(self.blocking.conn.easy, c.CURLOPT_PROXY, proxy));
self.blocking.conn.opts.use_proxy = proxy != null;
}
fn makeRequest(self: *Client, handle: *Handle, transfer: *Transfer) !void {

View File

@@ -94,6 +94,7 @@ pub const Connection = struct {
opts: Connection.Opts,
const Opts = struct {
use_proxy: bool,
proxy_bearer_token: ?[:0]const u8,
};
@@ -112,9 +113,11 @@ pub const Connection = struct {
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_REDIR_PROTOCOLS_STR, "HTTP,HTTPS")); // remove FTP and FTPS from the default
// proxy
var use_proxy = false;
if (opts.http_proxy) |proxy| {
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_PROXY, proxy.ptr));
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_SUPPRESS_CONNECT_HEADERS, @as(c_long, 1)));
use_proxy = true;
}
// tls
@@ -156,6 +159,7 @@ pub const Connection = struct {
return .{
.easy = easy,
.opts = .{
.use_proxy = use_proxy,
.proxy_bearer_token = opts.proxy_bearer_token,
},
};