Reduce url buffer

This commit is contained in:
sjorsdonkers
2025-05-09 10:33:44 +02:00
committed by Sjors
parent fb95df66c9
commit 2a95b7a37c
2 changed files with 18 additions and 2 deletions

View File

@@ -193,7 +193,7 @@ pub const Session = struct {
// can't use the page arena, because we're about to reset it
// and don't want to use the session's arena, because that'll start to
// look like a leak if we navigate from page to page a lot.
var buf: [4096]u8 = undefined;
var buf: [2048]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buf);
const url = try self.page.?.url.resolve(fba.allocator(), url_string);
@@ -732,7 +732,7 @@ pub const Page = struct {
_ = repeat_delay;
const self: *DelayedNavigation = @fieldParentPtr("navigate_node", node);
self.session.pageNavigate(self.href) catch |err| {
log.err("Delayed navigation error {}", .{err});
log.err("Delayed navigation error {}", .{err}); // TODO: should we trigger a specific event here?
};
}
};

View File

@@ -82,3 +82,19 @@ pub const URL = struct {
return WebApiURL.init(allocator, self.uri);
}
};
test "Url resolve size" {
const base = "https://www.lightpande.io";
const url = try URL.parse(base, null);
var url_string: [511]u8 = undefined; // Currently this is the largest url we support, it is however recommmended to at least support 2000 characters
@memset(&url_string, 'a');
var buf: [2048]u8 = undefined; // This is approximately the required size to support the current largest supported URL
var fba = std.heap.FixedBufferAllocator.init(&buf);
const out_url = try url.resolve(fba.allocator(), &url_string);
try std.testing.expectEqualStrings(out_url.raw[0..25], base);
try std.testing.expectEqual(out_url.raw[25], '/');
try std.testing.expectEqualStrings(out_url.raw[26..], &url_string);
}