From 1ee0f9263cd8e2984237ff34ae4625e8aaf2680c Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Mon, 12 Jan 2026 19:18:45 -0500 Subject: Properly handle large messages add max bytes setting --- src/subcommand/serve.zig | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/subcommand') diff --git a/src/subcommand/serve.zig b/src/subcommand/serve.zig index e6bb648..9cb35bb 100644 --- a/src/subcommand/serve.zig +++ b/src/subcommand/serve.zig @@ -30,7 +30,7 @@ pub fn main(alloc: Allocator, outer_io: Io, args: []const [:0]const u8) !void { .server_id = Server.default_id, .server_name = Server.default_name, .version = "zits-master", - .max_payload = 1048576, + .max_payload = 1 * 1024 * 1024, .headers = true, }; @@ -54,6 +54,18 @@ pub fn main(alloc: Allocator, outer_io: Io, args: []const [:0]const u8) !void { return; } }, + .max_bytes => { + i += 1; + if (args.len > i) { + server_config.max_payload = std.fmt.parseUnsigned(usize, args[i], 10) catch { + std.log.err("Could not parse max bytes: {s}", .{args[i]}); + return; + }; + } else { + std.log.err("Must specify max bytes with {s}", .{args[i - 1]}); + return; + } + }, } } } @@ -90,16 +102,23 @@ pub fn main(alloc: Allocator, outer_io: Io, args: []const [:0]const u8) !void { std.log.info("Goodbye", .{}); } -const help = "serve help\n"; +const help = + \\--port/-p Specify port + \\--help/-h Get help. + \\--max-bytes Specify max message byte size + \\ +; const to_flag: std.StaticStringMap(Flag) = .initComptime(.{ .{ "-p", .port }, .{ "--port", .port }, .{ "-h", .help }, .{ "--help", .help }, + .{ "--max-bytes", .max_bytes }, }); const Flag = enum { port, help, + max_bytes, }; -- cgit