diff --git a/cookies.zig b/cookies.zig index f12f3f056caf756a41eee71928a175786bc4480e..9794439f7bc815e1226879f1e37a27c9e23cc383 100644 --- a/cookies.zig +++ b/cookies.zig @@ -19,6 +19,19 @@ pub fn parse(alloc: std.mem.Allocator, cookie_str: ?string) !Jar { return map; } +pub fn get(cookie_str: ?string, name: string) ?string { + const h = cookie_str orelse return null; + var iter = std.mem.split(u8, h, "; "); + while (iter.next()) |item| { + const i = std.mem.indexOfScalar(u8, item, '='); + if (i == null) continue; + const k = item[0..i.?]; + const v = item[i.? + 1 ..]; + if (std.mem.eql(u8, k, name)) return v; + } + return null; +} + pub fn delete_string(comptime name: string) string { return name ++ "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"; }