Switches from GCDWebServer to CocoaHTTPServer so we can have HTTPS eventually
This commit is contained in:
@@ -8,9 +8,10 @@
|
||||
|
||||
#import "MBIMBridge.h"
|
||||
#import "MBIMBridgeOperation.h"
|
||||
#import "MBIMHTTPConnection.h"
|
||||
#import "hooking.h"
|
||||
|
||||
#import <GCDWebServers/GCDWebServers.h>
|
||||
#import <CocoaHTTPServer/CocoaHTTPServer.h>
|
||||
|
||||
#import <IMCore/IMCore.h>
|
||||
#import <IMCore/IMCore_Private.h>
|
||||
@@ -21,7 +22,7 @@
|
||||
static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone";
|
||||
|
||||
@interface MBIMBridge (/* INTERNAL */)
|
||||
@property (nonatomic, strong) GCDWebServer *webServer;
|
||||
@property (nonatomic, strong) HTTPServer *httpServer;
|
||||
@property (nonatomic, strong) NSOperationQueue *operationQueue;
|
||||
|
||||
- (instancetype)_init;
|
||||
@@ -130,33 +131,16 @@ static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone";
|
||||
#pragma mark -
|
||||
#pragma mark Web Server initialization
|
||||
|
||||
- (void)_handleAsyncServerRequest:(GCDWebServerRequest *)request completion:(GCDWebServerCompletionBlock)completion
|
||||
{
|
||||
NSString *endpointName = [[request URL] lastPathComponent];
|
||||
Class operationClass = [MBIMBridgeOperation operationClassForEndpointName:endpointName];
|
||||
if (operationClass != nil) {
|
||||
MBIMBridgeOperation *operation = [[operationClass alloc] initWithRequest:request completion:completion];
|
||||
[[self operationQueue] addOperation:operation];
|
||||
} else {
|
||||
completion([GCDWebServerDataResponse responseWithStatusCode:404]);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startWebServer
|
||||
{
|
||||
[GCDWebServer setLogLevel:3];
|
||||
self.httpServer = [[HTTPServer alloc] init];
|
||||
[self.httpServer setConnectionClass:[MBIMHTTPConnection class]];
|
||||
[self.httpServer setPort:8080];
|
||||
|
||||
__auto_type __weak weakSelf = self;
|
||||
self.webServer = [[GCDWebServer alloc] init];
|
||||
[self.webServer addDefaultHandlerForMethod:@"GET"
|
||||
requestClass:[GCDWebServerRequest class]
|
||||
asyncProcessBlock:^(__kindof GCDWebServerRequest * _Nonnull request, GCDWebServerCompletionBlock _Nonnull completionBlock) { [weakSelf _handleAsyncServerRequest:request completion:completionBlock]; }];
|
||||
|
||||
[self.webServer addDefaultHandlerForMethod:@"POST"
|
||||
requestClass:[GCDWebServerURLEncodedFormRequest class]
|
||||
asyncProcessBlock:^(__kindof GCDWebServerRequest * _Nonnull request, GCDWebServerCompletionBlock _Nonnull completionBlock) { [weakSelf _handleAsyncServerRequest:request completion:completionBlock]; }];
|
||||
|
||||
[self.webServer startWithPort:8080 bonjourName:nil];
|
||||
NSError *error = nil;
|
||||
if (![self.httpServer start:&error]) {
|
||||
NSLog(@"Error starting HTTP server: %@", [error localizedDescription]);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
Reference in New Issue
Block a user