@@ -93,6 +93,11 @@ notification: ?*Notification = null,
9393// restoring, this originally-configured value is what it goes to.
9494http_proxy : ? [:0 ]const u8 = null ,
9595
96+ // track if the client use a proxy for connections.
97+ // We can't use http_proxy because we want also to track proxy configured via
98+ // CDP.
99+ use_proxy : bool ,
100+
96101// The complete user-agent header line
97102user_agent : [:0 ]const u8 ,
98103
@@ -126,6 +131,7 @@ pub fn init(allocator: Allocator, ca_blob: ?c.curl_blob, opts: Http.Opts) !*Clie
126131 .handles = handles ,
127132 .allocator = allocator ,
128133 .http_proxy = opts .http_proxy ,
134+ .use_proxy = opts .http_proxy != null ,
129135 .user_agent = opts .user_agent ,
130136 .transfer_pool = transfer_pool ,
131137 };
@@ -315,6 +321,7 @@ pub fn changeProxy(self: *Client, proxy: [:0]const u8) !void {
315321 for (self .handles .handles ) | * h | {
316322 try errorCheck (c .curl_easy_setopt (h .conn .easy , c .CURLOPT_PROXY , proxy .ptr ));
317323 }
324+ self .use_proxy = true ;
318325}
319326
320327// Same restriction as changeProxy. Should be ok since this is only called on
@@ -326,6 +333,41 @@ pub fn restoreOriginalProxy(self: *Client) !void {
326333 for (self .handles .handles ) | * h | {
327334 try errorCheck (c .curl_easy_setopt (h .conn .easy , c .CURLOPT_PROXY , proxy ));
328335 }
336+ self .use_proxy = proxy != null ;
337+ }
338+
339+ // Enable TLS verification on all connections.
340+ pub fn enableTlsVerify (self : * const Client ) ! void {
341+ try self .ensureNoActiveConnection ();
342+
343+ for (self .handles .handles ) | * h | {
344+ const easy = h .conn .easy ;
345+
346+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_SSL_VERIFYHOST , @as (c_long , 2 )));
347+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_SSL_VERIFYPEER , @as (c_long , 1 )));
348+
349+ if (self .use_proxy ) {
350+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_PROXY_SSL_VERIFYHOST , @as (c_long , 2 )));
351+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_PROXY_SSL_VERIFYPEER , @as (c_long , 1 )));
352+ }
353+ }
354+ }
355+
356+ // Disable TLS verification on all connections.
357+ pub fn disableTlsVerify (self : * const Client ) ! void {
358+ try self .ensureNoActiveConnection ();
359+
360+ for (self .handles .handles ) | * h | {
361+ const easy = h .conn .easy ;
362+
363+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_SSL_VERIFYHOST , @as (c_long , 0 )));
364+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_SSL_VERIFYPEER , @as (c_long , 0 )));
365+
366+ if (self .use_proxy ) {
367+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_PROXY_SSL_VERIFYHOST , @as (c_long , 0 )));
368+ try errorCheck (c .curl_easy_setopt (easy , c .CURLOPT_PROXY_SSL_VERIFYPEER , @as (c_long , 0 )));
369+ }
370+ }
329371}
330372
331373fn makeRequest (self : * Client , handle : * Handle , transfer : * Transfer ) ! void {
0 commit comments