Skip to content

Commit a751606

Browse files
committed
http: move use_proxy from connection to client
1 parent e61d787 commit a751606

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/http/Client.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ notification: ?*Notification = null,
8989
// restoring, this originally-configured value is what it goes to.
9090
http_proxy: ?[:0]const u8 = null,
9191

92+
// does the client use a proxy?
93+
use_proxy: bool = false,
94+
9295
const TransferQueue = std.DoublyLinkedList(*Transfer);
9396

9497
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
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 {
278283
pub 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 {
291295
pub 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

303306
fn 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| {

src/http/Http.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ pub const Connection = struct {
9494
opts: Connection.Opts,
9595

9696
const Opts = struct {
97-
use_proxy: bool,
9897
proxy_bearer_token: ?[:0]const u8,
9998
};
10099

@@ -113,10 +112,8 @@ pub const Connection = struct {
113112
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_REDIR_PROTOCOLS_STR, "HTTP,HTTPS")); // remove FTP and FTPS from the default
114113

115114
// proxy
116-
var use_proxy = false;
117115
if (opts.http_proxy) |proxy| {
118116
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_PROXY, proxy.ptr));
119-
use_proxy = true;
120117
}
121118

122119
// tls
@@ -158,7 +155,6 @@ pub const Connection = struct {
158155
return .{
159156
.easy = easy,
160157
.opts = .{
161-
.use_proxy = use_proxy,
162158
.proxy_bearer_token = opts.proxy_bearer_token,
163159
},
164160
};

0 commit comments

Comments
 (0)