authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-03-30 04:17:51 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-03-30 04:17:51 -07:00
log81ac56dd5578da03c2bacefcae615e263f12cdb2
tree946f1608d7cb4ba1a97f55e7cd52afdd4f09bba4
parent144dc2a53444ce410c7519aa9bcbd51245eecc00

add get() function for single cookie value


1 files changed, 13 insertions(+), 0 deletions(-)

cookies.zig+13
......@@ -19,6 +19,19 @@ pub fn parse(alloc: std.mem.Allocator, cookie_str: ?string) !Jar {
1919 return map;
2020}
2121
22pub fn get(cookie_str: ?string, name: string) ?string {
23 const h = cookie_str orelse return null;
24 var iter = std.mem.split(u8, h, "; ");
25 while (iter.next()) |item| {
26 const i = std.mem.indexOfScalar(u8, item, '=');
27 if (i == null) continue;
28 const k = item[0..i.?];
29 const v = item[i.? + 1 ..];
30 if (std.mem.eql(u8, k, name)) return v;
31 }
32 return null;
33}
34
2235pub fn delete_string(comptime name: string) string {
2336 return name ++ "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
2437}