Private
Public Access
1
0

Switches from GCDWebServer to CocoaHTTPServer so we can have HTTPS eventually

This commit is contained in:
2018-11-16 01:30:38 -08:00
parent 5ced6151c2
commit baffa7b035
20 changed files with 692 additions and 345 deletions

View File

@@ -41,20 +41,25 @@
- (void)main
{
assert([self.request isKindOfClass:[GCDWebServerURLEncodedFormRequest class]]);
NSObject<HTTPResponse> *response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
GCDWebServerURLEncodedFormRequest *formRequest = (GCDWebServerURLEncodedFormRequest *)self.request;
NSDictionary *args = [formRequest arguments];
NSError *error = nil;
NSDictionary *args = [NSJSONSerialization JSONObjectWithData:self.requestBodyData options:0 error:&error];
if (error || args.count == 0) {
self.serverCompletionBlock(response);
return;
}
NSString *guid = [args objectForKey:@"guid"];
NSString *messageBody = [args objectForKey:@"body"];
BOOL result = [self _sendMessage:messageBody toChatWithGUID:guid];
if (!guid || !messageBody) {
self.serverCompletionBlock(response);
return;
}
GCDWebServerResponse *response = nil;
BOOL result = [self _sendMessage:messageBody toChatWithGUID:guid];
if (result) {
response = [GCDWebServerDataResponse responseWithStatusCode:200];
} else {
response = [GCDWebServerDataResponse responseWithStatusCode:500];
response = [[HTTPErrorResponse alloc] initWithErrorCode:200];
}
self.serverCompletionBlock(response);