1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 23:24:09 +00:00

add handling for unset request types in endpoint

This commit is contained in:
OsakiTsukiko 2024-10-26 18:48:42 +03:00
parent 675c65b509
commit 15ba95ee07

View file

@ -30,6 +30,8 @@ pub const Settings = struct {
options: ?RequestFn = null, options: ?RequestFn = null,
/// Only applicable to Authenticating Endpoint: handler for unauthorized requests /// Only applicable to Authenticating Endpoint: handler for unauthorized requests
unauthorized: ?RequestFn = null, unauthorized: ?RequestFn = null,
// callback to any unset request type
unset: ?RequestFn = null,
}; };
settings: Settings, settings: Settings,
@ -41,13 +43,14 @@ pub fn init(s: Settings) Endpoint {
return .{ return .{
.settings = .{ .settings = .{
.path = s.path, .path = s.path,
.get = s.get orelse &nop, .get = s.get orelse s.unset orelse &nop,
.post = s.post orelse &nop, .post = s.post orelse s.unset orelse &nop,
.put = s.put orelse &nop, .put = s.put orelse s.unset orelse &nop,
.delete = s.delete orelse &nop, .delete = s.delete orelse s.unset orelse &nop,
.patch = s.patch orelse &nop, .patch = s.patch orelse s.unset orelse &nop,
.options = s.options orelse &nop, .options = s.options orelse s.unset orelse &nop,
.unauthorized = s.unauthorized orelse &nop, .unauthorized = s.unauthorized orelse s.unset orelse &nop,
.unset = s.unset orelse &nop,
}, },
}; };
} }
@ -98,6 +101,7 @@ pub fn Authenticating(comptime Authenticator: type) type {
.patch = if (e.settings.patch != null) patch else null, .patch = if (e.settings.patch != null) patch else null,
.options = if (e.settings.options != null) options else null, .options = if (e.settings.options != null) options else null,
.unauthorized = e.settings.unauthorized, .unauthorized = e.settings.unauthorized,
.unset = e.settings.unset,
}), }),
}; };
} }