mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
http: add use_proxy bool in connection
This commit is contained in:
@@ -278,9 +278,11 @@ 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();
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,10 +292,12 @@ pub fn restoreOriginalProxy(self: *Client) !void {
|
|||||||
try self.ensureNoActiveConnection();
|
try self.ensureNoActiveConnection();
|
||||||
|
|
||||||
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 {
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ 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,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,9 +113,11 @@ 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));
|
||||||
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_SUPPRESS_CONNECT_HEADERS, @as(c_long, 1)));
|
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_SUPPRESS_CONNECT_HEADERS, @as(c_long, 1)));
|
||||||
|
use_proxy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tls
|
// tls
|
||||||
@@ -156,6 +159,7 @@ 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