From 6ee43f7c9f303ca9d2b6213f0ede1da91b564697 Mon Sep 17 00:00:00 2001 From: Dustin Date: Tue, 11 Jun 2024 16:08:00 -0600 Subject: [PATCH 1/2] Fix nested paths in public folder on windows --- src/jetzig/http/Server.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/jetzig/http/Server.zig b/src/jetzig/http/Server.zig index aa4387a..2fc17e1 100644 --- a/src/jetzig/http/Server.zig +++ b/src/jetzig/http/Server.zig @@ -598,11 +598,14 @@ fn matchPublicContent(self: *Server, request: *jetzig.http.Request) !?StaticReso var walker = try iterable_dir.walk(request.allocator); defer walker.deinit(); - + var path_buffer: [256]u8 = undefined; while (try walker.next()) |file| { if (file.kind != .file) continue; - - if (std.mem.eql(u8, file.path, request.path.file_path[1..])) { + const file_path = if (builtin.os.tag == .windows) blk: { + _ = std.mem.replace(u8, file.path, std.fs.path.sep_str_windows, std.fs.path.sep_str_posix, &path_buffer); + break :blk path_buffer[0..file.path.len]; + } else file.path; + if (std.mem.eql(u8, file_path, request.path.file_path[1..])) { const content = try iterable_dir.readFileAlloc( request.allocator, file.path, From 33e76d74ad6a42026e5bb1932239b8e7b08d3507 Mon Sep 17 00:00:00 2001 From: Dustin Date: Tue, 11 Jun 2024 16:27:24 -0600 Subject: [PATCH 2/2] Fix nested paths in public folder on windows --- src/jetzig/http/Server.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jetzig/http/Server.zig b/src/jetzig/http/Server.zig index 2fc17e1..e2d6976 100644 --- a/src/jetzig/http/Server.zig +++ b/src/jetzig/http/Server.zig @@ -608,10 +608,10 @@ fn matchPublicContent(self: *Server, request: *jetzig.http.Request) !?StaticReso if (std.mem.eql(u8, file_path, request.path.file_path[1..])) { const content = try iterable_dir.readFileAlloc( request.allocator, - file.path, + file_path, jetzig.config.get(usize, "max_bytes_public_content"), ); - const extension = std.fs.path.extension(file.path); + const extension = std.fs.path.extension(file_path); const mime_type = if (self.mime_map.get(extension)) |mime| mime else "application/octet-stream"; return .{ .content = content,