Updated to clang-format 7.0.0

This commit is contained in:
Pierre-Olivier Latour
2018-12-14 07:10:03 -08:00
parent 7df465336e
commit bac5b680df
9 changed files with 6 additions and 89 deletions
-22
View File
@@ -206,10 +206,8 @@ static void _ExecuteMainThreadRunLoopSources() {
if (_backgroundTask == UIBackgroundTaskInvalid) { if (_backgroundTask == UIBackgroundTaskInvalid) {
GWS_LOG_DEBUG(@"Did start background task"); GWS_LOG_DEBUG(@"Did start background task");
_backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ _backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
GWS_LOG_WARNING(@"Application is being suspended while %@ is still connected", [self class]); GWS_LOG_WARNING(@"Application is being suspended while %@ is still connected", [self class]);
[self _endBackgroundTask]; [self _endBackgroundTask];
}]; }];
} else { } else {
GWS_DNOT_REACHED(); GWS_DNOT_REACHED();
@@ -238,7 +236,6 @@ static void _ExecuteMainThreadRunLoopSources() {
- (void)willStartConnection:(GCDWebServerConnection*)connection { - (void)willStartConnection:(GCDWebServerConnection*)connection {
dispatch_sync(_syncQueue, ^{ dispatch_sync(_syncQueue, ^{
GWS_DCHECK(_activeConnections >= 0); GWS_DCHECK(_activeConnections >= 0);
if (_activeConnections == 0) { if (_activeConnections == 0) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
@@ -253,7 +250,6 @@ static void _ExecuteMainThreadRunLoopSources() {
}); });
} }
_activeConnections += 1; _activeConnections += 1;
}); });
} }
@@ -469,7 +465,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
dispatch_group_enter(_sourceGroup); dispatch_group_enter(_sourceGroup);
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, listeningSocket, 0, dispatch_get_global_queue(_dispatchQueuePriority, 0)); dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, listeningSocket, 0, dispatch_get_global_queue(_dispatchQueuePriority, 0));
dispatch_source_set_cancel_handler(source, ^{ dispatch_source_set_cancel_handler(source, ^{
@autoreleasepool { @autoreleasepool {
int result = close(listeningSocket); int result = close(listeningSocket);
if (result != 0) { if (result != 0) {
@@ -479,10 +474,8 @@ static inline NSString* _EncodeBase64(NSString* string) {
} }
} }
dispatch_group_leave(_sourceGroup); dispatch_group_leave(_sourceGroup);
}); });
dispatch_source_set_event_handler(source, ^{ dispatch_source_set_event_handler(source, ^{
@autoreleasepool { @autoreleasepool {
struct sockaddr_storage remoteSockAddr; struct sockaddr_storage remoteSockAddr;
socklen_t remoteAddrLen = sizeof(remoteSockAddr); socklen_t remoteAddrLen = sizeof(remoteSockAddr);
@@ -509,7 +502,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
GWS_LOG_ERROR(@"Failed accepting %s socket: %s (%i)", isIPv6 ? "IPv6" : "IPv4", strerror(errno), errno); GWS_LOG_ERROR(@"Failed accepting %s socket: %s (%i)", isIPv6 ? "IPv6" : "IPv4", strerror(errno), errno);
} }
} }
}); });
return source; return source;
} }
@@ -877,12 +869,10 @@ static inline NSString* _EncodeBase64(NSString* string) {
- (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block { - (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block {
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) { [self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
if (![requestMethod isEqualToString:method]) { if (![requestMethod isEqualToString:method]) {
return nil; return nil;
} }
return [[aClass alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery]; return [[aClass alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery];
} }
asyncProcessBlock:block]; asyncProcessBlock:block];
} }
@@ -899,7 +889,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
- (void)addHandlerForMethod:(NSString*)method path:(NSString*)path requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block { - (void)addHandlerForMethod:(NSString*)method path:(NSString*)path requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block {
if ([path hasPrefix:@"/"] && [aClass isSubclassOfClass:[GCDWebServerRequest class]]) { if ([path hasPrefix:@"/"] && [aClass isSubclassOfClass:[GCDWebServerRequest class]]) {
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) { [self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
if (![requestMethod isEqualToString:method]) { if (![requestMethod isEqualToString:method]) {
return nil; return nil;
} }
@@ -907,7 +896,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
return nil; return nil;
} }
return [[aClass alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery]; return [[aClass alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery];
} }
asyncProcessBlock:block]; asyncProcessBlock:block];
} else { } else {
@@ -928,7 +916,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
NSRegularExpression* expression = [NSRegularExpression regularExpressionWithPattern:regex options:NSRegularExpressionCaseInsensitive error:NULL]; NSRegularExpression* expression = [NSRegularExpression regularExpressionWithPattern:regex options:NSRegularExpressionCaseInsensitive error:NULL];
if (expression && [aClass isSubclassOfClass:[GCDWebServerRequest class]]) { if (expression && [aClass isSubclassOfClass:[GCDWebServerRequest class]]) {
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) { [self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
if (![requestMethod isEqualToString:method]) { if (![requestMethod isEqualToString:method]) {
return nil; return nil;
} }
@@ -954,7 +941,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
GCDWebServerRequest* request = [[aClass alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery]; GCDWebServerRequest* request = [[aClass alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery];
[request setAttribute:captures forKey:GCDWebServerRequestAttribute_RegexCaptures]; [request setAttribute:captures forKey:GCDWebServerRequestAttribute_RegexCaptures];
return request; return request;
} }
asyncProcessBlock:block]; asyncProcessBlock:block];
} else { } else {
@@ -971,11 +957,9 @@ static inline NSString* _EncodeBase64(NSString* string) {
path:path path:path
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) {
GCDWebServerResponse* response = [GCDWebServerDataResponse responseWithData:staticData contentType:contentType]; GCDWebServerResponse* response = [GCDWebServerDataResponse responseWithData:staticData contentType:contentType];
response.cacheControlMaxAge = cacheAge; response.cacheControlMaxAge = cacheAge;
return response; return response;
}]; }];
} }
@@ -984,7 +968,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
path:path path:path
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) {
GCDWebServerResponse* response = nil; GCDWebServerResponse* response = nil;
if (allowRangeRequests) { if (allowRangeRequests) {
response = [GCDWebServerFileResponse responseWithFile:filePath byteRange:request.byteRange isAttachment:isAttachment]; response = [GCDWebServerFileResponse responseWithFile:filePath byteRange:request.byteRange isAttachment:isAttachment];
@@ -994,7 +977,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
} }
response.cacheControlMaxAge = cacheAge; response.cacheControlMaxAge = cacheAge;
return response; return response;
}]; }];
} }
@@ -1032,7 +1014,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
if ([basePath hasPrefix:@"/"] && [basePath hasSuffix:@"/"]) { if ([basePath hasPrefix:@"/"] && [basePath hasSuffix:@"/"]) {
GCDWebServer* __unsafe_unretained server = self; GCDWebServer* __unsafe_unretained server = self;
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) { [self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
if (![requestMethod isEqualToString:@"GET"]) { if (![requestMethod isEqualToString:@"GET"]) {
return nil; return nil;
} }
@@ -1040,10 +1021,8 @@ static inline NSString* _EncodeBase64(NSString* string) {
return nil; return nil;
} }
return [[GCDWebServerRequest alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery]; return [[GCDWebServerRequest alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:urlPath query:urlQuery];
} }
processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) {
GCDWebServerResponse* response = nil; GCDWebServerResponse* response = nil;
NSString* filePath = [directoryPath stringByAppendingPathComponent:[request.path substringFromIndex:basePath.length]]; NSString* filePath = [directoryPath stringByAppendingPathComponent:[request.path substringFromIndex:basePath.length]];
NSString* fileType = [[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:NULL] fileType]; NSString* fileType = [[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:NULL] fileType];
@@ -1072,7 +1051,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
response = [GCDWebServerResponse responseWithStatusCode:kGCDWebServerHTTPStatusCode_NotFound]; response = [GCDWebServerResponse responseWithStatusCode:kGCDWebServerHTTPStatusCode_NotFound];
} }
return response; return response;
}]; }];
} else { } else {
GWS_DNOT_REACHED(); GWS_DNOT_REACHED();
@@ -196,19 +196,15 @@ NS_ASSUME_NONNULL_END
CFHTTPMessageSetHeaderFieldValue(_responseMessage, (__bridge CFStringRef)key, (__bridge CFStringRef)obj); CFHTTPMessageSetHeaderFieldValue(_responseMessage, (__bridge CFStringRef)key, (__bridge CFStringRef)obj);
}]; }];
[self writeHeadersWithCompletionBlock:^(BOOL success) { [self writeHeadersWithCompletionBlock:^(BOOL success) {
if (success) { if (success) {
if (hasBody) { if (hasBody) {
[self writeBodyWithCompletionBlock:^(BOOL successInner) { [self writeBodyWithCompletionBlock:^(BOOL successInner) {
[_response performClose]; // TODO: There's nothing we can do on failure as headers have already been sent [_response performClose]; // TODO: There's nothing we can do on failure as headers have already been sent
}]; }];
} }
} else if (hasBody) { } else if (hasBody) {
[_response performClose]; [_response performClose];
} }
}]; }];
} else { } else {
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError]; [self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError];
@@ -238,7 +234,6 @@ NS_ASSUME_NONNULL_END
if (length) { if (length) {
[self readBodyWithRemainingLength:length [self readBodyWithRemainingLength:length
completionBlock:^(BOOL success) { completionBlock:^(BOOL success) {
NSError* localError = nil; NSError* localError = nil;
if ([_request performClose:&localError]) { if ([_request performClose:&localError]) {
[self _startProcessingRequest]; [self _startProcessingRequest];
@@ -246,7 +241,6 @@ NS_ASSUME_NONNULL_END
GWS_LOG_ERROR(@"Failed closing request body for socket %i: %@", _socket, error); GWS_LOG_ERROR(@"Failed closing request body for socket %i: %@", _socket, error);
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError]; [self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError];
} }
}]; }];
} else { } else {
if ([_request performClose:&error]) { if ([_request performClose:&error]) {
@@ -269,7 +263,6 @@ NS_ASSUME_NONNULL_END
NSMutableData* chunkData = [[NSMutableData alloc] initWithData:initialData]; NSMutableData* chunkData = [[NSMutableData alloc] initWithData:initialData];
[self readNextBodyChunk:chunkData [self readNextBodyChunk:chunkData
completionBlock:^(BOOL success) { completionBlock:^(BOOL success) {
NSError* localError = nil; NSError* localError = nil;
if ([_request performClose:&localError]) { if ([_request performClose:&localError]) {
[self _startProcessingRequest]; [self _startProcessingRequest];
@@ -277,7 +270,6 @@ NS_ASSUME_NONNULL_END
GWS_LOG_ERROR(@"Failed closing request body for socket %i: %@", _socket, error); GWS_LOG_ERROR(@"Failed closing request body for socket %i: %@", _socket, error);
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError]; [self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError];
} }
}]; }];
} }
@@ -286,7 +278,6 @@ NS_ASSUME_NONNULL_END
NSMutableData* headersData = [[NSMutableData alloc] initWithCapacity:kHeadersReadCapacity]; NSMutableData* headersData = [[NSMutableData alloc] initWithCapacity:kHeadersReadCapacity];
[self readHeaders:headersData [self readHeaders:headersData
withCompletionBlock:^(NSData* extraData) { withCompletionBlock:^(NSData* extraData) {
if (extraData) { if (extraData) {
NSString* requestMethod = CFBridgingRelease(CFHTTPMessageCopyRequestMethod(_requestMessage)); // Method verbs are case-sensitive and uppercase NSString* requestMethod = CFBridgingRelease(CFHTTPMessageCopyRequestMethod(_requestMessage)); // Method verbs are case-sensitive and uppercase
if (_server.shouldAutomaticallyMapHEADToGET && [requestMethod isEqualToString:@"HEAD"]) { if (_server.shouldAutomaticallyMapHEADToGET && [requestMethod isEqualToString:@"HEAD"]) {
@@ -324,7 +315,6 @@ NS_ASSUME_NONNULL_END
if ([expectHeader caseInsensitiveCompare:@"100-continue"] == NSOrderedSame) { // TODO: Actually validate request before continuing if ([expectHeader caseInsensitiveCompare:@"100-continue"] == NSOrderedSame) { // TODO: Actually validate request before continuing
[self writeData:_continueData [self writeData:_continueData
withCompletionBlock:^(BOOL success) { withCompletionBlock:^(BOOL success) {
if (success) { if (success) {
if (_request.usesChunkedTransferEncoding) { if (_request.usesChunkedTransferEncoding) {
[self _readChunkedBodyWithInitialData:extraData]; [self _readChunkedBodyWithInitialData:extraData];
@@ -332,7 +322,6 @@ NS_ASSUME_NONNULL_END
[self _readBodyWithLength:_request.contentLength initialData:extraData]; [self _readBodyWithLength:_request.contentLength initialData:extraData];
} }
} }
}]; }];
} else { } else {
GWS_LOG_ERROR(@"Unsupported 'Expect' / 'Content-Length' header combination on socket %i", _socket); GWS_LOG_ERROR(@"Unsupported 'Expect' / 'Content-Length' header combination on socket %i", _socket);
@@ -364,7 +353,6 @@ NS_ASSUME_NONNULL_END
} else { } else {
[self abortRequest:nil withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError]; [self abortRequest:nil withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError];
} }
}]; }];
} }
@@ -426,7 +414,6 @@ NS_ASSUME_NONNULL_END
- (void)readData:(NSMutableData*)data withLength:(NSUInteger)length completionBlock:(ReadDataCompletionBlock)block { - (void)readData:(NSMutableData*)data withLength:(NSUInteger)length completionBlock:(ReadDataCompletionBlock)block {
dispatch_read(_socket, length, dispatch_get_global_queue(_server.dispatchQueuePriority, 0), ^(dispatch_data_t buffer, int error) { dispatch_read(_socket, length, dispatch_get_global_queue(_server.dispatchQueuePriority, 0), ^(dispatch_data_t buffer, int error) {
@autoreleasepool { @autoreleasepool {
if (error == 0) { if (error == 0) {
size_t size = dispatch_data_get_size(buffer); size_t size = dispatch_data_get_size(buffer);
@@ -451,7 +438,6 @@ NS_ASSUME_NONNULL_END
block(NO); block(NO);
} }
} }
}); });
} }
@@ -460,7 +446,6 @@ NS_ASSUME_NONNULL_END
[self readData:headersData [self readData:headersData
withLength:NSUIntegerMax withLength:NSUIntegerMax
completionBlock:^(BOOL success) { completionBlock:^(BOOL success) {
if (success) { if (success) {
NSRange range = [headersData rangeOfData:_CRLFCRLFData options:0 range:NSMakeRange(0, headersData.length)]; NSRange range = [headersData rangeOfData:_CRLFCRLFData options:0 range:NSMakeRange(0, headersData.length)];
if (range.location == NSNotFound) { if (range.location == NSNotFound) {
@@ -482,7 +467,6 @@ NS_ASSUME_NONNULL_END
} else { } else {
block(nil); block(nil);
} }
}]; }];
} }
@@ -492,7 +476,6 @@ NS_ASSUME_NONNULL_END
[self readData:bodyData [self readData:bodyData
withLength:length withLength:length
completionBlock:^(BOOL success) { completionBlock:^(BOOL success) {
if (success) { if (success) {
if (bodyData.length <= length) { if (bodyData.length <= length) {
NSError* error = nil; NSError* error = nil;
@@ -515,7 +498,6 @@ NS_ASSUME_NONNULL_END
} else { } else {
block(NO); block(NO);
} }
}]; }];
} }
@@ -575,13 +557,11 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
[self readData:chunkData [self readData:chunkData
withLength:NSUIntegerMax withLength:NSUIntegerMax
completionBlock:^(BOOL success) { completionBlock:^(BOOL success) {
if (success) { if (success) {
[self readNextBodyChunk:chunkData completionBlock:block]; [self readNextBodyChunk:chunkData completionBlock:block];
} else { } else {
block(NO); block(NO);
} }
}]; }];
} }
@@ -594,7 +574,6 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
[data self]; // Keeps ARC from releasing data too early [data self]; // Keeps ARC from releasing data too early
}); });
dispatch_write(_socket, buffer, dispatch_get_global_queue(_server.dispatchQueuePriority, 0), ^(dispatch_data_t remainingData, int error) { dispatch_write(_socket, buffer, dispatch_get_global_queue(_server.dispatchQueuePriority, 0), ^(dispatch_data_t remainingData, int error) {
@autoreleasepool { @autoreleasepool {
if (error == 0) { if (error == 0) {
GWS_DCHECK(remainingData == NULL); GWS_DCHECK(remainingData == NULL);
@@ -605,7 +584,6 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
block(NO); block(NO);
} }
} }
}); });
#if !OS_OBJECT_USE_OBJC_RETAIN_RELEASE #if !OS_OBJECT_USE_OBJC_RETAIN_RELEASE
dispatch_release(buffer); dispatch_release(buffer);
@@ -622,7 +600,6 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
- (void)writeBodyWithCompletionBlock:(WriteBodyCompletionBlock)block { - (void)writeBodyWithCompletionBlock:(WriteBodyCompletionBlock)block {
GWS_DCHECK([_response hasBody]); GWS_DCHECK([_response hasBody]);
[_response performReadDataWithCompletion:^(NSData* data, NSError* error) { [_response performReadDataWithCompletion:^(NSData* data, NSError* error) {
if (data) { if (data) {
if (data.length) { if (data.length) {
if (_response.usesChunkedTransferEncoding) { if (_response.usesChunkedTransferEncoding) {
@@ -647,21 +624,17 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
} }
[self writeData:data [self writeData:data
withCompletionBlock:^(BOOL success) { withCompletionBlock:^(BOOL success) {
if (success) { if (success) {
[self writeBodyWithCompletionBlock:block]; [self writeBodyWithCompletionBlock:block];
} else { } else {
block(NO); block(NO);
} }
}]; }];
} else { } else {
if (_response.usesChunkedTransferEncoding) { if (_response.usesChunkedTransferEncoding) {
[self writeData:_lastChunkData [self writeData:_lastChunkData
withCompletionBlock:^(BOOL success) { withCompletionBlock:^(BOOL success) {
block(success); block(success);
}]; }];
} else { } else {
block(YES); block(YES);
@@ -671,7 +644,6 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
GWS_LOG_ERROR(@"Failed reading response body for socket %i: %@", _socket, error); GWS_LOG_ERROR(@"Failed reading response body for socket %i: %@", _socket, error);
block(NO); block(NO);
} }
}]; }];
} }
@@ -48,11 +48,9 @@
- (instancetype)initWithContentType:(NSString*)type streamBlock:(GCDWebServerStreamBlock)block { - (instancetype)initWithContentType:(NSString*)type streamBlock:(GCDWebServerStreamBlock)block {
return [self initWithContentType:type return [self initWithContentType:type
asyncStreamBlock:^(GCDWebServerBodyReaderCompletionBlock completionBlock) { asyncStreamBlock:^(GCDWebServerBodyReaderCompletionBlock completionBlock) {
NSError* error = nil; NSError* error = nil;
NSData* data = block(&error); NSData* data = block(&error);
completionBlock(data, error); completionBlock(data, error);
}]; }];
} }
-1
View File
@@ -135,7 +135,6 @@ NS_ASSUME_NONNULL_END
@"epilogue" : epilogue, @"epilogue" : epilogue,
@"footer" : footer @"footer" : footer
}]; }];
}]; }];
// File listing // File listing
-30
View File
@@ -219,9 +219,7 @@ int main(int argc, const char* argv[]) {
[webServer addDefaultHandlerForMethod:@"GET" [webServer addDefaultHandlerForMethod:@"GET"
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) {
return [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello World</p></body></html>"]; return [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello World</p></body></html>"];
}]; }];
break; break;
} }
@@ -234,7 +232,6 @@ int main(int argc, const char* argv[]) {
path:@"/" path:@"/"
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) {
NSString* html = @" \ NSString* html = @" \
<html><body> \ <html><body> \
<form name=\"input\" action=\"/\" method=\"post\" enctype=\"application/x-www-form-urlencoded\"> \ <form name=\"input\" action=\"/\" method=\"post\" enctype=\"application/x-www-form-urlencoded\"> \
@@ -244,17 +241,14 @@ int main(int argc, const char* argv[]) {
</body></html> \ </body></html> \
"; ";
return [GCDWebServerDataResponse responseWithHTML:html]; return [GCDWebServerDataResponse responseWithHTML:html];
}]; }];
[webServer addHandlerForMethod:@"POST" [webServer addHandlerForMethod:@"POST"
path:@"/" path:@"/"
requestClass:[GCDWebServerURLEncodedFormRequest class] requestClass:[GCDWebServerURLEncodedFormRequest class]
processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) {
NSString* value = [[(GCDWebServerURLEncodedFormRequest*)request arguments] objectForKey:@"value"]; NSString* value = [[(GCDWebServerURLEncodedFormRequest*)request arguments] objectForKey:@"value"];
NSString* html = [NSString stringWithFormat:@"<html><body><p>%@</p></body></html>", value]; NSString* html = [NSString stringWithFormat:@"<html><body><p>%@</p></body></html>", value];
return [GCDWebServerDataResponse responseWithHTML:html]; return [GCDWebServerDataResponse responseWithHTML:html];
}]; }];
break; break;
} }
@@ -274,16 +268,13 @@ int main(int argc, const char* argv[]) {
path:@"/" path:@"/"
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) {
NSString* html = [NSString stringWithFormat:@"<html><body>%@</body></html>", formHTML]; NSString* html = [NSString stringWithFormat:@"<html><body>%@</body></html>", formHTML];
return [GCDWebServerDataResponse responseWithHTML:html]; return [GCDWebServerDataResponse responseWithHTML:html];
}]; }];
[webServer addHandlerForMethod:@"POST" [webServer addHandlerForMethod:@"POST"
path:@"/" path:@"/"
requestClass:[GCDWebServerMultiPartFormRequest class] requestClass:[GCDWebServerMultiPartFormRequest class]
processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) {
NSMutableString* string = [NSMutableString string]; NSMutableString* string = [NSMutableString string];
for (GCDWebServerMultiPartArgument* argument in [(GCDWebServerMultiPartFormRequest*)request arguments]) { for (GCDWebServerMultiPartArgument* argument in [(GCDWebServerMultiPartFormRequest*)request arguments]) {
[string appendFormat:@"%@ = %@<br>", argument.controlName, argument.string]; [string appendFormat:@"%@ = %@<br>", argument.controlName, argument.string];
@@ -296,7 +287,6 @@ int main(int argc, const char* argv[]) {
}; };
NSString* html = [NSString stringWithFormat:@"<html><body><p>%@</p><hr>%@</body></html>", string, formHTML]; NSString* html = [NSString stringWithFormat:@"<html><body><p>%@</p><hr>%@</body></html>", string, formHTML];
return [GCDWebServerDataResponse responseWithHTML:html]; return [GCDWebServerDataResponse responseWithHTML:html];
}]; }];
break; break;
} }
@@ -323,39 +313,29 @@ int main(int argc, const char* argv[]) {
path:@"/sync" path:@"/sync"
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) {
__block int countDown = 10; __block int countDown = 10;
return [GCDWebServerStreamedResponse responseWithContentType:@"text/plain" return [GCDWebServerStreamedResponse responseWithContentType:@"text/plain"
streamBlock:^NSData*(NSError** error) { streamBlock:^NSData*(NSError** error) {
usleep(100 * 1000); usleep(100 * 1000);
if (countDown) { if (countDown) {
return [[NSString stringWithFormat:@"%i\n", countDown--] dataUsingEncoding:NSUTF8StringEncoding]; return [[NSString stringWithFormat:@"%i\n", countDown--] dataUsingEncoding:NSUTF8StringEncoding];
} else { } else {
return [NSData data]; return [NSData data];
} }
}]; }];
}]; }];
[webServer addHandlerForMethod:@"GET" [webServer addHandlerForMethod:@"GET"
path:@"/async" path:@"/async"
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse*(GCDWebServerRequest* request) {
__block int countDown = 10; __block int countDown = 10;
return [GCDWebServerStreamedResponse responseWithContentType:@"text/plain" return [GCDWebServerStreamedResponse responseWithContentType:@"text/plain"
asyncStreamBlock:^(GCDWebServerBodyReaderCompletionBlock completionBlock) { asyncStreamBlock:^(GCDWebServerBodyReaderCompletionBlock completionBlock) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSData* data = countDown ? [[NSString stringWithFormat:@"%i\n", countDown--] dataUsingEncoding:NSUTF8StringEncoding] : [NSData data]; NSData* data = countDown ? [[NSString stringWithFormat:@"%i\n", countDown--] dataUsingEncoding:NSUTF8StringEncoding] : [NSData data];
completionBlock(data, nil); completionBlock(data, nil);
}); });
}]; }];
}]; }];
break; break;
} }
@@ -368,36 +348,26 @@ int main(int argc, const char* argv[]) {
path:@"/async" path:@"/async"
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
asyncProcessBlock:^(GCDWebServerRequest* request, GCDWebServerCompletionBlock completionBlock) { asyncProcessBlock:^(GCDWebServerRequest* request, GCDWebServerCompletionBlock completionBlock) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
GCDWebServerDataResponse* response = [GCDWebServerDataResponse responseWithData:(NSData*)[@"Hello World!" dataUsingEncoding:NSUTF8StringEncoding] contentType:@"text/plain"]; GCDWebServerDataResponse* response = [GCDWebServerDataResponse responseWithData:(NSData*)[@"Hello World!" dataUsingEncoding:NSUTF8StringEncoding] contentType:@"text/plain"];
completionBlock(response); completionBlock(response);
}); });
}]; }];
[webServer addHandlerForMethod:@"GET" [webServer addHandlerForMethod:@"GET"
path:@"/async2" path:@"/async2"
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
asyncProcessBlock:^(GCDWebServerRequest* request, GCDWebServerCompletionBlock handlerCompletionBlock) { asyncProcessBlock:^(GCDWebServerRequest* request, GCDWebServerCompletionBlock handlerCompletionBlock) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
__block int countDown = 10; __block int countDown = 10;
GCDWebServerStreamedResponse* response = [GCDWebServerStreamedResponse responseWithContentType:@"text/plain" GCDWebServerStreamedResponse* response = [GCDWebServerStreamedResponse responseWithContentType:@"text/plain"
asyncStreamBlock:^(GCDWebServerBodyReaderCompletionBlock readerCompletionBlock) { asyncStreamBlock:^(GCDWebServerBodyReaderCompletionBlock readerCompletionBlock) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSData* data = countDown ? [[NSString stringWithFormat:@"%i\n", countDown--] dataUsingEncoding:NSUTF8StringEncoding] : [NSData data]; NSData* data = countDown ? [[NSString stringWithFormat:@"%i\n", countDown--] dataUsingEncoding:NSUTF8StringEncoding] : [NSData data];
readerCompletionBlock(data, nil); readerCompletionBlock(data, nil);
}); });
}]; }];
handlerCompletionBlock(response); handlerCompletionBlock(response);
}); });
}]; }];
break; break;
} }
+1 -1
View File
@@ -3,7 +3,7 @@
# brew install clang-format # brew install clang-format
CLANG_FORMAT_VERSION=`clang-format -version | awk '{ print $3 }'` CLANG_FORMAT_VERSION=`clang-format -version | awk '{ print $3 }'`
if [[ "$CLANG_FORMAT_VERSION" != "5.0.0" ]]; then if [[ "$CLANG_FORMAT_VERSION" != "7.0.0" ]]; then
echo "Unsupported clang-format version" echo "Unsupported clang-format version"
exit 1 exit 1
fi fi