Skip to content

Commit

Permalink
fix: setCookie in ReleaseXXX mode, spelling COOKIE
Browse files Browse the repository at this point in the history
  • Loading branch information
renerocksai committed May 29, 2023
1 parent 6d99e7e commit d1da4ec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion examples/cookies/cookies.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}

Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/http_auth.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion src/zap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit d1da4ec

Please sign in to comment.