| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const http = @import("apple_pie"); |
| 4 | |
| 5 | pub const Jar = std.StringHashMap(string); |
| 6 | |
| 7 | pub fn parse(alloc: std.mem.Allocator, headers: http.Request.Headers) !Jar { |
| 8 | var map = Jar.init(alloc); |
| 9 | // extra check caused by https://github.com/Luukdegram/apple_pie/issues/70 |
| 10 | const h = headers.get("Cookie") orelse headers.get("cookie"); |
| 11 | if (h == null) return map; |
| 12 | |
| 13 | var iter = std.mem.split(u8, h.?, ";"); |
| 14 | while (iter.next()) |item| { |
| 15 | const i = std.mem.indexOfScalar(u8, item, '='); |
| 16 | if (i == null) continue; |
| 17 | const k = item[0..i.?]; |
| 18 | const v = item[i.? + 1 ..]; |
| 19 | |
| 20 | if (map.contains(k)) continue; |
| 21 | try map.put(k, v); |
| 22 | } |
| 23 | return map; |
| 24 | } |
| 25 | |
| 26 | pub fn delete(response: *http.Response, comptime name: string) !void { |
| 27 | try response.headers.put("Set-Cookie", name ++ "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"); |
| 28 | } |