Fix print call

This commit is contained in:
jaina heartles 2022-11-17 19:48:25 -08:00
parent fcbb1bb623
commit 58a0dd900f
1 changed files with 5 additions and 4 deletions

View File

@ -133,20 +133,21 @@ pub const Fields = struct {
}; };
pub fn setCookie(self: *Fields, name: []const u8, value: []const u8, opt: CookieOptions) !void { pub fn setCookie(self: *Fields, name: []const u8, value: []const u8, opt: CookieOptions) !void {
const cookie = try std.fmt.printAlloc( const cookie = try std.fmt.allocPrint(
self.allocator, self.allocator,
"{s}={s}{s}{s}{s}", "{s}={s}{s}{s}{s}{s}",
.{ .{
name, name,
value, value,
if (opt.Secure) "; Secure" else "", if (opt.Secure) "; Secure" else "",
if (opt.HttpOnly) "; HttpOnly" else "", if (opt.HttpOnly) "; HttpOnly" else "",
if (opt.SameSite) |same_site| "; SameSite=" ++ @tagName(same_site) else "", if (opt.SameSite) |_| "; SameSite=" else "",
if (opt.SameSite) |same_site| @tagName(same_site) else "",
}, },
); );
defer self.allocator.free(cookie); defer self.allocator.free(cookie);
// TODO: reduce unnecessary allocations // TODO: reduce unnecessary allocations
self.append("Set-Cookie", cookie); try self.append("Set-Cookie", cookie);
} }
}; };