Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit df8d66f

Browse files
committed
Formatted source
1 parent 45432e6 commit df8d66f

File tree

4 files changed

+63
-57
lines changed

4 files changed

+63
-57
lines changed

GCDWebServer/Core/GCDWebServer.m

+54-50
Original file line numberDiff line numberDiff line change
@@ -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])];

GCDWebServer/Core/GCDWebServerConnection.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@ - (void)abortRequest:(GCDWebServerRequest*)request withStatusCode:(NSInteger)sta
794794
GWS_DCHECK(_responseMessage == NULL);
795795
GWS_DCHECK((statusCode >= 400) && (statusCode < 600));
796796
[self _initializeResponseHeadersWithStatusCode:statusCode];
797-
[self writeHeadersWithCompletionBlock:^(BOOL success) {
798-
// Nothing more to do
797+
[self writeHeadersWithCompletionBlock:^(BOOL success){
798+
// Nothing more to do
799799
}];
800800
GWS_LOG_DEBUG(@"Connection aborted with status code %i on socket %i", (int)statusCode, _socket);
801801
}

Mac/main.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ int main(int argc, const char* argv[]) {
380380
webServer.delegate = delegate;
381381
#endif
382382
fprintf(stdout, "<RUNNING TESTS FROM \"%s\">\n\n", [testDirectory UTF8String]);
383-
result = (int)[webServer runTestsWithOptions:@{ GCDWebServerOption_Port : @8080 } inDirectory:testDirectory];
383+
result = (int)[webServer runTestsWithOptions:@{GCDWebServerOption_Port : @8080} inDirectory:testDirectory];
384384
} else {
385385
webServer.delegate = delegate;
386386
if (recording) {

format-source.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
# brew install clang-format
44

5+
SWIFT_FORMAT_VERSION='0.44.5'
6+
57
CLANG_FORMAT_VERSION=`clang-format -version | awk '{ print $3 }'`
6-
if [[ "$CLANG_FORMAT_VERSION" != "7.0.0" ]]; then
8+
if [[ "$CLANG_FORMAT_VERSION" != "9.0.0" ]]; then
79
echo "Unsupported clang-format version"
810
exit 1
911
fi
1012

1113
if [[ ! -f "build/swiftformat" ]]; then
1214
mkdir -p "build"
13-
curl -sfL -o "build/SwiftFormat.zip" "https://github.com/nicklockwood/SwiftFormat/archive/0.37.2.zip"
14-
unzip "build/SwiftFormat.zip" "SwiftFormat-0.37.2/CommandLineTool/swiftformat" -d "build"
15-
mv "build/SwiftFormat-0.37.2/CommandLineTool/swiftformat" "build/swiftformat"
15+
curl -sfL -o "build/SwiftFormat.zip" "https://github.com/nicklockwood/SwiftFormat/archive/$SWIFT_FORMAT_VERSION.zip"
16+
unzip "build/SwiftFormat.zip" "SwiftFormat-$SWIFT_FORMAT_VERSION/CommandLineTool/swiftformat" -d "build"
17+
mv "build/SwiftFormat-$SWIFT_FORMAT_VERSION/CommandLineTool/swiftformat" "build/swiftformat"
1618
fi
1719

1820
pushd "GCDWebServer/Core"

0 commit comments

Comments
 (0)