From 38748c2023fa16d1632dcf0ad6eb9430074abbed Mon Sep 17 00:00:00 2001 From: robin Date: Mon, 17 Aug 2026 11:54:28 +0200 Subject: [PATCH] fix: use `conn.path` instead of `request.head.target` --- src/handler.zig | 4 ++-- src/root.zig | 18 ++++++++---------- src/router.zig | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/handler.zig b/src/handler.zig index 05b5b0c..26dbfd9 100644 --- a/src/handler.zig +++ b/src/handler.zig @@ -67,7 +67,7 @@ pub fn dispatch(conn: Connection) !void { var l = fern.debug().ctx("handler.dispatch") .msg("request") .fmt("method", "{}", .{request.head.method}) - .str("path", request.head.target); + .str("path", conn.path); var it = request.iterateHeaders(); while (it.next()) |header| l = l.str(header.name, header.value); l.log(); @@ -77,7 +77,7 @@ pub fn dispatch(conn: Connection) !void { const elapsed = std.Io.Timestamp.durationTo(timer, std.Io.Timestamp.now(maivi.io, .cpu_thread)).toMilliseconds(); fern.debug().ctx("handler.dispatch") .msg("response") - .str("path", request.head.target) + .str("path", conn.path) .int("elapsed", elapsed).log(); } diff --git a/src/root.zig b/src/root.zig index 9d72f30..88feee6 100644 --- a/src/root.zig +++ b/src/root.zig @@ -140,7 +140,7 @@ pub fn handle(conn: handler.Connection) !void { return try handletxt(conn); }; - const path = router.paths.get(request.head.target) orelse return handle_fs(conn); + const path = router.paths.get(conn.path) orelse return handle_fs(conn); blk: { for (path.config.allowed_methods) |method| @@ -162,27 +162,25 @@ pub fn handle(conn: handler.Connection) !void { pub const MESSAGE_PATH = "/index.txt"; fn handle_fs(conn: handler.Connection) !void { - const request = conn.request; - const build_dir = try std.Io.Dir.openDirAbsolute(io, config.buildroot, .{}); defer build_dir.close(io); try_build: { - return helpers.sendfile(conn, build_dir, request.head.target) catch |err| switch (err) { + return helpers.sendfile(conn, build_dir, conn.path) catch |err| switch (err) { error.FileNotFound => break :try_build, else => return err, }; } try_build_index_html: { - if (std.mem.eql(u8, request.head.target, "/")) { + if (std.mem.eql(u8, conn.path, "/")) { return helpers.sendfile(conn, build_dir, "/index.html") catch |err| switch (err) { error.FileNotFound => break :try_build_index_html, else => return err, }; } - const path = try std.mem.join(allocator, "/", &.{ request.head.target, "index.html" }); + const path = try std.mem.join(allocator, "/", &.{ conn.path, "index.html" }); defer allocator.free(path); return helpers.sendfile(conn, build_dir, path) catch |err| switch (err) { error.FileNotFound => break :try_build_index_html, @@ -194,7 +192,7 @@ fn handle_fs(conn: handler.Connection) !void { defer static_dir.close(io); try_static: { - return helpers.sendfile(conn, static_dir, request.head.target) catch |err| switch (err) { + return helpers.sendfile(conn, static_dir, conn.path) catch |err| switch (err) { error.FileNotFound => break :try_static, else => return err, }; @@ -206,7 +204,7 @@ fn handle_fs(conn: handler.Connection) !void { pub fn handletxt(conn: handler.Connection) !void { const request = conn.request; - if (request.head.target.len == 1) { + if (conn.path.len == 1) { fern.debug().ctx("maivi.handletxt") .msg("redirecting to message path") .str("path", MESSAGE_PATH) @@ -216,7 +214,7 @@ pub fn handletxt(conn: handler.Connection) !void { }; } - const mdpath = try std.mem.concat(allocator, u8, &.{ request.head.target[0 .. request.head.target.len - 1], ".md" }); + const mdpath = try std.mem.concat(allocator, u8, &.{ conn.path[0 .. conn.path.len - 1], ".md" }); defer allocator.free(mdpath); fern.debug().ctx("maivi.handletxt") .str("path", mdpath) @@ -260,7 +258,7 @@ pub fn add_redirects() !void { fn handleredirect(conn: handler.Connection) !void { const request = conn.request; - const redirect_url = redirects.get(request.head.target) orelse + const redirect_url = redirects.get(conn.path) orelse return error.FileNotFound; _ = try helpers.redirect(conn.arena, request, redirect_url, null); } diff --git a/src/router.zig b/src/router.zig index a25afb1..ab6a788 100644 --- a/src/router.zig +++ b/src/router.zig @@ -108,7 +108,7 @@ fn lua_add(l: *Lua) !i32 { pub fn handle_lua(conn: handler.Connection) !void { const request = conn.request; - const content_type = helpers.content_type_for_file(request.head.target) orelse .html; + const content_type = helpers.content_type_for_file(conn.path) orelse .html; var wbuf: [0x4000]u8 = undefined; var b = try maivi.helpers.respond(request, &wbuf, .{ @@ -116,7 +116,7 @@ pub fn handle_lua(conn: handler.Connection) !void { .content_type = content_type, }); - const data = maivi.router.luapaths.get(request.head.target) orelse return error.FileNotFound; + const data = maivi.router.luapaths.get(conn.path) orelse return error.FileNotFound; try get(maivi.lua.lua, &b.writer, data); } -- 2.51.2