@@ -89,6 +89,9 @@ notification: ?*Notification = null,
8989// restoring, this originally-configured value is what it goes to.
9090http_proxy : ? [:0 ]const u8 = null ,
9191
92+ // does the client use a proxy?
93+ use_proxy : bool = false ,
94+
9295const TransferQueue = std .DoublyLinkedList (* Transfer );
9396
9497pub 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
120123 .blocking = blocking ,
121124 .allocator = allocator ,
122125 .http_proxy = opts .http_proxy ,
126+ .use_proxy = opts .http_proxy != null ,
123127 .transfer_pool = transfer_pool ,
124128 .queue_node_pool = queue_node_pool ,
125129 };
@@ -242,6 +246,7 @@ fn makeTransfer(self: *Client, req: Request) !*Transfer {
242246 .req = req ,
243247 .ctx = req .ctx ,
244248 .client = self ,
249+ ._use_proxy = self .use_proxy ,
245250 };
246251 return transfer ;
247252}
@@ -278,11 +283,10 @@ fn requestFailed(self: *Client, transfer: *Transfer, err: anyerror) void {
278283pub fn changeProxy (self : * Client , proxy : [:0 ]const u8 ) ! void {
279284 try self .ensureNoActiveConnection ();
280285
286+ self .use_proxy = true ;
281287 for (self .handles .handles ) | * h | {
282- h .conn .opts .use_proxy = true ;
283288 try errorCheck (c .curl_easy_setopt (h .conn .easy , c .CURLOPT_PROXY , proxy .ptr ));
284289 }
285- self .blocking .conn .opts .use_proxy = true ;
286290 try errorCheck (c .curl_easy_setopt (self .blocking .conn .easy , c .CURLOPT_PROXY , proxy .ptr ));
287291}
288292
@@ -291,13 +295,12 @@ pub fn changeProxy(self: *Client, proxy: [:0]const u8) !void {
291295pub fn restoreOriginalProxy (self : * Client ) ! void {
292296 try self .ensureNoActiveConnection ();
293297
298+ self .use_proxy = self .http_proxy != null ;
294299 const proxy = if (self .http_proxy ) | p | p .ptr else null ;
295300 for (self .handles .handles ) | * h | {
296- h .conn .opts .use_proxy = proxy != null ;
297301 try errorCheck (c .curl_easy_setopt (h .conn .easy , c .CURLOPT_PROXY , proxy ));
298302 }
299303 try errorCheck (c .curl_easy_setopt (self .blocking .conn .easy , c .CURLOPT_PROXY , proxy ));
300- self .blocking .conn .opts .use_proxy = proxy != null ;
301304}
302305
303306fn makeRequest (self : * Client , handle : * Handle , transfer : * Transfer ) ! void {
@@ -309,9 +312,6 @@ fn makeRequest(self: *Client, handle: *Handle, transfer: *Transfer) !void {
309312 transfer ._handle = handle ;
310313 errdefer transfer .deinit ();
311314
312- // Store the proxy's information in transfer to ease headers parsing.
313- transfer ._use_proxy = conn .opts .use_proxy ;
314-
315315 try conn .setURL (req .url );
316316 try conn .setMethod (req .method );
317317 if (req .body ) | b | {
0 commit comments