mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-09-15 07:19:20 -04:00
chore: Simplify Network and HttpClient init
Remove app field from Network
This commit is contained in:
4 files changed
+20
-15
No files matched your search
+1
-1
@@ -67,7 +67,7 @@ pub fn init(allocator: Allocator, config: *const Config) !*App {
|
||||
try app.watchdog.start();
|
||||
errdefer app.watchdog.deinit();
|
||||
|
||||
app.network = try Network.init(allocator, app, config);
|
||||
app.network = try Network.init(app);
|
||||
errdefer app.network.deinit();
|
||||
|
||||
app.app_dir_path = getAndMakeAppDir(allocator);
|
||||
|
||||
@@ -128,7 +128,7 @@ pub fn init(self: *Browser, app: *App, opts: InitOpts, cdp: ?*CDP) !void {
|
||||
.watchdog_entry = undefined,
|
||||
};
|
||||
self.env.protectHeapLimit();
|
||||
try self.http_client.init(allocator, &app.network, cdp);
|
||||
try self.http_client.init(app, cdp);
|
||||
|
||||
self.watchdog_entry = .{
|
||||
.env = &self.env,
|
||||
|
||||
@@ -190,14 +190,17 @@ obey_robots: bool,
|
||||
robots: RobotsGate,
|
||||
url_blocklist: ?UrlBlocklist,
|
||||
|
||||
pub fn init(self: *Client, allocator: Allocator, network: *Network, cdp: ?*CDP) !void {
|
||||
var handles = try http.Handles.init(network.config);
|
||||
pub fn init(self: *Client, app: *lp.App, cdp: ?*CDP) !void {
|
||||
const config = app.config;
|
||||
const allocator = app.allocator;
|
||||
|
||||
var handles = try http.Handles.init(config);
|
||||
errdefer handles.deinit();
|
||||
|
||||
const http_proxy = network.config.httpProxy();
|
||||
const http_proxy = config.httpProxy();
|
||||
|
||||
var url_blocklist: ?UrlBlocklist = null;
|
||||
if (network.config.blockedUrlPatterns()) |initial_patterns| {
|
||||
if (config.blockedUrlPatterns()) |initial_patterns| {
|
||||
var patterns: std.ArrayList([]const u8) = .empty;
|
||||
defer patterns.deinit(allocator);
|
||||
|
||||
@@ -211,10 +214,12 @@ pub fn init(self: *Client, allocator: Allocator, network: *Network, cdp: ?*CDP)
|
||||
}
|
||||
errdefer if (url_blocklist) |*blocklist| blocklist.deinit();
|
||||
|
||||
const network = &app.network;
|
||||
|
||||
self.* = Client{
|
||||
.handles = handles,
|
||||
.network = network,
|
||||
.allocator = allocator,
|
||||
.allocator = app.allocator,
|
||||
.cdp = cdp,
|
||||
.inbox = .{},
|
||||
.cache = &network.cache,
|
||||
@@ -224,14 +229,14 @@ pub fn init(self: *Client, allocator: Allocator, network: *Network, cdp: ?*CDP)
|
||||
.tls_verify = network.config.tlsVerifyHost(),
|
||||
.max_response_size = network.config.httpMaxResponseSize() orelse 1 * 1024 * 1024 * 1024, // 1 GiB
|
||||
|
||||
.serve_mode = network.config.mode == .serve,
|
||||
.obey_robots = network.config.obeyRobots(),
|
||||
.serve_mode = config.mode == .serve,
|
||||
.obey_robots = config.obeyRobots(),
|
||||
.robots = .{
|
||||
.network = network,
|
||||
.single_flight = .init(allocator),
|
||||
},
|
||||
.url_blocklist = url_blocklist,
|
||||
.arena_pool = &network.app.arena_pool,
|
||||
.arena_pool = &app.arena_pool,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -81,10 +81,8 @@ pub const CdpLink = struct {
|
||||
// Number of fixed pollfds entries (wakeup pipe + listener).
|
||||
const PSEUDO_POLLFDS = 2;
|
||||
|
||||
allocator: Allocator,
|
||||
|
||||
app: *App,
|
||||
cache: Cache,
|
||||
allocator: Allocator,
|
||||
config: *const Config,
|
||||
robot_store: RobotStore,
|
||||
web_bot_auth: ?WebBotAuth,
|
||||
@@ -140,12 +138,15 @@ cdp_start: usize,
|
||||
/// Optional IP filter for blocking requests to private/internal networks (--block-private-networks).
|
||||
ip_filter: ?*IpFilter = null,
|
||||
|
||||
pub fn init(allocator: Allocator, app: *App, config: *const Config) !Network {
|
||||
pub fn init(app: *App) !Network {
|
||||
libcurl.curl_global_init(.{ .ssl = true }, null) catch |err| {
|
||||
lp.assert(false, "curl global init", .{ .err = err });
|
||||
};
|
||||
errdefer libcurl.curl_global_cleanup();
|
||||
|
||||
const config = app.config;
|
||||
const allocator = app.allocator;
|
||||
|
||||
const pipe = try sys_net.pipe2(.{ .NONBLOCK = true, .CLOEXEC = true });
|
||||
|
||||
// pollfds layout:
|
||||
@@ -207,7 +208,6 @@ pub fn init(allocator: Allocator, app: *App, config: *const Config) !Network {
|
||||
errdefer cache.deinit();
|
||||
|
||||
return .{
|
||||
.app = app,
|
||||
.config = config,
|
||||
.allocator = allocator,
|
||||
.certificates = certificates,
|
||||
|
||||
Reference in new issue
Block a user