fix docs and tests
This commit is contained in:
parent
048b6290b7
commit
7c845d097b
2 changed files with 6 additions and 2 deletions
|
@ -27,8 +27,11 @@ pub const Cookie = struct {
|
||||||
|
|
||||||
test "Parse Request Cookie(s)" {
|
test "Parse Request Cookie(s)" {
|
||||||
const allocator = std.testing.allocator;
|
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);
|
const cookie = try Cookie.parse(cookie_string, allocator);
|
||||||
defer allocator.free(cookie);
|
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].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,
|
value: []const u8,
|
||||||
path: []const u8 = "/",
|
path: []const u8 = "/",
|
||||||
domain: []const u8 = "",
|
domain: []const u8 = "",
|
||||||
|
/// Indicates the number of seconds until the cookie expires.
|
||||||
maxAge: i64 = 0,
|
maxAge: i64 = 0,
|
||||||
secure: bool = true,
|
secure: bool = true,
|
||||||
httpOnly: bool = true,
|
httpOnly: bool = true,
|
||||||
|
@ -16,7 +17,7 @@ pub const Cookie = struct {
|
||||||
defer allocator.free(domain);
|
defer allocator.free(domain);
|
||||||
const secure = if (self.secure) "Secure; " else "";
|
const secure = if (self.secure) "Secure; " else "";
|
||||||
const httpOnly = if (self.httpOnly) "HttpOnly; " 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…
Add table
Reference in a new issue