From 7c845d097b89c9da765508c018e8998d3992de7b Mon Sep 17 00:00:00 2001 From: floscodes Date: Tue, 16 May 2023 12:11:51 +0200 Subject: [PATCH] fix docs and tests --- src/req_cookie.zig | 5 ++++- src/res_cookie.zig | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/req_cookie.zig b/src/req_cookie.zig index 17267b8..5bcc6e7 100644 --- a/src/req_cookie.zig +++ b/src/req_cookie.zig @@ -27,8 +27,11 @@ pub const Cookie = struct { test "Parse Request Cookie(s)" { const allocator = std.testing.allocator; - const cookie_string = "test_cookie=successful; second_cookie: also successful!"; + const cookie_string = "Test-Cookie=successful; Second-Cookie=also successful"; const cookie = try Cookie.parse(cookie_string, allocator); defer allocator.free(cookie); try std.testing.expect(std.mem.eql(u8, cookie[0].value, "successful")); + try std.testing.expect(std.mem.eql(u8, cookie[0].name, "Test-Cookie")); + try std.testing.expect(std.mem.eql(u8, cookie[1].name, "Second-Cookie")); + try std.testing.expect(std.mem.eql(u8, cookie[1].value, "also successful")); } diff --git a/src/res_cookie.zig b/src/res_cookie.zig index 5312a0c..768e64c 100644 --- a/src/res_cookie.zig +++ b/src/res_cookie.zig @@ -6,6 +6,7 @@ pub const Cookie = struct { value: []const u8, path: []const u8 = "/", domain: []const u8 = "", + /// Indicates the number of seconds until the cookie expires. maxAge: i64 = 0, secure: bool = true, httpOnly: bool = true, @@ -16,7 +17,7 @@ pub const Cookie = struct { defer allocator.free(domain); const secure = if (self.secure) "Secure; " else ""; const httpOnly = if (self.httpOnly) "HttpOnly; " else ""; - return try std.fmt.allocPrint(allocator, "Set-Cookie: {s}={s}; {s}Max-Age={}; {s}{s}{s}\n", .{ self.name, self.value, domain, self.maxAge, secure, httpOnly, getSameSite(&self) }); + return try std.fmt.allocPrint(allocator, "Set-Cookie: {s}={s}; Path={s}; {s}Max-Age={}; {s}{s}{s}\n", .{ self.name, self.value, self.path, domain, self.maxAge, secure, httpOnly, getSameSite(&self) }); } };