| ... | ... | @@ -1,16 +1,12 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | | const http = @import("apple_pie"); |
| 4 | 3 | |
| 5 | 4 | pub const Jar = std.StringHashMap(string); |
| 6 | 5 | |
| 7 | | pub fn parse(alloc: std.mem.Allocator, headers: http.Request.Headers) !Jar { |
| 6 | pub fn parse(alloc: std.mem.Allocator, headers: std.http.Headers) !Jar { |
| 8 | 7 | 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.?, ";"); |
| 8 | const h = headers.getFirstValue("cookie") orelse return map; |
| 9 | var iter = std.mem.split(u8, h, ";"); |
| 14 | 10 | while (iter.next()) |item| { |
| 15 | 11 | const i = std.mem.indexOfScalar(u8, item, '='); |
| 16 | 12 | if (i == null) continue; |
| ... | ... | @@ -23,6 +19,6 @@ pub fn parse(alloc: std.mem.Allocator, headers: http.Request.Headers) !Jar { |
| 23 | 19 | return map; |
| 24 | 20 | } |
| 25 | 21 | |
| 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"); |
| 22 | pub fn delete(response: *std.http.Server.Response, comptime name: string) !void { |
| 23 | try response.headers.append("Set-Cookie", name ++ "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"); |
| 28 | 24 | } |