From 8156e741ef7c8a59317ba801aa0c8940e9fcbd00 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Sun, 6 Aug 2023 19:55:20 +0100 Subject: Percent-decode query parameters like they shoud be according to the spec https://www.w3.org/TR/html401/interact/forms.html --- src/main.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 1f4d8f9..70869b2 100644 --- a/src/main.zig +++ b/src/main.zig @@ -10,7 +10,8 @@ const Context = struct { }; const Handler = struct { pub fn handle(_: Handler, res: *std.http.Server.Response, _: Context) !void { - const p = try zws.Path.parse(res.request.target); + var p = try zws.Path.parse(res.allocator, res.request.target); + defer p.deinit(); const path = try std.fs.path.join(res.allocator, &[_][]const u8{ ".", p.path }); defer res.allocator.free(path); if (std.fs.cwd().openFile(path, .{})) |file| { @@ -43,7 +44,7 @@ const Handler = struct { while (true) { const read = try file.read(&buf); if (read == 0) break; - _ = try res.write(buf[0..read]); + _ = try res.writeAll(buf[0..read]); } } -- cgit v1.2.3-ZIG