Move ivars to class extensions
This commit is contained in:
@ -31,14 +31,7 @@
|
|||||||
typedef GCDWebServerRequest* (^GCDWebServerMatchBlock)(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery);
|
typedef GCDWebServerRequest* (^GCDWebServerMatchBlock)(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery);
|
||||||
typedef GCDWebServerResponse* (^GCDWebServerProcessBlock)(GCDWebServerRequest* request);
|
typedef GCDWebServerResponse* (^GCDWebServerProcessBlock)(GCDWebServerRequest* request);
|
||||||
|
|
||||||
@interface GCDWebServer : NSObject {
|
@interface GCDWebServer : NSObject
|
||||||
@private
|
|
||||||
NSMutableArray* _handlers;
|
|
||||||
|
|
||||||
NSUInteger _port;
|
|
||||||
dispatch_source_t _source;
|
|
||||||
CFNetServiceRef _service;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly, getter=isRunning) BOOL running;
|
@property(nonatomic, readonly, getter=isRunning) BOOL running;
|
||||||
@property(nonatomic, readonly) NSUInteger port;
|
@property(nonatomic, readonly) NSUInteger port;
|
||||||
@property(nonatomic, readonly) NSString* bonjourName; // Only non-nil if Bonjour registration is active
|
@property(nonatomic, readonly) NSString* bonjourName; // Only non-nil if Bonjour registration is active
|
||||||
|
|||||||
@ -36,6 +36,23 @@
|
|||||||
|
|
||||||
#define kMaxPendingConnections 16
|
#define kMaxPendingConnections 16
|
||||||
|
|
||||||
|
@interface GCDWebServer () {
|
||||||
|
@private
|
||||||
|
NSMutableArray* _handlers;
|
||||||
|
|
||||||
|
NSUInteger _port;
|
||||||
|
dispatch_source_t _source;
|
||||||
|
CFNetServiceRef _service;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GCDWebServerHandler () {
|
||||||
|
@private
|
||||||
|
GCDWebServerMatchBlock _matchBlock;
|
||||||
|
GCDWebServerProcessBlock _processBlock;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
static BOOL _run;
|
static BOOL _run;
|
||||||
|
|
||||||
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension) {
|
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension) {
|
||||||
|
|||||||
@ -29,20 +29,7 @@
|
|||||||
|
|
||||||
@class GCDWebServerHandler;
|
@class GCDWebServerHandler;
|
||||||
|
|
||||||
@interface GCDWebServerConnection : NSObject {
|
@interface GCDWebServerConnection : NSObject
|
||||||
@private
|
|
||||||
GCDWebServer* _server;
|
|
||||||
NSData* _address;
|
|
||||||
CFSocketNativeHandle _socket;
|
|
||||||
NSUInteger _bytesRead;
|
|
||||||
NSUInteger _bytesWritten;
|
|
||||||
|
|
||||||
CFHTTPMessageRef _requestMessage;
|
|
||||||
GCDWebServerRequest* _request;
|
|
||||||
GCDWebServerHandler* _handler;
|
|
||||||
CFHTTPMessageRef _responseMessage;
|
|
||||||
GCDWebServerResponse* _response;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly) GCDWebServer* server;
|
@property(nonatomic, readonly) GCDWebServer* server;
|
||||||
@property(nonatomic, readonly) NSData* address; // struct sockaddr
|
@property(nonatomic, readonly) NSData* address; // struct sockaddr
|
||||||
@property(nonatomic, readonly) NSUInteger totalBytesRead;
|
@property(nonatomic, readonly) NSUInteger totalBytesRead;
|
||||||
|
|||||||
@ -45,6 +45,22 @@ static NSData* _continueData = nil;
|
|||||||
static NSDateFormatter* _dateFormatter = nil;
|
static NSDateFormatter* _dateFormatter = nil;
|
||||||
static dispatch_queue_t _formatterQueue = NULL;
|
static dispatch_queue_t _formatterQueue = NULL;
|
||||||
|
|
||||||
|
@interface GCDWebServerConnection () {
|
||||||
|
@private
|
||||||
|
GCDWebServer* _server;
|
||||||
|
NSData* _address;
|
||||||
|
CFSocketNativeHandle _socket;
|
||||||
|
NSUInteger _bytesRead;
|
||||||
|
NSUInteger _bytesWritten;
|
||||||
|
|
||||||
|
CFHTTPMessageRef _requestMessage;
|
||||||
|
GCDWebServerRequest* _request;
|
||||||
|
GCDWebServerHandler* _handler;
|
||||||
|
CFHTTPMessageRef _responseMessage;
|
||||||
|
GCDWebServerResponse* _response;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation GCDWebServerConnection (Read)
|
@implementation GCDWebServerConnection (Read)
|
||||||
|
|
||||||
- (void)_readBufferWithLength:(NSUInteger)length completionBlock:(ReadBufferCompletionBlock)block {
|
- (void)_readBufferWithLength:(NSUInteger)length completionBlock:(ReadBufferCompletionBlock)block {
|
||||||
|
|||||||
@ -126,11 +126,7 @@ NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form);
|
|||||||
@property(nonatomic, readonly) NSArray* handlers;
|
@property(nonatomic, readonly) NSArray* handlers;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerHandler : NSObject {
|
@interface GCDWebServerHandler : NSObject
|
||||||
@private
|
|
||||||
GCDWebServerMatchBlock _matchBlock;
|
|
||||||
GCDWebServerProcessBlock _processBlock;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly) GCDWebServerMatchBlock matchBlock;
|
@property(nonatomic, readonly) GCDWebServerMatchBlock matchBlock;
|
||||||
@property(nonatomic, readonly) GCDWebServerProcessBlock processBlock;
|
@property(nonatomic, readonly) GCDWebServerProcessBlock processBlock;
|
||||||
- (id)initWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock;
|
- (id)initWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock;
|
||||||
|
|||||||
@ -27,16 +27,7 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
@interface GCDWebServerRequest : NSObject {
|
@interface GCDWebServerRequest : NSObject
|
||||||
@private
|
|
||||||
NSString* _method;
|
|
||||||
NSURL* _url;
|
|
||||||
NSDictionary* _headers;
|
|
||||||
NSString* _path;
|
|
||||||
NSDictionary* _query;
|
|
||||||
NSString* _type;
|
|
||||||
NSUInteger _length;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly) NSString* method;
|
@property(nonatomic, readonly) NSString* method;
|
||||||
@property(nonatomic, readonly) NSURL* URL;
|
@property(nonatomic, readonly) NSURL* URL;
|
||||||
@property(nonatomic, readonly) NSDictionary* headers;
|
@property(nonatomic, readonly) NSDictionary* headers;
|
||||||
@ -54,18 +45,11 @@
|
|||||||
- (BOOL)close; // Implementation required
|
- (BOOL)close; // Implementation required
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerDataRequest : GCDWebServerRequest {
|
@interface GCDWebServerDataRequest : GCDWebServerRequest
|
||||||
@private
|
|
||||||
NSMutableData* _data;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly) NSData* data; // Only valid after open / write / close sequence
|
@property(nonatomic, readonly) NSData* data; // Only valid after open / write / close sequence
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerFileRequest : GCDWebServerRequest {
|
@interface GCDWebServerFileRequest : GCDWebServerRequest
|
||||||
@private
|
|
||||||
NSString* _filePath;
|
|
||||||
int _file;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly) NSString* filePath; // Only valid after open / write / close sequence
|
@property(nonatomic, readonly) NSString* filePath; // Only valid after open / write / close sequence
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -77,48 +61,22 @@
|
|||||||
+ (NSString*)mimeType;
|
+ (NSString*)mimeType;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerMultiPart : NSObject {
|
@interface GCDWebServerMultiPart : NSObject
|
||||||
@private
|
|
||||||
NSString* _contentType;
|
|
||||||
NSString* _mimeType;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly) NSString* contentType; // May be nil
|
@property(nonatomic, readonly) NSString* contentType; // May be nil
|
||||||
@property(nonatomic, readonly) NSString* mimeType; // Defaults to "text/plain" per specifications if undefined
|
@property(nonatomic, readonly) NSString* mimeType; // Defaults to "text/plain" per specifications if undefined
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerMultiPartArgument : GCDWebServerMultiPart {
|
@interface GCDWebServerMultiPartArgument : GCDWebServerMultiPart
|
||||||
@private
|
|
||||||
NSData* _data;
|
|
||||||
NSString* _string;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly) NSData* data;
|
@property(nonatomic, readonly) NSData* data;
|
||||||
@property(nonatomic, readonly) NSString* string; // May be nil (only valid for text mime types
|
@property(nonatomic, readonly) NSString* string; // May be nil (only valid for text mime types
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerMultiPartFile : GCDWebServerMultiPart {
|
@interface GCDWebServerMultiPartFile : GCDWebServerMultiPart
|
||||||
@private
|
|
||||||
NSString* _fileName;
|
|
||||||
NSString* _temporaryPath;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly) NSString* fileName; // May be nil
|
@property(nonatomic, readonly) NSString* fileName; // May be nil
|
||||||
@property(nonatomic, readonly) NSString* temporaryPath;
|
@property(nonatomic, readonly) NSString* temporaryPath;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerMultiPartFormRequest : GCDWebServerRequest {
|
@interface GCDWebServerMultiPartFormRequest : GCDWebServerRequest
|
||||||
@private
|
|
||||||
NSData* _boundary;
|
|
||||||
|
|
||||||
NSUInteger _parserState;
|
|
||||||
NSMutableData* _parserData;
|
|
||||||
NSString* _controlName;
|
|
||||||
NSString* _fileName;
|
|
||||||
NSString* _contentType;
|
|
||||||
NSString* _tmpPath;
|
|
||||||
int _tmpFile;
|
|
||||||
|
|
||||||
NSMutableDictionary* _arguments;
|
|
||||||
NSMutableDictionary* _files;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly) NSDictionary* arguments; // Only valid after open / write / close sequence
|
@property(nonatomic, readonly) NSDictionary* arguments; // Only valid after open / write / close sequence
|
||||||
@property(nonatomic, readonly) NSDictionary* files; // Only valid after open / write / close sequence
|
@property(nonatomic, readonly) NSDictionary* files; // Only valid after open / write / close sequence
|
||||||
+ (NSString*)mimeType;
|
+ (NSString*)mimeType;
|
||||||
|
|||||||
@ -37,6 +37,69 @@ enum {
|
|||||||
kParserState_End
|
kParserState_End
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@interface GCDWebServerRequest () {
|
||||||
|
@private
|
||||||
|
NSString* _method;
|
||||||
|
NSURL* _url;
|
||||||
|
NSDictionary* _headers;
|
||||||
|
NSString* _path;
|
||||||
|
NSDictionary* _query;
|
||||||
|
NSString* _type;
|
||||||
|
NSUInteger _length;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GCDWebServerDataRequest () {
|
||||||
|
@private
|
||||||
|
NSMutableData* _data;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GCDWebServerFileRequest () {
|
||||||
|
@private
|
||||||
|
NSString* _filePath;
|
||||||
|
int _file;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GCDWebServerMultiPart () {
|
||||||
|
@private
|
||||||
|
NSString* _contentType;
|
||||||
|
NSString* _mimeType;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GCDWebServerMultiPartArgument () {
|
||||||
|
@private
|
||||||
|
NSData* _data;
|
||||||
|
NSString* _string;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GCDWebServerMultiPartFile () {
|
||||||
|
@private
|
||||||
|
NSString* _fileName;
|
||||||
|
NSString* _temporaryPath;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GCDWebServerMultiPartFormRequest () {
|
||||||
|
@private
|
||||||
|
NSData* _boundary;
|
||||||
|
|
||||||
|
NSUInteger _parserState;
|
||||||
|
NSMutableData* _parserData;
|
||||||
|
NSString* _controlName;
|
||||||
|
NSString* _fileName;
|
||||||
|
NSString* _contentType;
|
||||||
|
NSString* _tmpPath;
|
||||||
|
int _tmpFile;
|
||||||
|
|
||||||
|
NSMutableDictionary* _arguments;
|
||||||
|
NSMutableDictionary* _files;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
static NSData* _newlineData = nil;
|
static NSData* _newlineData = nil;
|
||||||
static NSData* _newlinesData = nil;
|
static NSData* _newlinesData = nil;
|
||||||
static NSData* _dashNewlineData = nil;
|
static NSData* _dashNewlineData = nil;
|
||||||
|
|||||||
@ -27,14 +27,7 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
@interface GCDWebServerResponse : NSObject {
|
@interface GCDWebServerResponse : NSObject
|
||||||
@private
|
|
||||||
NSString* _type;
|
|
||||||
NSUInteger _length;
|
|
||||||
NSInteger _status;
|
|
||||||
NSUInteger _maxAge;
|
|
||||||
NSMutableDictionary* _headers;
|
|
||||||
}
|
|
||||||
@property(nonatomic, readonly) NSString* contentType;
|
@property(nonatomic, readonly) NSString* contentType;
|
||||||
@property(nonatomic, readonly) NSUInteger contentLength;
|
@property(nonatomic, readonly) NSUInteger contentLength;
|
||||||
@property(nonatomic) NSInteger statusCode; // Default is 200
|
@property(nonatomic) NSInteger statusCode; // Default is 200
|
||||||
@ -60,11 +53,7 @@
|
|||||||
- (id)initWithRedirect:(NSURL*)location permanent:(BOOL)permanent;
|
- (id)initWithRedirect:(NSURL*)location permanent:(BOOL)permanent;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerDataResponse : GCDWebServerResponse {
|
@interface GCDWebServerDataResponse : GCDWebServerResponse
|
||||||
@private
|
|
||||||
NSData* _data;
|
|
||||||
NSInteger _offset;
|
|
||||||
}
|
|
||||||
+ (GCDWebServerDataResponse*)responseWithData:(NSData*)data contentType:(NSString*)type;
|
+ (GCDWebServerDataResponse*)responseWithData:(NSData*)data contentType:(NSString*)type;
|
||||||
- (id)initWithData:(NSData*)data contentType:(NSString*)type;
|
- (id)initWithData:(NSData*)data contentType:(NSString*)type;
|
||||||
@end
|
@end
|
||||||
@ -78,11 +67,7 @@
|
|||||||
- (id)initWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables; // Simple template system that replaces all occurences of "%variable%" with corresponding value (encodes using UTF-8)
|
- (id)initWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables; // Simple template system that replaces all occurences of "%variable%" with corresponding value (encodes using UTF-8)
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerFileResponse : GCDWebServerResponse {
|
@interface GCDWebServerFileResponse : GCDWebServerResponse
|
||||||
@private
|
|
||||||
NSString* _path;
|
|
||||||
int _file;
|
|
||||||
}
|
|
||||||
+ (GCDWebServerFileResponse*)responseWithFile:(NSString*)path;
|
+ (GCDWebServerFileResponse*)responseWithFile:(NSString*)path;
|
||||||
+ (GCDWebServerFileResponse*)responseWithFile:(NSString*)path isAttachment:(BOOL)attachment;
|
+ (GCDWebServerFileResponse*)responseWithFile:(NSString*)path isAttachment:(BOOL)attachment;
|
||||||
- (id)initWithFile:(NSString*)path;
|
- (id)initWithFile:(NSString*)path;
|
||||||
|
|||||||
@ -29,6 +29,30 @@
|
|||||||
|
|
||||||
#import "GCDWebServerPrivate.h"
|
#import "GCDWebServerPrivate.h"
|
||||||
|
|
||||||
|
@interface GCDWebServerResponse () {
|
||||||
|
@private
|
||||||
|
NSString* _type;
|
||||||
|
NSUInteger _length;
|
||||||
|
NSInteger _status;
|
||||||
|
NSUInteger _maxAge;
|
||||||
|
NSMutableDictionary* _headers;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GCDWebServerDataResponse () {
|
||||||
|
@private
|
||||||
|
NSData* _data;
|
||||||
|
NSInteger _offset;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GCDWebServerFileResponse () {
|
||||||
|
@private
|
||||||
|
NSString* _path;
|
||||||
|
int _file;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation GCDWebServerResponse
|
@implementation GCDWebServerResponse
|
||||||
|
|
||||||
@synthesize contentType=_type, contentLength=_length, statusCode=_status, cacheControlMaxAge=_maxAge, additionalHeaders=_headers;
|
@synthesize contentType=_type, contentLength=_length, statusCode=_status, cacheControlMaxAge=_maxAge, additionalHeaders=_headers;
|
||||||
|
|||||||
Reference in New Issue
Block a user