mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 15:14:08 +00:00
finalize: allocator always 1st-ish arg
This commit is contained in:
parent
35a8d8f39b
commit
eca4d511f0
6 changed files with 17 additions and 17 deletions
|
@ -56,7 +56,7 @@ const Handler = struct {
|
|||
else => {
|
||||
// might be a string param, we don't care
|
||||
// let's just get it as string
|
||||
if (r.getParamStr(kv.key.str, Handler.alloc, false)) |maybe_str| {
|
||||
if (r.getParamStr(Handler.alloc, kv.key.str, false)) |maybe_str| {
|
||||
const value: []const u8 = if (maybe_str) |s| s.str else "(no value)";
|
||||
std.log.debug(" {s} = {s}", .{ kv.key.str, value });
|
||||
} else |err| {
|
||||
|
@ -68,7 +68,7 @@ const Handler = struct {
|
|||
}
|
||||
|
||||
// check if we received a terminate=true parameter
|
||||
if (r.getParamStr("terminate", Handler.alloc, false)) |maybe_str| {
|
||||
if (r.getParamStr(Handler.alloc, "terminate", false)) |maybe_str| {
|
||||
if (maybe_str) |*s| {
|
||||
defer s.deinit();
|
||||
std.log.info("?terminate={s}\n", .{s.str});
|
||||
|
|
|
@ -61,7 +61,7 @@ pub fn main() !void {
|
|||
|
||||
// let's get cookie "ZIG_ZAP" by name
|
||||
std.debug.print("\n", .{});
|
||||
if (r.getCookieStr("ZIG_ZAP", alloc, false)) |maybe_str| {
|
||||
if (r.getCookieStr(alloc, "ZIG_ZAP", false)) |maybe_str| {
|
||||
if (maybe_str) |*s| {
|
||||
defer s.deinit();
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ pub fn main() !void {
|
|||
|
||||
// let's get param "one" by name
|
||||
std.debug.print("\n", .{});
|
||||
if (r.getParamStr("one", alloc, false)) |maybe_str| {
|
||||
if (r.getParamStr(alloc, "one", false)) |maybe_str| {
|
||||
if (maybe_str) |*s| {
|
||||
defer s.deinit();
|
||||
|
||||
|
@ -82,7 +82,7 @@ pub fn main() !void {
|
|||
}
|
||||
|
||||
// check if we received a terminate=true parameter
|
||||
if (r.getParamStr("terminate", alloc, false)) |maybe_str| {
|
||||
if (r.getParamStr(alloc, "terminate", false)) |maybe_str| {
|
||||
if (maybe_str) |*s| {
|
||||
defer s.deinit();
|
||||
if (std.mem.eql(u8, s.str, "true")) {
|
||||
|
|
|
@ -449,7 +449,7 @@ pub fn UserPassSessionAuth(comptime Lookup: type, comptime lockedPwLookups: bool
|
|||
r.parseCookies(false);
|
||||
|
||||
// check for session cookie
|
||||
if (r.getCookieStr(self.settings.cookieName, self.allocator, false)) |maybe_cookie| {
|
||||
if (r.getCookieStr(self.allocator, self.settings.cookieName, false)) |maybe_cookie| {
|
||||
if (maybe_cookie) |cookie| {
|
||||
defer cookie.deinit();
|
||||
self.tokenLookupLock.lock();
|
||||
|
@ -485,7 +485,7 @@ pub fn UserPassSessionAuth(comptime Lookup: type, comptime lockedPwLookups: bool
|
|||
r.parseCookies(false);
|
||||
|
||||
// check for session cookie
|
||||
if (r.getCookieStr(self.settings.cookieName, self.allocator, false)) |maybe_cookie| {
|
||||
if (r.getCookieStr(self.allocator, self.settings.cookieName, false)) |maybe_cookie| {
|
||||
if (maybe_cookie) |cookie| {
|
||||
defer cookie.deinit();
|
||||
// locked or unlocked token lookup
|
||||
|
@ -507,10 +507,10 @@ pub fn UserPassSessionAuth(comptime Lookup: type, comptime lockedPwLookups: bool
|
|||
}
|
||||
|
||||
// get params of username and password
|
||||
if (r.getParamStr(self.settings.usernameParam, self.allocator, false)) |maybe_username| {
|
||||
if (r.getParamStr(self.allocator, self.settings.usernameParam, false)) |maybe_username| {
|
||||
if (maybe_username) |*username| {
|
||||
defer username.deinit();
|
||||
if (r.getParamStr(self.settings.passwordParam, self.allocator, false)) |maybe_pw| {
|
||||
if (r.getParamStr(self.allocator, self.settings.passwordParam, false)) |maybe_pw| {
|
||||
if (maybe_pw) |*pw| {
|
||||
defer pw.deinit();
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ test "http parameters" {
|
|||
// true -> make copies of temp strings
|
||||
params = r.parametersToOwnedList(alloc, true) catch unreachable;
|
||||
|
||||
var maybe_str = r.getParamStr("one", alloc, true) catch unreachable;
|
||||
var maybe_str = r.getParamStr(alloc, "one", true) catch unreachable;
|
||||
if (maybe_str) |*s| {
|
||||
paramOneStr = s.*;
|
||||
}
|
||||
|
|
14
src/zap.zig
14
src/zap.zig
|
@ -370,7 +370,7 @@ pub const Request = struct {
|
|||
if (value == fio.FIOBJ_INVALID) {
|
||||
return null;
|
||||
}
|
||||
return try util.fio2strAllocOrNot(value, a, always_alloc);
|
||||
return try util.fio2strAllocOrNot(a, value, always_alloc);
|
||||
}
|
||||
|
||||
/// Returns the number of cookies after parsing.
|
||||
|
@ -454,11 +454,11 @@ pub const Request = struct {
|
|||
// this is thread-safe, guaranteed by fio
|
||||
const fiobj_key: fio.FIOBJ = fio.fiobj_hash_key_in_loop();
|
||||
ctx.params.append(.{
|
||||
.key = util.fio2strAllocOrNot(fiobj_key, ctx.allocator, ctx.always_alloc) catch |err| {
|
||||
.key = util.fio2strAllocOrNot(ctx.allocator, fiobj_key, ctx.always_alloc) catch |err| {
|
||||
ctx.last_error = err;
|
||||
return -1;
|
||||
},
|
||||
.value = util.fio2strAllocOrNot(fiobj_value, ctx.allocator, ctx.always_alloc) catch |err| {
|
||||
.value = util.fio2strAllocOrNot(ctx.allocator, fiobj_value, ctx.always_alloc) catch |err| {
|
||||
ctx.last_error = err;
|
||||
return -1;
|
||||
},
|
||||
|
@ -507,11 +507,11 @@ pub const Request = struct {
|
|||
// this is thread-safe, guaranteed by fio
|
||||
const fiobj_key: fio.FIOBJ = fio.fiobj_hash_key_in_loop();
|
||||
ctx.params.append(.{
|
||||
.key = util.fio2strAllocOrNot(fiobj_key, ctx.allocator, ctx.dupe_strings) catch |err| {
|
||||
.key = util.fio2strAllocOrNot(ctx.allocator, fiobj_key, ctx.dupe_strings) catch |err| {
|
||||
ctx.last_error = err;
|
||||
return -1;
|
||||
},
|
||||
.value = Fiobj2HttpParam(fiobj_value, ctx.allocator, ctx.dupe_strings) catch |err| {
|
||||
.value = Fiobj2HttpParam(ctx.allocator, fiobj_value, ctx.dupe_strings) catch |err| {
|
||||
ctx.last_error = err;
|
||||
return -1;
|
||||
},
|
||||
|
@ -546,7 +546,7 @@ pub const Request = struct {
|
|||
if (value == fio.FIOBJ_INVALID) {
|
||||
return null;
|
||||
}
|
||||
return try util.fio2strAllocOrNot(value, a, always_alloc);
|
||||
return try util.fio2strAllocOrNot(a, value, always_alloc);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -764,7 +764,7 @@ pub fn Fiobj2HttpParam(a: std.mem.Allocator, o: fio.FIOBJ, dupe_string: bool) !?
|
|||
fio.FIOBJ_T_FALSE => .{ .Bool = false },
|
||||
fio.FIOBJ_T_NUMBER => .{ .Int = fio.fiobj_obj2num(o) },
|
||||
fio.FIOBJ_T_FLOAT => .{ .Float = fio.fiobj_obj2float(o) },
|
||||
fio.FIOBJ_T_STRING => .{ .String = try util.fio2strAllocOrNot(o, a, dupe_string) },
|
||||
fio.FIOBJ_T_STRING => .{ .String = try util.fio2strAllocOrNot(a, o, dupe_string) },
|
||||
fio.FIOBJ_T_ARRAY => {
|
||||
return .{ .Unsupported = null };
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue