Skip to content

Commit

Permalink
MicroHTTPKit: Method for automatic CORS handler configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
hmelder committed Mar 4, 2024
1 parent 75a2f6f commit db9b2f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions Libraries/MicroHTTPKit/MicroHTTPKit/HKRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern NSString *const HKResponseStatusKey;
- (instancetype)initWithRoutes:(NSArray<HKRoute *> *)routes
notFoundHandler:(HKHandlerBlock)notFoundHandler NS_DESIGNATED_INITIALIZER;

- (void)registerRoute:(HKRoute *)route withCORSHandler:(HKHandlerBlock)handler;
- (void)registerRoute:(HKRoute *)route;

- (NSArray<HKRoute *> *)routes;
Expand Down
12 changes: 12 additions & 0 deletions Libraries/MicroHTTPKit/Source/HKRouter.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
*/

#import <MicroHTTPKit/HKHTTPConstants.h>
#import <MicroHTTPKit/HKRouter.h>

@interface HKRouter ()
Expand Down Expand Up @@ -71,6 +72,17 @@ - (nullable HKHandlerBlock)handlerForRequest:(HKHTTPRequest *)request {
return nil;
}

- (void)registerRoute:(HKRoute *)route withCORSHandler:(HKHandlerBlock)handler {
NSString *path;
HKRoute *corsRoute;

path = [route path];
corsRoute = [HKRoute routeWithPath:path method:HKHTTPMethodPOST handler:handler];

[_routes addObject:route];
[_routes addObject:corsRoute];
}

- (void)registerRoute:(HKRoute *)route {
[_routes addObject:route];
}
Expand Down

0 comments on commit db9b2f1

Please sign in to comment.