Skip to content

Lightpanda: the headless browser designed for AI and automation

0 for robot entry limit means no limit

Muki Kiboigod16091a40359
diff --git a/src/Config.zig b/src/Config.zig
index 23582f8bd..c15d51314 100644
--- a/src/Config.zig
+++ b/src/Config.zig
@@ -233,28 +233,6 @@ fn caPathValidator(
}
}
-fn robotStoreEntryLimitValidator(_: Allocator, args: *std.process.Args.Iterator, target: *?u32) !void {
- const str = args.next() orelse return error.MissingArgument;
- const value = std.fmt.parseInt(u32, str, 10) catch {
- log.fatal(.app, "invalid option value", .{
- .arg = "--robot-store-entry-limit",
- .value = str,
- .hint = "must be a positive integer",
- });
- return error.InvalidArgument;
- };
-
- if (value == 0) {
- log.fatal(.app, "invalid option value", .{
- .arg = "--robot-store-entry-limit",
- .value = str,
- .hint = "must be at least 1",
- });
- return error.InvalidArgument;
- }
- target.* = value;
-}
-
pub const HttpVersion = enum {
auto,
@"1.1",
@@ -275,7 +253,7 @@ pub const ExperimentalFeatures = packed struct(u2) {
/// Common CLI args.
const CommonOptions = .{
.{ .name = "obey_robots", .type = bool },
- .{ .name = "robot_store_entry_limit", .type = ?u32, .default = 1000, .validator = robotStoreEntryLimitValidator },
+ .{ .name = "robot_store_entry_limit", .type = ?u32, .default = 1000 },
.{ .name = "proxy_bearer_token", .type = ?[:0]const u8 },
.{ .name = "http_proxy", .type = ?[:0]const u8 },
.{ .name = "http_max_concurrent", .type = ?u8 },
diff --git a/src/help.zon b/src/help.zon
index 576741170..a8a251c4a 100644
--- a/src/help.zon
+++ b/src/help.zon
@@ -490,7 +490,7 @@
\\ Fetches and obeys robots.txt of the target page.
\\ Defaults to false.
\\ --robot-store-entry-limit <INT>
- \\ Maximum number of entries kept in the RobotStore.
+ \\ Maximum number of entries kept in the RobotStore. 0 means no limit.
\\ Defaults to 1000.
\\ --proxy-bearer-token <TOKEN>
\\ Token sent for bearer authentication with the proxy:
diff --git a/src/network/ClockCache.zig b/src/network/ClockCache.zig
index 84c41f310..4eaa21372 100644
--- a/src/network/ClockCache.zig
+++ b/src/network/ClockCache.zig
@@ -38,13 +38,13 @@ pub fn ClockCache(comptime V: type) type {
};
allocator: Allocator,
- capacity: usize,
+ capacity: ?usize,
map: Map = .empty,
hand: usize = 0,
pub fn init(allocator: Allocator, capacity: usize) Self {
- std.debug.assert(capacity > 0);
- return .{ .allocator = allocator, .capacity = capacity };
+ const true_capacity = if (capacity == 0) null else capacity;
+ return .{ .allocator = allocator, .capacity = true_capacity };
}
pub fn deinit(self: *Self) void {
@@ -72,8 +72,13 @@ pub fn ClockCache(comptime V: type) type {
gop.key_ptr.* = try self.allocator.dupe(u8, key);
gop.value_ptr.* = .{ .value = value, .referenced = true };
- if (self.map.count() <= self.capacity) return .{ .inserted = null };
- return .{ .inserted = self.evictOne() };
+ if (self.capacity) |cap| {
+ if (self.map.count() > cap) {
+ return .{ .inserted = self.evictOne() };
+ }
+ }
+
+ return .{ .inserted = null };
}
fn evictOne(self: *Self) V {