@@ -256,7 +256,7 @@ pub fn Create(
256
256
/// Authenticates GET requests using the Authenticator.
257
257
pub fn get (self : * AuthenticatingEndpoint , arena : Allocator , context : * Context , request : Request ) anyerror ! void {
258
258
try switch (self .authenticator .authenticateRequest (& request )) {
259
- .AuthFailed = > return self .ep .* . unauthorized ( arena , context , request ),
259
+ .AuthFailed = > callHandlerIfExist ( "unauthorized" , self .ep , arena , context , request ),
260
260
.AuthOK = > callHandlerIfExist ("get" , self .ep , arena , context , request ),
261
261
.Handled = > {},
262
262
};
@@ -265,7 +265,7 @@ pub fn Create(
265
265
/// Authenticates POST requests using the Authenticator.
266
266
pub fn post (self : * AuthenticatingEndpoint , arena : Allocator , context : * Context , request : Request ) anyerror ! void {
267
267
try switch (self .authenticator .authenticateRequest (& request )) {
268
- .AuthFailed = > return self .ep .* . unauthorized ( arena , context , request ),
268
+ .AuthFailed = > callHandlerIfExist ( "unauthorized" , self .ep , arena , context , request ),
269
269
.AuthOK = > callHandlerIfExist ("post" , self .ep , arena , context , request ),
270
270
.Handled = > {},
271
271
};
@@ -274,7 +274,7 @@ pub fn Create(
274
274
/// Authenticates PUT requests using the Authenticator.
275
275
pub fn put (self : * AuthenticatingEndpoint , arena : Allocator , context : * Context , request : zap.Request ) anyerror ! void {
276
276
try switch (self .authenticator .authenticateRequest (& request )) {
277
- .AuthFailed = > return self .ep .* . unauthorized ( arena , context , request ),
277
+ .AuthFailed = > callHandlerIfExist ( "unauthorized" , self .ep , arena , context , request ),
278
278
.AuthOK = > callHandlerIfExist ("put" , self .ep , arena , context , request ),
279
279
.Handled = > {},
280
280
};
@@ -283,7 +283,7 @@ pub fn Create(
283
283
/// Authenticates DELETE requests using the Authenticator.
284
284
pub fn delete (self : * AuthenticatingEndpoint , arena : Allocator , context : * Context , request : zap.Request ) anyerror ! void {
285
285
try switch (self .authenticator .authenticateRequest (& request )) {
286
- .AuthFailed = > return self .ep .* . unauthorized ( arena , context , request ),
286
+ .AuthFailed = > callHandlerIfExist ( "unauthorized" , self .ep , arena , context , request ),
287
287
.AuthOK = > callHandlerIfExist ("delete" , self .ep , arena , context , request ),
288
288
.Handled = > {},
289
289
};
@@ -292,7 +292,7 @@ pub fn Create(
292
292
/// Authenticates PATCH requests using the Authenticator.
293
293
pub fn patch (self : * AuthenticatingEndpoint , arena : Allocator , context : * Context , request : zap.Request ) anyerror ! void {
294
294
try switch (self .authenticator .authenticateRequest (& request )) {
295
- .AuthFailed = > return self .ep .* . unauthorized ( arena , context , request ),
295
+ .AuthFailed = > callHandlerIfExist ( "unauthorized" , self .ep , arena , context , request ),
296
296
.AuthOK = > callHandlerIfExist ("patch" , self .ep , arena , context , request ),
297
297
.Handled = > {},
298
298
};
@@ -301,7 +301,7 @@ pub fn Create(
301
301
/// Authenticates OPTIONS requests using the Authenticator.
302
302
pub fn options (self : * AuthenticatingEndpoint , arena : Allocator , context : * Context , request : zap.Request ) anyerror ! void {
303
303
try switch (self .authenticator .authenticateRequest (& request )) {
304
- .AuthFailed = > return self .ep .* . unauthorized ( arena , context , request ),
304
+ .AuthFailed = > callHandlerIfExist ( "unauthorized" , self .ep , arena , context , request ),
305
305
.AuthOK = > callHandlerIfExist ("options" , self .ep , arena , context , request ),
306
306
.Handled = > {},
307
307
};
@@ -310,7 +310,7 @@ pub fn Create(
310
310
/// Authenticates HEAD requests using the Authenticator.
311
311
pub fn head (self : * AuthenticatingEndpoint , arena : Allocator , context : * Context , request : zap.Request ) anyerror ! void {
312
312
try switch (self .authenticator .authenticateRequest (& request )) {
313
- .AuthFailed = > return self .ep .* . unauthorized ( arena , context , request ),
313
+ .AuthFailed = > callHandlerIfExist ( "unauthorized" , self .ep , arena , context , request ),
314
314
.AuthOK = > callHandlerIfExist ("head" , self .ep , arena , context , request ),
315
315
.Handled = > {},
316
316
};
@@ -393,6 +393,12 @@ pub fn Create(
393
393
if (@hasDecl (EndPoint , fn_name )) {
394
394
return @field (EndPoint , fn_name )(e , arena , ctx , r );
395
395
}
396
+ zap .log .debug (
397
+ "Unhandled `{s}` {s} request ({s} not implemented in {s})" ,
398
+ .{ r .method orelse "<unknown>" , r .path orelse "" , fn_name , @typeName (Endpoint ) },
399
+ );
400
+ r .setStatus (.method_not_allowed );
401
+ try r .sendBody ("405 - method not allowed\r \n " );
396
402
return ;
397
403
}
398
404
0 commit comments