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