Skip to content

Commit

Permalink
HKHTTPServer: Change default behaviour of requestHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
hmelder committed Mar 4, 2024
1 parent 89774c5 commit 2d7083d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Libraries/MicroHTTPKit/Source/HKHTTPServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,19 @@ - (enum MHD_Result)_sendResponseForRequest:(HKHTTPRequest *)request
HKHandlerBlock middlewareHandler = nil;
NSData *responseData = nil;
NSDictionary<NSString *, NSString *> *responseHeaders = nil;

HKHandlerBlock handler = [[self router] handlerForRequest:request];
middlewareHandler = [[self router] middleware];
// Check if a middleware handler is registered
if (middlewareHandler) {

if (!handler) {
NSLog(@"Could not find handler!");
handler = [[self router] notFoundHandler];
response = handler(request);
} else if (middlewareHandler) {
response = middlewareHandler(request);
}

// If middleware set a response, use it. Otherwise, use the response from the router.
if (response == nil) {
HKHandlerBlock handler = [[self router] handlerForRequest:request];
// Execute the installed handler block
response = handler(request);
}
Expand Down

0 comments on commit 2d7083d

Please sign in to comment.