From d1da4ec3bc01644d4ff5ca88883b7fcab7cb9e9a Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Mon, 29 May 2023 18:19:25 +0200 Subject: [PATCH] fix: setCookie in ReleaseXXX mode, spelling COOKIE --- examples/cookies/cookies.zig | 6 +++++- src/http_auth.zig | 4 ++-- src/zap.zig | 10 +++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/examples/cookies/cookies.zig b/examples/cookies/cookies.zig index 5eb6f82..0e07db7 100644 --- a/examples/cookies/cookies.zig +++ b/examples/cookies/cookies.zig @@ -73,6 +73,7 @@ pub fn main() !void { // since we provided "false" for duplicating strings in the call // to getCookieStr(), there won't be an allocation error else |err| { + std.log.err("ERROR!\n", .{}); std.log.err("cannot check for `ZIG_ZAP` cookie: {any}\n", .{err}); } @@ -83,7 +84,10 @@ pub fn main() !void { // .max_age_s = 60, // // check out other params: domain, path, secure, http_only - }) catch unreachable; + }) catch |err| { + std.log.err("ERROR!\n", .{}); + std.log.err("cannot set cookie: {any}\n", .{err}); + }; r.sendBody("Hello") catch unreachable; } diff --git a/src/http_auth.zig b/src/http_auth.zig index 71ee4c6..c883ef7 100644 --- a/src/http_auth.zig +++ b/src/http_auth.zig @@ -464,10 +464,10 @@ pub fn UserPassSessionAuth(comptime Lookup: type, comptime lockedPwLookups: bool defer self.tokenLookupLock.unlock(); if (self.sessionTokens.contains(cookie.str)) { // cookie is a valid session! - zap.debug("Auth: COKIE IS OK!!!!: {s}\n", .{cookie.str}); + zap.debug("Auth: COOKIE IS OK!!!!: {s}\n", .{cookie.str}); return .AuthOK; } else { - zap.debug("Auth: COKIE IS BAD!!!!: {s}\n", .{cookie.str}); + zap.debug("Auth: COOKIE IS BAD!!!!: {s}\n", .{cookie.str}); // this is not necessarily a bad thing. it could be a // stale cookie from a previous session. So let's check // if username and password are being sent and correct. diff --git a/src/zap.zig b/src/zap.zig index 445fb84..a3d54e2 100644 --- a/src/zap.zig +++ b/src/zap.zig @@ -310,7 +310,15 @@ pub const SimpleRequest = struct { .secure = if (args.secure) 1 else 0, .http_only = if (args.http_only) 1 else 0, }; - if (fio.http_set_cookie(self.h, c) == -1) { + + // TODO WAT? + // if we: + // if(fio.http_set_cookie(...) == -1) + // instead of capturing it in `ret` first and then checking it, + // all ReleaseXXX builds return an error! + const ret = fio.http_set_cookie(self.h, c); + if (ret == -1) { + std.log.err("fio.http_set_cookie returned: {}\n", .{ret}); return error.SetCookie; } }