Switches from GCDWebServer to CocoaHTTPServer so we can have HTTPS eventually
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user