Added types to collections
This commit is contained in:
@ -95,7 +95,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
*
|
*
|
||||||
* The default value is nil i.e. all file extensions are allowed.
|
* The default value is nil i.e. all file extensions are allowed.
|
||||||
*/
|
*/
|
||||||
@property(nonatomic, copy) NSArray* allowedFileExtensions;
|
@property(nonatomic, copy) NSArray<NSString*>* allowedFileExtensions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets if files and directories whose name start with a period are allowed to
|
* Sets if files and directories whose name start with a period are allowed to
|
||||||
|
|||||||
@ -42,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
* GCDWebServerRequest instance created with the same basic info.
|
* GCDWebServerRequest instance created with the same basic info.
|
||||||
* Otherwise, it simply returns nil.
|
* Otherwise, it simply returns nil.
|
||||||
*/
|
*/
|
||||||
typedef GCDWebServerRequest* _Nullable (^GCDWebServerMatchBlock)(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery);
|
typedef GCDWebServerRequest* _Nullable (^GCDWebServerMatchBlock)(NSString* requestMethod, NSURL* requestURL, NSDictionary<NSString*, NSString*>* requestHeaders, NSString* urlPath, NSDictionary<NSString*, NSString*>* urlQuery);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The GCDWebServerProcessBlock is called after the HTTP request has been fully
|
* The GCDWebServerProcessBlock is called after the HTTP request has been fully
|
||||||
@ -365,7 +365,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
|||||||
*
|
*
|
||||||
* Returns NO if the server failed to start and sets "error" argument if not NULL.
|
* Returns NO if the server failed to start and sets "error" argument if not NULL.
|
||||||
*/
|
*/
|
||||||
- (BOOL)startWithOptions:(nullable NSDictionary*)options error:(NSError** _Nullable)error;
|
- (BOOL)startWithOptions:(nullable NSDictionary<NSString*, id>*)options error:(NSError** _Nullable)error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the server and prevents it to accepts new HTTP requests.
|
* Stops the server and prevents it to accepts new HTTP requests.
|
||||||
@ -444,7 +444,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
|||||||
*
|
*
|
||||||
* @warning This method must be used from the main thread only.
|
* @warning This method must be used from the main thread only.
|
||||||
*/
|
*/
|
||||||
- (BOOL)runWithOptions:(nullable NSDictionary*)options error:(NSError** _Nullable)error;
|
- (BOOL)runWithOptions:(nullable NSDictionary<NSString*, id>*)options error:(NSError** _Nullable)error;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -613,7 +613,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
|||||||
*
|
*
|
||||||
* Returns the number of failed tests or -1 if server failed to start.
|
* Returns the number of failed tests or -1 if server failed to start.
|
||||||
*/
|
*/
|
||||||
- (NSInteger)runTestsWithOptions:(nullable NSDictionary*)options inDirectory:(NSString*)path;
|
- (NSInteger)runTestsWithOptions:(nullable NSDictionary<NSString*, id>*)options inDirectory:(NSString*)path;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@ -141,14 +141,14 @@ static void _ExecuteMainThreadRunLoopSources() {
|
|||||||
@implementation GCDWebServer {
|
@implementation GCDWebServer {
|
||||||
dispatch_queue_t _syncQueue;
|
dispatch_queue_t _syncQueue;
|
||||||
dispatch_group_t _sourceGroup;
|
dispatch_group_t _sourceGroup;
|
||||||
NSMutableArray* _handlers;
|
NSMutableArray<GCDWebServerHandler*>* _handlers;
|
||||||
NSInteger _activeConnections; // Accessed through _syncQueue only
|
NSInteger _activeConnections; // Accessed through _syncQueue only
|
||||||
BOOL _connected; // Accessed on main thread only
|
BOOL _connected; // Accessed on main thread only
|
||||||
CFRunLoopTimerRef _disconnectTimer; // Accessed on main thread only
|
CFRunLoopTimerRef _disconnectTimer; // Accessed on main thread only
|
||||||
|
|
||||||
NSDictionary* _options;
|
NSDictionary<NSString*, id>* _options;
|
||||||
NSMutableDictionary* _authenticationBasicAccounts;
|
NSMutableDictionary<NSString*, NSString*>* _authenticationBasicAccounts;
|
||||||
NSMutableDictionary* _authenticationDigestAccounts;
|
NSMutableDictionary<NSString*, NSString*>* _authenticationDigestAccounts;
|
||||||
Class _connectionClass;
|
Class _connectionClass;
|
||||||
CFTimeInterval _disconnectDelay;
|
CFTimeInterval _disconnectDelay;
|
||||||
dispatch_source_t _source4;
|
dispatch_source_t _source4;
|
||||||
@ -408,7 +408,7 @@ static void _SocketCallBack(CFSocketRef s, CFSocketCallBackType type, CFDataRef
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline id _GetOption(NSDictionary* options, NSString* key, id defaultValue) {
|
static inline id _GetOption(NSDictionary<NSString*, id>* options, NSString* key, id defaultValue) {
|
||||||
id value = [options objectForKey:key];
|
id value = [options objectForKey:key];
|
||||||
return value ? value : defaultValue;
|
return value ? value : defaultValue;
|
||||||
}
|
}
|
||||||
@ -721,7 +721,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
- (BOOL)startWithOptions:(NSDictionary*)options error:(NSError**)error {
|
- (BOOL)startWithOptions:(NSDictionary<NSString*, id>*)options error:(NSError**)error {
|
||||||
if (_options == nil) {
|
if (_options == nil) {
|
||||||
_options = options ? [options copy] : @{};
|
_options = options ? [options copy] : @{};
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
@ -832,7 +832,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
|||||||
return [self runWithOptions:options error:NULL];
|
return [self runWithOptions:options error:NULL];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)runWithOptions:(NSDictionary*)options error:(NSError**)error {
|
- (BOOL)runWithOptions:(NSDictionary<NSString*, id>*)options error:(NSError**)error {
|
||||||
GWS_DCHECK([NSThread isMainThread]);
|
GWS_DCHECK([NSThread isMainThread]);
|
||||||
BOOL success = NO;
|
BOOL success = NO;
|
||||||
_run = YES;
|
_run = YES;
|
||||||
@ -868,7 +868,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block {
|
- (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block {
|
||||||
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
|
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary<NSString*, NSString*>* requestHeaders, NSString* urlPath, NSDictionary<NSString*, NSString*>* urlQuery) {
|
||||||
if (![requestMethod isEqualToString:method]) {
|
if (![requestMethod isEqualToString:method]) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -888,7 +888,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
|||||||
|
|
||||||
- (void)addHandlerForMethod:(NSString*)method path:(NSString*)path requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block {
|
- (void)addHandlerForMethod:(NSString*)method path:(NSString*)path requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block {
|
||||||
if ([path hasPrefix:@"/"] && [aClass isSubclassOfClass:[GCDWebServerRequest class]]) {
|
if ([path hasPrefix:@"/"] && [aClass isSubclassOfClass:[GCDWebServerRequest class]]) {
|
||||||
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
|
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary<NSString*, NSString*>* requestHeaders, NSString* urlPath, NSDictionary<NSString*, NSString*>* urlQuery) {
|
||||||
if (![requestMethod isEqualToString:method]) {
|
if (![requestMethod isEqualToString:method]) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -915,7 +915,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
|||||||
- (void)addHandlerForMethod:(NSString*)method pathRegex:(NSString*)regex requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block {
|
- (void)addHandlerForMethod:(NSString*)method pathRegex:(NSString*)regex requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block {
|
||||||
NSRegularExpression* expression = [NSRegularExpression regularExpressionWithPattern:regex options:NSRegularExpressionCaseInsensitive error:NULL];
|
NSRegularExpression* expression = [NSRegularExpression regularExpressionWithPattern:regex options:NSRegularExpressionCaseInsensitive error:NULL];
|
||||||
if (expression && [aClass isSubclassOfClass:[GCDWebServerRequest class]]) {
|
if (expression && [aClass isSubclassOfClass:[GCDWebServerRequest class]]) {
|
||||||
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
|
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary<NSString*, NSString*>* requestHeaders, NSString* urlPath, NSDictionary<NSString*, NSString*>* urlQuery) {
|
||||||
if (![requestMethod isEqualToString:method]) {
|
if (![requestMethod isEqualToString:method]) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -1013,7 +1013,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
|||||||
- (void)addGETHandlerForBasePath:(NSString*)basePath directoryPath:(NSString*)directoryPath indexFilename:(NSString*)indexFilename cacheAge:(NSUInteger)cacheAge allowRangeRequests:(BOOL)allowRangeRequests {
|
- (void)addGETHandlerForBasePath:(NSString*)basePath directoryPath:(NSString*)directoryPath indexFilename:(NSString*)indexFilename cacheAge:(NSUInteger)cacheAge allowRangeRequests:(BOOL)allowRangeRequests {
|
||||||
if ([basePath hasPrefix:@"/"] && [basePath hasSuffix:@"/"]) {
|
if ([basePath hasPrefix:@"/"] && [basePath hasSuffix:@"/"]) {
|
||||||
GCDWebServer* __unsafe_unretained server = self;
|
GCDWebServer* __unsafe_unretained server = self;
|
||||||
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
|
[self addHandlerWithMatchBlock:^GCDWebServerRequest*(NSString* requestMethod, NSURL* requestURL, NSDictionary<NSString*, NSString*>* requestHeaders, NSString* urlPath, NSDictionary<NSString*, NSString*>* urlQuery) {
|
||||||
if (![requestMethod isEqualToString:@"GET"]) {
|
if (![requestMethod isEqualToString:@"GET"]) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@ -1168,7 +1168,7 @@ static void _LogResult(NSString* format, ...) {
|
|||||||
fprintf(stdout, "%s\n", [message UTF8String]);
|
fprintf(stdout, "%s\n", [message UTF8String]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger)runTestsWithOptions:(NSDictionary*)options inDirectory:(NSString*)path {
|
- (NSInteger)runTestsWithOptions:(NSDictionary<NSString*, id>*)options inDirectory:(NSString*)path {
|
||||||
GWS_DCHECK([NSThread isMainThread]);
|
GWS_DCHECK([NSThread isMainThread]);
|
||||||
NSArray* ignoredHeaders = @[ @"Date", @"Etag" ]; // Dates are always different by definition and ETags depend on file system node IDs
|
NSArray* ignoredHeaders = @[ @"Date", @"Etag" ]; // Dates are always different by definition and ETags depend on file system node IDs
|
||||||
NSInteger result = -1;
|
NSInteger result = -1;
|
||||||
|
|||||||
@ -130,7 +130,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
*
|
*
|
||||||
* The default implementation returns the original URL.
|
* The default implementation returns the original URL.
|
||||||
*/
|
*/
|
||||||
- (NSURL*)rewriteRequestURL:(NSURL*)url withMethod:(NSString*)method headers:(NSDictionary*)headers;
|
- (NSURL*)rewriteRequestURL:(NSURL*)url withMethod:(NSString*)method headers:(NSDictionary<NSString*, NSString*>*)headers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assuming a valid HTTP request was received, this method is called before
|
* Assuming a valid HTTP request was received, this method is called before
|
||||||
|
|||||||
@ -698,7 +698,7 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURL*)rewriteRequestURL:(NSURL*)url withMethod:(NSString*)method headers:(NSDictionary*)headers {
|
- (NSURL*)rewriteRequestURL:(NSURL*)url withMethod:(NSString*)method headers:(NSDictionary<NSString*, NSString*>*)headers {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,7 @@ extern "C" {
|
|||||||
* types. Keys of the dictionary must be lowercased file extensions without
|
* types. Keys of the dictionary must be lowercased file extensions without
|
||||||
* the period, and the values must be the corresponding MIME types.
|
* the period, and the values must be the corresponding MIME types.
|
||||||
*/
|
*/
|
||||||
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension, NSDictionary* _Nullable overrides);
|
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension, NSDictionary<NSString*, NSString*>* _Nullable overrides);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add percent-escapes to a string so it can be used in a URL.
|
* Add percent-escapes to a string so it can be used in a URL.
|
||||||
@ -60,7 +60,7 @@ NSString* _Nullable GCDWebServerUnescapeURLString(NSString* string);
|
|||||||
* "application/x-www-form-urlencoded" form.
|
* "application/x-www-form-urlencoded" form.
|
||||||
* http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
|
* http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
|
||||||
*/
|
*/
|
||||||
NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form);
|
NSDictionary<NSString*, NSString*>* GCDWebServerParseURLEncodedForm(NSString* form);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On OS X, returns the IPv4 or IPv6 address as a string of the primary
|
* On OS X, returns the IPv4 or IPv6 address as a string of the primary
|
||||||
|
|||||||
@ -166,7 +166,7 @@ NSString* GCDWebServerDescribeData(NSData* data, NSString* type) {
|
|||||||
return [NSString stringWithFormat:@"<%lu bytes>", (unsigned long)data.length];
|
return [NSString stringWithFormat:@"<%lu bytes>", (unsigned long)data.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension, NSDictionary* overrides) {
|
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension, NSDictionary<NSString*, NSString*>* overrides) {
|
||||||
NSDictionary* builtInOverrides = @{@"css" : @"text/css"};
|
NSDictionary* builtInOverrides = @{@"css" : @"text/css"};
|
||||||
NSString* mimeType = nil;
|
NSString* mimeType = nil;
|
||||||
extension = [extension lowercaseString];
|
extension = [extension lowercaseString];
|
||||||
@ -200,7 +200,7 @@ NSString* GCDWebServerUnescapeURLString(NSString* string) {
|
|||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form) {
|
NSDictionary<NSString*, NSString*>* GCDWebServerParseURLEncodedForm(NSString* form) {
|
||||||
NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
|
NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
|
||||||
NSScanner* scanner = [[NSScanner alloc] initWithString:form];
|
NSScanner* scanner = [[NSScanner alloc] initWithString:form];
|
||||||
[scanner setCharactersToBeSkipped:nil];
|
[scanner setCharactersToBeSkipped:nil];
|
||||||
|
|||||||
@ -185,11 +185,11 @@ extern NSString* GCDWebServerStringFromSockAddr(const struct sockaddr* addr, BOO
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServer ()
|
@interface GCDWebServer ()
|
||||||
@property(nonatomic, readonly) NSMutableArray* handlers;
|
@property(nonatomic, readonly) NSMutableArray<GCDWebServerHandler*>* handlers;
|
||||||
@property(nonatomic, readonly, nullable) NSString* serverName;
|
@property(nonatomic, readonly, nullable) NSString* serverName;
|
||||||
@property(nonatomic, readonly, nullable) NSString* authenticationRealm;
|
@property(nonatomic, readonly, nullable) NSString* authenticationRealm;
|
||||||
@property(nonatomic, readonly, nullable) NSMutableDictionary* authenticationBasicAccounts;
|
@property(nonatomic, readonly, nullable) NSMutableDictionary<NSString*, NSString*>* authenticationBasicAccounts;
|
||||||
@property(nonatomic, readonly, nullable) NSMutableDictionary* authenticationDigestAccounts;
|
@property(nonatomic, readonly, nullable) NSMutableDictionary<NSString*, NSString*>* authenticationDigestAccounts;
|
||||||
@property(nonatomic, readonly) BOOL shouldAutomaticallyMapHEADToGET;
|
@property(nonatomic, readonly) BOOL shouldAutomaticallyMapHEADToGET;
|
||||||
@property(nonatomic, readonly) dispatch_queue_priority_t dispatchQueuePriority;
|
@property(nonatomic, readonly) dispatch_queue_priority_t dispatchQueuePriority;
|
||||||
- (void)willStartConnection:(GCDWebServerConnection*)connection;
|
- (void)willStartConnection:(GCDWebServerConnection*)connection;
|
||||||
@ -213,7 +213,7 @@ extern NSString* GCDWebServerStringFromSockAddr(const struct sockaddr* addr, BOO
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerResponse ()
|
@interface GCDWebServerResponse ()
|
||||||
@property(nonatomic, readonly) NSDictionary* additionalHeaders;
|
@property(nonatomic, readonly) NSDictionary<NSString*, NSString*>* additionalHeaders;
|
||||||
@property(nonatomic, readonly) BOOL usesChunkedTransferEncoding;
|
@property(nonatomic, readonly) BOOL usesChunkedTransferEncoding;
|
||||||
- (void)prepareForReading;
|
- (void)prepareForReading;
|
||||||
- (BOOL)performOpen:(NSError**)error;
|
- (BOOL)performOpen:(NSError**)error;
|
||||||
|
|||||||
@ -102,7 +102,7 @@ extern NSString* const GCDWebServerRequestAttribute_RegexCaptures;
|
|||||||
/**
|
/**
|
||||||
* Returns the HTTP headers for the request.
|
* Returns the HTTP headers for the request.
|
||||||
*/
|
*/
|
||||||
@property(nonatomic, readonly) NSDictionary* headers;
|
@property(nonatomic, readonly) NSDictionary<NSString*, NSString*>* headers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the path component of the URL for the request.
|
* Returns the path component of the URL for the request.
|
||||||
@ -114,7 +114,7 @@ extern NSString* const GCDWebServerRequestAttribute_RegexCaptures;
|
|||||||
*
|
*
|
||||||
* @warning This property will be nil if there is no query in the URL.
|
* @warning This property will be nil if there is no query in the URL.
|
||||||
*/
|
*/
|
||||||
@property(nonatomic, readonly, nullable) NSDictionary* query;
|
@property(nonatomic, readonly, nullable) NSDictionary<NSString*, NSString*>* query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the content type for the body of the request parsed from the
|
* Returns the content type for the body of the request parsed from the
|
||||||
@ -186,7 +186,7 @@ extern NSString* const GCDWebServerRequestAttribute_RegexCaptures;
|
|||||||
/**
|
/**
|
||||||
* This method is the designated initializer for the class.
|
* This method is the designated initializer for the class.
|
||||||
*/
|
*/
|
||||||
- (instancetype)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(nullable NSDictionary*)query;
|
- (instancetype)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary<NSString*, NSString*>*)headers path:(NSString*)path query:(nullable NSDictionary<NSString*, NSString*>*)query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method that checks if the contentType property is defined.
|
* Convenience method that checks if the contentType property is defined.
|
||||||
|
|||||||
@ -136,12 +136,12 @@ NSString* const GCDWebServerRequestAttribute_RegexCaptures = @"GCDWebServerReque
|
|||||||
|
|
||||||
@implementation GCDWebServerRequest {
|
@implementation GCDWebServerRequest {
|
||||||
BOOL _opened;
|
BOOL _opened;
|
||||||
NSMutableArray* _decoders;
|
NSMutableArray<GCDWebServerBodyDecoder*>* _decoders;
|
||||||
id<GCDWebServerBodyWriter> __unsafe_unretained _writer;
|
id<GCDWebServerBodyWriter> __unsafe_unretained _writer;
|
||||||
NSMutableDictionary* _attributes;
|
NSMutableDictionary<NSString*, id>* _attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(NSDictionary*)query {
|
- (instancetype)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary<NSString*, NSString*>*)headers path:(NSString*)path query:(NSDictionary<NSString*, NSString*>*)query {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
_method = [method copy];
|
_method = [method copy];
|
||||||
_URL = url;
|
_URL = url;
|
||||||
|
|||||||
@ -150,7 +150,7 @@
|
|||||||
|
|
||||||
@implementation GCDWebServerResponse {
|
@implementation GCDWebServerResponse {
|
||||||
BOOL _opened;
|
BOOL _opened;
|
||||||
NSMutableArray* _encoders;
|
NSMutableArray<GCDWebServerBodyEncoder*>* _encoders;
|
||||||
id<GCDWebServerBodyReader> __unsafe_unretained _reader;
|
id<GCDWebServerBodyReader> __unsafe_unretained _reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,7 @@
|
|||||||
int _file;
|
int _file;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(NSDictionary*)query {
|
- (instancetype)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary<NSString*, NSString*>*)headers path:(NSString*)path query:(NSDictionary<NSString*, NSString*>*)query {
|
||||||
if ((self = [super initWithMethod:method url:url headers:headers path:path query:query])) {
|
if ((self = [super initWithMethod:method url:url headers:headers path:path query:query])) {
|
||||||
_temporaryPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]];
|
_temporaryPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -107,13 +107,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
* Returns the argument parts from the multipart encoded form as
|
* Returns the argument parts from the multipart encoded form as
|
||||||
* name / GCDWebServerMultiPartArgument pairs.
|
* name / GCDWebServerMultiPartArgument pairs.
|
||||||
*/
|
*/
|
||||||
@property(nonatomic, readonly) NSArray* arguments;
|
@property(nonatomic, readonly) NSArray<GCDWebServerMultiPartArgument*>* arguments;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the files parts from the multipart encoded form as
|
* Returns the files parts from the multipart encoded form as
|
||||||
* name / GCDWebServerMultiPartFile pairs.
|
* name / GCDWebServerMultiPartFile pairs.
|
||||||
*/
|
*/
|
||||||
@property(nonatomic, readonly) NSArray* files;
|
@property(nonatomic, readonly) NSArray<GCDWebServerMultiPartFile*>* files;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the MIME type for multipart encoded forms
|
* Returns the MIME type for multipart encoded forms
|
||||||
|
|||||||
@ -106,8 +106,8 @@ static NSData* _dashNewlineData = nil;
|
|||||||
NSString* _defaultcontrolName;
|
NSString* _defaultcontrolName;
|
||||||
ParserState _state;
|
ParserState _state;
|
||||||
NSMutableData* _data;
|
NSMutableData* _data;
|
||||||
NSMutableArray* _arguments;
|
NSMutableArray<GCDWebServerMultiPartArgument*>* _arguments;
|
||||||
NSMutableArray* _files;
|
NSMutableArray<GCDWebServerMultiPartFile*>* _files;
|
||||||
|
|
||||||
NSString* _controlName;
|
NSString* _controlName;
|
||||||
NSString* _fileName;
|
NSString* _fileName;
|
||||||
@ -132,7 +132,7 @@ static NSData* _dashNewlineData = nil;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithBoundary:(NSString* _Nonnull)boundary defaultControlName:(NSString* _Nullable)name arguments:(NSMutableArray* _Nonnull)arguments files:(NSMutableArray* _Nonnull)files {
|
- (instancetype)initWithBoundary:(NSString* _Nonnull)boundary defaultControlName:(NSString* _Nullable)name arguments:(NSMutableArray<GCDWebServerMultiPartArgument*>* _Nonnull)arguments files:(NSMutableArray<GCDWebServerMultiPartFile*>* _Nonnull)files {
|
||||||
NSData* data = boundary.length ? [[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSASCIIStringEncoding] : nil;
|
NSData* data = boundary.length ? [[NSString stringWithFormat:@"--%@", boundary] dataUsingEncoding:NSASCIIStringEncoding] : nil;
|
||||||
if (data == nil) {
|
if (data == nil) {
|
||||||
GWS_DNOT_REACHED();
|
GWS_DNOT_REACHED();
|
||||||
@ -312,8 +312,8 @@ static NSData* _dashNewlineData = nil;
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GCDWebServerMultiPartFormRequest ()
|
@interface GCDWebServerMultiPartFormRequest ()
|
||||||
@property(nonatomic) NSMutableArray* arguments;
|
@property(nonatomic) NSMutableArray<GCDWebServerMultiPartArgument*>* arguments;
|
||||||
@property(nonatomic) NSMutableArray* files;
|
@property(nonatomic) NSMutableArray<GCDWebServerMultiPartFile*>* files;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation GCDWebServerMultiPartFormRequest {
|
@implementation GCDWebServerMultiPartFormRequest {
|
||||||
@ -324,7 +324,7 @@ static NSData* _dashNewlineData = nil;
|
|||||||
return @"multipart/form-data";
|
return @"multipart/form-data";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(NSDictionary*)query {
|
- (instancetype)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary<NSString*, NSString*>*)headers path:(NSString*)path query:(NSDictionary<NSString*, NSString*>*)query {
|
||||||
if ((self = [super initWithMethod:method url:url headers:headers path:path query:query])) {
|
if ((self = [super initWithMethod:method url:url headers:headers path:path query:query])) {
|
||||||
_arguments = [[NSMutableArray alloc] init];
|
_arguments = [[NSMutableArray alloc] init];
|
||||||
_files = [[NSMutableArray alloc] init];
|
_files = [[NSMutableArray alloc] init];
|
||||||
|
|||||||
@ -42,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
* The text encoding used to interpret the data is extracted from the
|
* The text encoding used to interpret the data is extracted from the
|
||||||
* "Content-Type" header or defaults to UTF-8.
|
* "Content-Type" header or defaults to UTF-8.
|
||||||
*/
|
*/
|
||||||
@property(nonatomic, readonly) NSDictionary* arguments;
|
@property(nonatomic, readonly) NSDictionary<NSString*, NSString*>* arguments;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the MIME type for URL encoded forms
|
* Returns the MIME type for URL encoded forms
|
||||||
|
|||||||
@ -64,7 +64,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
* Creates a data response from an HTML template encoded using UTF-8.
|
* Creates a data response from an HTML template encoded using UTF-8.
|
||||||
* See -initWithHTMLTemplate:variables: for details.
|
* See -initWithHTMLTemplate:variables: for details.
|
||||||
*/
|
*/
|
||||||
+ (nullable instancetype)responseWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables;
|
+ (nullable instancetype)responseWithHTMLTemplate:(NSString*)path variables:(NSDictionary<NSString*, NSString*>*)variables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a data response from a serialized JSON object and the default
|
* Creates a data response from a serialized JSON object and the default
|
||||||
@ -94,7 +94,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
* All occurences of "%variable%" within the HTML template are replaced with
|
* All occurences of "%variable%" within the HTML template are replaced with
|
||||||
* their corresponding values.
|
* their corresponding values.
|
||||||
*/
|
*/
|
||||||
- (nullable instancetype)initWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables;
|
- (nullable instancetype)initWithHTMLTemplate:(NSString*)path variables:(NSDictionary<NSString*, NSString*>*)variables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a data response from a serialized JSON object and the default
|
* Initializes a data response from a serialized JSON object and the default
|
||||||
|
|||||||
@ -112,7 +112,7 @@
|
|||||||
return [self initWithData:data contentType:@"text/html; charset=utf-8"];
|
return [self initWithData:data contentType:@"text/html; charset=utf-8"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithHTMLTemplate:(NSString*)path variables:(NSDictionary*)variables {
|
- (instancetype)initWithHTMLTemplate:(NSString*)path variables:(NSDictionary<NSString*, NSString*>*)variables {
|
||||||
NSMutableString* html = [[NSMutableString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
|
NSMutableString* html = [[NSMutableString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
|
||||||
[variables enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSString* value, BOOL* stop) {
|
[variables enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSString* value, BOOL* stop) {
|
||||||
[html replaceOccurrencesOfString:[NSString stringWithFormat:@"%%%@%%", key] withString:value options:0 range:NSMakeRange(0, html.length)];
|
[html replaceOccurrencesOfString:[NSString stringWithFormat:@"%%%@%%", key] withString:value options:0 range:NSMakeRange(0, html.length)];
|
||||||
|
|||||||
@ -101,7 +101,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
* file extensions without the period, and the values must be the corresponding
|
* file extensions without the period, and the values must be the corresponding
|
||||||
* MIME types.
|
* MIME types.
|
||||||
*/
|
*/
|
||||||
- (nullable instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment mimeTypeOverrides:(nullable NSDictionary*)overrides;
|
- (nullable instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment mimeTypeOverrides:(nullable NSDictionary<NSString*, NSString*>*)overrides;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@ -76,7 +76,7 @@ static inline NSDate* _NSDateFromTimeSpec(const struct timespec* t) {
|
|||||||
return [NSDate dateWithTimeIntervalSince1970:((NSTimeInterval)t->tv_sec + (NSTimeInterval)t->tv_nsec / 1000000000.0)];
|
return [NSDate dateWithTimeIntervalSince1970:((NSTimeInterval)t->tv_sec + (NSTimeInterval)t->tv_nsec / 1000000000.0)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment mimeTypeOverrides:(NSDictionary*)overrides {
|
- (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment mimeTypeOverrides:(NSDictionary<NSString*, NSString*>*)overrides {
|
||||||
struct stat info;
|
struct stat info;
|
||||||
if (lstat([path fileSystemRepresentation], &info) || !(info.st_mode & S_IFREG)) {
|
if (lstat([path fileSystemRepresentation], &info) || !(info.st_mode & S_IFREG)) {
|
||||||
GWS_DNOT_REACHED();
|
GWS_DNOT_REACHED();
|
||||||
|
|||||||
@ -93,7 +93,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
*
|
*
|
||||||
* The default value is nil i.e. all file extensions are allowed.
|
* The default value is nil i.e. all file extensions are allowed.
|
||||||
*/
|
*/
|
||||||
@property(nonatomic, copy) NSArray* allowedFileExtensions;
|
@property(nonatomic, copy) NSArray<NSString*>* allowedFileExtensions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets if files and directories whose name start with a period are allowed to
|
* Sets if files and directories whose name start with a period are allowed to
|
||||||
|
|||||||
Reference in New Issue
Block a user