fix docs and tests

main
floscodes 1 year ago
parent 048b6290b7
commit 7c845d097b

@ -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"));
}

@ -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) });
}
};

Loading…
Cancel
Save