authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-31 01:18:55 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-31 01:18:55 -07:00
logdcc0b3a5aa0667f37f7e1f6bf44a1c083663ebfa
tree854e2cd1184b2e89b10a4552609f01d195bcdb83
parent88ba75f97402d8939505cb3ae21fff8e2379072b

use std.http instead of apple_pie


2 files changed, 5 insertions(+), 10 deletions(-)

cookies.zig+5-9
...@@ -1,16 +1,12 @@...@@ -1,16 +1,12 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const http = @import("apple_pie");
43
5pub const Jar = std.StringHashMap(string);4pub const Jar = std.StringHashMap(string);
65
7pub fn parse(alloc: std.mem.Allocator, headers: http.Request.Headers) !Jar {6pub 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/708 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}
2521
26pub fn delete(response: *http.Response, comptime name: string) !void {22pub 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}
zigmod.yml-1
...@@ -3,4 +3,3 @@ name: cookies...@@ -3,4 +3,3 @@ name: cookies
3main: cookies.zig3main: cookies.zig
4license: MIT4license: MIT
5dependencies:5dependencies:
6 - src: git https://github.com/Luukdegram/apple_pie