From a7516061d0c23c7b644504046a83d5e571333cc1 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 22 Aug 2025 11:58:48 +0200 Subject: [PATCH] http: move use_proxy from connection to client --- src/http/Client.zig | 14 +++++++------- src/http/Http.zig | 4 ---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/http/Client.zig b/src/http/Client.zig index 9b1456ba..a74c85d8 100644 --- a/src/http/Client.zig +++ b/src/http/Client.zig @@ -89,6 +89,9 @@ notification: ?*Notification = null, // restoring, this originally-configured value is what it goes to. http_proxy: ?[:0]const u8 = null, +// does the client use a proxy? +use_proxy: bool = false, + const TransferQueue = std.DoublyLinkedList(*Transfer); pub fn init(allocator: Allocator, ca_blob: ?c.curl_blob, opts: Http.Opts) !*Client { @@ -120,6 +123,7 @@ pub fn init(allocator: Allocator, ca_blob: ?c.curl_blob, opts: Http.Opts) !*Clie .blocking = blocking, .allocator = allocator, .http_proxy = opts.http_proxy, + .use_proxy = opts.http_proxy != null, .transfer_pool = transfer_pool, .queue_node_pool = queue_node_pool, }; @@ -242,6 +246,7 @@ fn makeTransfer(self: *Client, req: Request) !*Transfer { .req = req, .ctx = req.ctx, .client = self, + ._use_proxy = self.use_proxy, }; return transfer; } @@ -278,11 +283,10 @@ fn requestFailed(self: *Client, transfer: *Transfer, err: anyerror) void { pub fn changeProxy(self: *Client, proxy: [:0]const u8) !void { try self.ensureNoActiveConnection(); + self.use_proxy = true; 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)); } @@ -291,13 +295,12 @@ pub fn changeProxy(self: *Client, proxy: [:0]const u8) !void { pub fn restoreOriginalProxy(self: *Client) !void { try self.ensureNoActiveConnection(); + self.use_proxy = self.http_proxy != null; const proxy = if (self.http_proxy) |p| p.ptr else null; 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 { @@ -309,9 +312,6 @@ fn makeRequest(self: *Client, handle: *Handle, transfer: *Transfer) !void { transfer._handle = handle; errdefer transfer.deinit(); - // Store the proxy's information in transfer to ease headers parsing. - transfer._use_proxy = conn.opts.use_proxy; - try conn.setURL(req.url); try conn.setMethod(req.method); if (req.body) |b| { diff --git a/src/http/Http.zig b/src/http/Http.zig index 7cf6a011..e661d766 100644 --- a/src/http/Http.zig +++ b/src/http/Http.zig @@ -94,7 +94,6 @@ pub const Connection = struct { opts: Connection.Opts, const Opts = struct { - use_proxy: bool, proxy_bearer_token: ?[:0]const u8, }; @@ -113,10 +112,8 @@ 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)); - use_proxy = true; } // tls @@ -158,7 +155,6 @@ pub const Connection = struct { return .{ .easy = easy, .opts = .{ - .use_proxy = use_proxy, .proxy_bearer_token = opts.proxy_bearer_token, }, };