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

@@ -0,0 +1,11 @@
//
// MBIMHTTPUtilities.h
// kordophoned
//
// Created by James Magahern on 11/16/18.
// Copyright © 2018 James Magahern. All rights reserved.
//
#import <Foundation/Foundation.h>
NSString* MBIMWebServerFormatRFC822(NSDate *date);

View File

@@ -0,0 +1,33 @@
//
// MBIMHTTPUtilities.c
// kordophoned
//
// Created by James Magahern on 11/16/18.
// Copyright © 2018 James Magahern. All rights reserved.
//
#include "MBIMHTTPUtilities.h"
static NSDateFormatter* _dateFormatterRFC822 = nil;
static dispatch_queue_t _dateFormatterQueue = NULL;
__attribute__((constructor))
static void __InitializeDateFormatter()
{
_dateFormatterQueue = dispatch_queue_create("dateFormatter", DISPATCH_QUEUE_SERIAL);
_dateFormatterRFC822 = [[NSDateFormatter alloc] init];
_dateFormatterRFC822.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
_dateFormatterRFC822.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";
_dateFormatterRFC822.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
}
NSString* MBIMWebServerFormatRFC822(NSDate *date)
{
__block NSString *string = nil;
dispatch_sync(_dateFormatterQueue, ^{
string = [_dateFormatterRFC822 stringFromDate:date];
});
return string;
}

View File

@@ -0,0 +1,16 @@
//
// MBIMJSONDataResponse.h
// kordophoned
//
// Created by James Magahern on 11/16/18.
// Copyright © 2018 James Magahern. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CocoaHTTPServer/CocoaHTTPServer.h>
@interface MBIMJSONDataResponse : HTTPDataResponse
+ (instancetype)responseWithJSONObject:(id)object;
@end

View File

@@ -0,0 +1,32 @@
//
// MBIMJSONDataResponse.m
// kordophoned
//
// Created by James Magahern on 11/16/18.
// Copyright © 2018 James Magahern. All rights reserved.
//
#import "MBIMJSONDataResponse.h"
@implementation MBIMJSONDataResponse
+ (instancetype)responseWithJSONObject:(id)object
{
NSData *data = [NSJSONSerialization dataWithJSONObject:object options:0 error:NULL];
if (data == nil) {
return nil;
}
MBIMJSONDataResponse *response = [[self alloc] initWithData:data];
return response;
}
- (NSDictionary *)httpHeaders
{
return @{
@"Content-Type" : @"application/json; charset=utf-8"
};
}
@end