mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
http: move use_proxy from connection to client
This commit is contained in:
@@ -89,6 +89,9 @@ notification: ?*Notification = null,
|
|||||||
// restoring, this originally-configured value is what it goes to.
|
// restoring, this originally-configured value is what it goes to.
|
||||||
http_proxy: ?[:0]const u8 = null,
|
http_proxy: ?[:0]const u8 = null,
|
||||||
|
|
||||||
|
// does the client use a proxy?
|
||||||
|
use_proxy: bool = false,
|
||||||
|
|
||||||
const TransferQueue = std.DoublyLinkedList(*Transfer);
|
const TransferQueue = std.DoublyLinkedList(*Transfer);
|
||||||
|
|
||||||
pub fn init(allocator: Allocator, ca_blob: ?c.curl_blob, opts: Http.Opts) !*Client {
|
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,
|
.blocking = blocking,
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.http_proxy = opts.http_proxy,
|
.http_proxy = opts.http_proxy,
|
||||||
|
.use_proxy = opts.http_proxy != null,
|
||||||
.transfer_pool = transfer_pool,
|
.transfer_pool = transfer_pool,
|
||||||
.queue_node_pool = queue_node_pool,
|
.queue_node_pool = queue_node_pool,
|
||||||
};
|
};
|
||||||
@@ -242,6 +246,7 @@ fn makeTransfer(self: *Client, req: Request) !*Transfer {
|
|||||||
.req = req,
|
.req = req,
|
||||||
.ctx = req.ctx,
|
.ctx = req.ctx,
|
||||||
.client = self,
|
.client = self,
|
||||||
|
._use_proxy = self.use_proxy,
|
||||||
};
|
};
|
||||||
return transfer;
|
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 {
|
pub fn changeProxy(self: *Client, proxy: [:0]const u8) !void {
|
||||||
try self.ensureNoActiveConnection();
|
try self.ensureNoActiveConnection();
|
||||||
|
|
||||||
|
self.use_proxy = true;
|
||||||
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));
|
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));
|
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 {
|
pub fn restoreOriginalProxy(self: *Client) !void {
|
||||||
try self.ensureNoActiveConnection();
|
try self.ensureNoActiveConnection();
|
||||||
|
|
||||||
|
self.use_proxy = self.http_proxy != null;
|
||||||
const proxy = if (self.http_proxy) |p| p.ptr else null;
|
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(h.conn.easy, c.CURLOPT_PROXY, proxy));
|
||||||
}
|
}
|
||||||
try errorCheck(c.curl_easy_setopt(self.blocking.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 {
|
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;
|
transfer._handle = handle;
|
||||||
errdefer transfer.deinit();
|
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.setURL(req.url);
|
||||||
try conn.setMethod(req.method);
|
try conn.setMethod(req.method);
|
||||||
if (req.body) |b| {
|
if (req.body) |b| {
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ pub const Connection = struct {
|
|||||||
opts: Connection.Opts,
|
opts: Connection.Opts,
|
||||||
|
|
||||||
const Opts = struct {
|
const Opts = struct {
|
||||||
use_proxy: bool,
|
|
||||||
proxy_bearer_token: ?[:0]const u8,
|
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
|
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_REDIR_PROTOCOLS_STR, "HTTP,HTTPS")); // remove FTP and FTPS from the default
|
||||||
|
|
||||||
// proxy
|
// proxy
|
||||||
var use_proxy = false;
|
|
||||||
if (opts.http_proxy) |proxy| {
|
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_PROXY, proxy.ptr));
|
||||||
use_proxy = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tls
|
// tls
|
||||||
@@ -158,7 +155,6 @@ pub const Connection = struct {
|
|||||||
return .{
|
return .{
|
||||||
.easy = easy,
|
.easy = easy,
|
||||||
.opts = .{
|
.opts = .{
|
||||||
.use_proxy = use_proxy,
|
|
||||||
.proxy_bearer_token = opts.proxy_bearer_token,
|
.proxy_bearer_token = opts.proxy_bearer_token,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user