diff --git a/src/http/headers.zig b/src/http/headers.zig index d1fa7f5..4f45029 100644 --- a/src/http/headers.zig +++ b/src/http/headers.zig @@ -3,24 +3,24 @@ const std = @import("std"); pub const Fields = struct { const HashContext = struct { const hash_seed = 1; - pub fn eql(_: @This(), lhs: []const u8, rhs: []const u8) bool { + pub fn eql(_: @This(), lhs: []const u8, rhs: []const u8, _: usize) bool { return std.ascii.eqlIgnoreCase(lhs, rhs); } - pub fn hash(_: @This(), s: []const u8) u64 { + pub fn hash(_: @This(), s: []const u8) u32 { var h = std.hash.Wyhash.init(hash_seed); for (s) |ch| { const c = [1]u8{std.ascii.toLower(ch)}; h.update(&c); } - return h.final(); + return @truncate(u32, h.final()); } }; - const HashMap = std.HashMapUnmanaged( + const HashMap = std.ArrayHashMapUnmanaged( []const u8, []const u8, HashContext, - std.hash_map.default_max_load_percentage, + true, ); unmanaged: HashMap, diff --git a/src/http/server/response.zig b/src/http/server/response.zig index b50b9f1..057c51a 100644 --- a/src/http/server/response.zig +++ b/src/http/server/response.zig @@ -38,7 +38,11 @@ fn writeStatusLine(writer: anytype, status: Status) !void { fn writeFields(writer: anytype, headers: *const Fields) !void { var iter = headers.iterator(); + std.log.debug("{any}", .{headers}); + std.log.debug("{any}", .{iter}); while (iter.next()) |header| { + std.log.debug("{any}", .{headers}); + std.log.debug("{any}", .{iter}); for (header.value_ptr.*) |ch| { if (ch == '\r' or ch == '\n') @panic("newlines not yet supported in headers"); } @@ -95,7 +99,6 @@ pub fn ResponseStream(comptime BaseWriter: type) type { return; } - std.debug.print("{}\n", .{cursor}); self.writeToBuffer(bytes[cursor .. cursor + remaining_in_chunk]); cursor += remaining_in_chunk; try self.flushChunk(); diff --git a/src/main/controllers/auth.zig b/src/main/controllers/auth.zig index 95be918..1b6e652 100644 --- a/src/main/controllers/auth.zig +++ b/src/main/controllers/auth.zig @@ -1,4 +1,5 @@ const api = @import("api"); +const std = @import("std"); pub const login = struct { pub const method = .POST; @@ -12,6 +13,8 @@ pub const login = struct { pub fn handler(req: anytype, res: anytype, srv: anytype) !void { const token = try srv.login(req.body.username, req.body.password); + std.log.debug("{any}", .{res.headers}); + try res.json(.ok, token); } };