@@ -876,13 +876,14 @@ - (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)aClass
876876}
877877
878878- (void )addDefaultHandlerForMethod : (NSString *)method requestClass : (Class )aClass asyncProcessBlock : (GCDWebServerAsyncProcessBlock)block {
879- [self addHandlerWithMatchBlock: ^GCDWebServerRequest*(NSString * requestMethod, NSURL * requestURL, NSDictionary <NSString *, NSString *>* requestHeaders, NSString * urlPath, NSDictionary <NSString *, NSString *>* urlQuery) {
880- if (![requestMethod isEqualToString: method]) {
881- return nil ;
882- }
883- return [(GCDWebServerRequest*)[aClass alloc ] initWithMethod: requestMethod url: requestURL headers: requestHeaders path: urlPath query: urlQuery];
884- }
885- asyncProcessBlock: block];
879+ [self
880+ addHandlerWithMatchBlock: ^GCDWebServerRequest*(NSString * requestMethod, NSURL * requestURL, NSDictionary <NSString *, NSString *>* requestHeaders, NSString * urlPath, NSDictionary <NSString *, NSString *>* urlQuery) {
881+ if (![requestMethod isEqualToString: method]) {
882+ return nil ;
883+ }
884+ return [(GCDWebServerRequest*)[aClass alloc ] initWithMethod: requestMethod url: requestURL headers: requestHeaders path: urlPath query: urlQuery];
885+ }
886+ asyncProcessBlock: block];
886887}
887888
888889- (void )addHandlerForMethod : (NSString *)method path : (NSString *)path requestClass : (Class )aClass processBlock : (GCDWebServerProcessBlock)block {
@@ -896,16 +897,17 @@ - (void)addHandlerForMethod:(NSString*)method path:(NSString*)path requestClass:
896897
897898- (void )addHandlerForMethod : (NSString *)method path : (NSString *)path requestClass : (Class )aClass asyncProcessBlock : (GCDWebServerAsyncProcessBlock)block {
898899 if ([path hasPrefix: @" /" ] && [aClass isSubclassOfClass: [GCDWebServerRequest class ]]) {
899- [self addHandlerWithMatchBlock: ^GCDWebServerRequest*(NSString * requestMethod, NSURL * requestURL, NSDictionary <NSString *, NSString *>* requestHeaders, NSString * urlPath, NSDictionary <NSString *, NSString *>* urlQuery) {
900- if (![requestMethod isEqualToString: method]) {
901- return nil ;
902- }
903- if ([urlPath caseInsensitiveCompare: path] != NSOrderedSame) {
904- return nil ;
905- }
906- return [(GCDWebServerRequest*)[aClass alloc ] initWithMethod: requestMethod url: requestURL headers: requestHeaders path: urlPath query: urlQuery];
907- }
908- asyncProcessBlock: block];
900+ [self
901+ addHandlerWithMatchBlock: ^GCDWebServerRequest*(NSString * requestMethod, NSURL * requestURL, NSDictionary <NSString *, NSString *>* requestHeaders, NSString * urlPath, NSDictionary <NSString *, NSString *>* urlQuery) {
902+ if (![requestMethod isEqualToString: method]) {
903+ return nil ;
904+ }
905+ if ([urlPath caseInsensitiveCompare: path] != NSOrderedSame) {
906+ return nil ;
907+ }
908+ return [(GCDWebServerRequest*)[aClass alloc ] initWithMethod: requestMethod url: requestURL headers: requestHeaders path: urlPath query: urlQuery];
909+ }
910+ asyncProcessBlock: block];
909911 } else {
910912 GWS_DNOT_REACHED ();
911913 }
@@ -923,34 +925,35 @@ - (void)addHandlerForMethod:(NSString*)method pathRegex:(NSString*)regex request
923925- (void )addHandlerForMethod : (NSString *)method pathRegex : (NSString *)regex requestClass : (Class )aClass asyncProcessBlock : (GCDWebServerAsyncProcessBlock)block {
924926 NSRegularExpression * expression = [NSRegularExpression regularExpressionWithPattern: regex options: NSRegularExpressionCaseInsensitive error: NULL ];
925927 if (expression && [aClass isSubclassOfClass: [GCDWebServerRequest class ]]) {
926- [self addHandlerWithMatchBlock: ^GCDWebServerRequest*(NSString * requestMethod, NSURL * requestURL, NSDictionary <NSString *, NSString *>* requestHeaders, NSString * urlPath, NSDictionary <NSString *, NSString *>* urlQuery) {
927- if (![requestMethod isEqualToString: method]) {
928- return nil ;
929- }
928+ [self
929+ addHandlerWithMatchBlock: ^GCDWebServerRequest*(NSString * requestMethod, NSURL * requestURL, NSDictionary <NSString *, NSString *>* requestHeaders, NSString * urlPath, NSDictionary <NSString *, NSString *>* urlQuery) {
930+ if (![requestMethod isEqualToString: method]) {
931+ return nil ;
932+ }
930933
931- NSArray * matches = [expression matchesInString: urlPath options: 0 range: NSMakeRange (0 , urlPath.length)];
932- if (matches.count == 0 ) {
933- return nil ;
934- }
934+ NSArray * matches = [expression matchesInString: urlPath options: 0 range: NSMakeRange (0 , urlPath.length)];
935+ if (matches.count == 0 ) {
936+ return nil ;
937+ }
935938
936- NSMutableArray * captures = [NSMutableArray array ];
937- for (NSTextCheckingResult * result in matches) {
938- // Start at 1; index 0 is the whole string
939- for (NSUInteger i = 1 ; i < result.numberOfRanges ; i++) {
940- NSRange range = [result rangeAtIndex: i];
941- // range is {NSNotFound, 0} "if one of the capture groups did not participate in this particular match"
942- // see discussion in -[NSRegularExpression firstMatchInString:options:range:]
943- if (range.location != NSNotFound ) {
944- [captures addObject: [urlPath substringWithRange: range]];
939+ NSMutableArray * captures = [NSMutableArray array ];
940+ for (NSTextCheckingResult * result in matches) {
941+ // Start at 1; index 0 is the whole string
942+ for (NSUInteger i = 1 ; i < result.numberOfRanges ; i++) {
943+ NSRange range = [result rangeAtIndex: i];
944+ // range is {NSNotFound, 0} "if one of the capture groups did not participate in this particular match"
945+ // see discussion in -[NSRegularExpression firstMatchInString:options:range:]
946+ if (range.location != NSNotFound ) {
947+ [captures addObject: [urlPath substringWithRange: range]];
948+ }
949+ }
945950 }
946- }
947- }
948951
949- GCDWebServerRequest* request = [(GCDWebServerRequest*)[aClass alloc ] initWithMethod: requestMethod url: requestURL headers: requestHeaders path: urlPath query: urlQuery];
950- [request setAttribute: captures forKey: GCDWebServerRequestAttribute_RegexCaptures];
951- return request;
952- }
953- asyncProcessBlock: block];
952+ GCDWebServerRequest* request = [(GCDWebServerRequest*)[aClass alloc ] initWithMethod: requestMethod url: requestURL headers: requestHeaders path: urlPath query: urlQuery];
953+ [request setAttribute: captures forKey: GCDWebServerRequestAttribute_RegexCaptures];
954+ return request;
955+ }
956+ asyncProcessBlock: block];
954957 } else {
955958 GWS_DNOT_REACHED ();
956959 }
@@ -1021,15 +1024,16 @@ - (GCDWebServerResponse*)_responseWithContentsOfDirectory:(NSString*)path {
10211024- (void )addGETHandlerForBasePath : (NSString *)basePath directoryPath : (NSString *)directoryPath indexFilename : (NSString *)indexFilename cacheAge : (NSUInteger )cacheAge allowRangeRequests : (BOOL )allowRangeRequests {
10221025 if ([basePath hasPrefix: @" /" ] && [basePath hasSuffix: @" /" ]) {
10231026 GCDWebServer* __unsafe_unretained server = self;
1024- [self addHandlerWithMatchBlock: ^GCDWebServerRequest*(NSString * requestMethod, NSURL * requestURL, NSDictionary <NSString *, NSString *>* requestHeaders, NSString * urlPath, NSDictionary <NSString *, NSString *>* urlQuery) {
1025- if (![requestMethod isEqualToString: @" GET" ]) {
1026- return nil ;
1027- }
1028- if (![urlPath hasPrefix: basePath]) {
1029- return nil ;
1030- }
1031- return [[GCDWebServerRequest alloc ] initWithMethod: requestMethod url: requestURL headers: requestHeaders path: urlPath query: urlQuery];
1032- }
1027+ [self
1028+ addHandlerWithMatchBlock: ^GCDWebServerRequest*(NSString * requestMethod, NSURL * requestURL, NSDictionary <NSString *, NSString *>* requestHeaders, NSString * urlPath, NSDictionary <NSString *, NSString *>* urlQuery) {
1029+ if (![requestMethod isEqualToString: @" GET" ]) {
1030+ return nil ;
1031+ }
1032+ if (![urlPath hasPrefix: basePath]) {
1033+ return nil ;
1034+ }
1035+ return [[GCDWebServerRequest alloc ] initWithMethod: requestMethod url: requestURL headers: requestHeaders path: urlPath query: urlQuery];
1036+ }
10331037 processBlock: ^GCDWebServerResponse*(GCDWebServerRequest* request) {
10341038 GCDWebServerResponse* response = nil ;
10351039 NSString * filePath = [directoryPath stringByAppendingPathComponent: GCDWebServerNormalizePath ([request.path substringFromIndex: basePath.length])];
0 commit comments