60 Commits
2.0 ... 2.2

Author SHA1 Message Date
Pierre-Olivier Latour
0b3f825f1a Bumped version 2014-04-17 01:04:55 -03:00
Pierre-Olivier Latour
6b9142642e Update README.md 2014-04-17 00:47:34 -03:00
Pierre-Olivier Latour
0a21059d25 Added support for background mode on iOS 2014-04-16 23:49:35 -03:00
Pierre-Olivier Latour
14acb7b323 Fix 2014-04-16 23:30:22 -03:00
Pierre-Olivier Latour
2f7f7b7b50 Fix 2014-04-16 01:50:17 -03:00
Pierre-Olivier Latour
998a47b099 Replaced GCDWebServer subclassing with explicit options 2014-04-16 01:29:52 -03:00
Pierre-Olivier Latour
2d8996b91e Added connected state to GCDWebServer 2014-04-16 00:57:41 -03:00
Pierre-Olivier Latour
c5ca0f7cee Added GCDWebServerDelegate 2014-04-16 00:57:41 -03:00
Pierre-Olivier Latour
05a704bcef Fix 2014-04-16 00:57:41 -03:00
Pierre-Olivier Latour
c170fb4fd3 Use strerror() consistently 2014-04-16 00:57:41 -03:00
Pierre-Olivier Latour
55a9abd506 Fix 2014-04-16 00:57:39 -03:00
Pierre-Olivier Latour
489c8c6236 Added +[GCDWebServer maxPendingConnections] 2014-04-16 00:57:14 -03:00
Pierre-Olivier Latour
9c73736225 Fix 2014-04-15 21:53:02 -03:00
Pierre-Olivier Latour
1f503aa3b6 Fix 2014-04-15 18:02:38 -03:00
Pierre-Olivier Latour
4eeeab7dc2 Build iOS app using iOS Simulator SDK on Travis CI 2014-04-15 17:57:42 -03:00
Pierre-Olivier Latour
813f124f6a Fix 2014-04-15 17:57:15 -03:00
Pierre-Olivier Latour
8fe66444ae Cleaned up connections read / write implementation 2014-04-15 17:46:43 -03:00
Pierre-Olivier Latour
e3efc065df Build iOS app as part of unit tests 2014-04-15 16:50:57 -03:00
Pierre-Olivier Latour
016153f900 Isolated all testing code with __GCDWEBSERVER_ENABLE_TESTING__ 2014-04-15 16:50:57 -03:00
Pierre-Olivier Latour
a55781e2c1 Changed -[GCDWebServerConnection open] to return a BOOL 2014-04-15 16:50:57 -03:00
Pierre-Olivier Latour
4fb5d67e9b Fixed broken iOS build with __GCDWEBSERVER_ENABLE_TESTING__ 2014-04-15 16:50:57 -03:00
Pierre-Olivier Latour
14e04b445f Fixes 2014-04-15 16:50:57 -03:00
Pierre-Olivier Latour
ad01c15dcd Update README.md 2014-04-15 01:28:46 -03:00
Pierre-Olivier Latour
bb0f62416e Update README.md 2014-04-15 01:24:31 -03:00
Pierre-Olivier Latour
14228834d6 Update README.md 2014-04-15 01:09:10 -03:00
Pierre-Olivier Latour
eb16566605 Update README.md 2014-04-15 01:08:19 -03:00
Pierre-Olivier Latour
06e0fc531d Fixes 2014-04-15 01:01:55 -03:00
Pierre-Olivier Latour
ea777865f3 Bumped version 2014-04-15 00:33:17 -03:00
Pierre-Olivier Latour
5842149d4b Fixed unit tests to work in any time zone 2014-04-15 00:29:56 -03:00
Pierre-Olivier Latour
46ee1a48d6 Fixed source folder name typo! 2014-04-15 00:13:31 -03:00
Pierre-Olivier Latour
c1b2b79b06 Update README.md 2014-04-15 00:04:56 -03:00
Pierre-Olivier Latour
41c56334d0 Update README.md 2014-04-15 00:02:42 -03:00
Pierre-Olivier Latour
2810086816 Update README.md 2014-04-14 23:59:07 -03:00
Pierre-Olivier Latour
c8cd771697 Make header parsing more robust 2014-04-14 19:08:08 -03:00
Pierre-Olivier Latour
252c38c42a Force preserve scrolling position 2014-04-14 18:45:31 -03:00
Pierre-Olivier Latour
cedeb88cb6 Bumped version 2014-04-14 18:37:35 -03:00
Pierre-Olivier Latour
854bbdc6b2 Disable table reloads while renaming 2014-04-14 18:34:26 -03:00
Pierre-Olivier Latour
b949187770 Use jquery data() instead of element attributes 2014-04-14 18:28:22 -03:00
Pierre-Olivier Latour
dafcb0d895 Enable Enter key for dialogs 2014-04-14 10:34:43 -03:00
Pierre-Olivier Latour
7bceb8132a Force overwrite of entire GCDWebUploader.bundle on build 2014-04-14 10:34:14 -03:00
Pierre-Olivier Latour
4c2ac12f7b Fix 2014-04-13 19:20:55 -03:00
Pierre-Olivier Latour
1d2efbbbc7 Update README.md 2014-04-12 09:12:48 -07:00
Pierre-Olivier Latour
91b832715a Organized source code in subfolders 2014-04-12 09:11:24 -07:00
Pierre-Olivier Latour
0852bf2d05 Moved functions to GCDWebServerFunctions.[h/m] 2014-04-12 09:07:09 -07:00
Pierre-Olivier Latour
eb29232842 #34 Added Travis CI integration 2014-04-11 23:37:45 -07:00
Pierre-Olivier Latour
3b1fa05046 Update .travis.yml 2014-04-11 23:31:28 -07:00
Pierre-Olivier Latour
4535c5d61a Update Run-Tests.sh 2014-04-11 23:29:40 -07:00
Pierre-Olivier Latour
ccd1eaa880 Create .travis.yml 2014-04-11 23:27:35 -07:00
Pierre-Olivier Latour
1b805c3951 Update GCDWebServerRequest.h 2014-04-11 23:19:09 -07:00
Pierre-Olivier Latour
2172872787 Update README.md 2014-04-11 23:17:57 -07:00
Pierre-Olivier Latour
894eacd517 Bumped version 2014-04-11 22:39:51 -07:00
Pierre-Olivier Latour
7a54bcbae5 #35 Finalized unit tests 2014-04-11 22:39:50 -07:00
Pierre-Olivier Latour
a28ac82ba2 #35 More work on unit tests 2014-04-11 22:39:50 -07:00
Pierre-Olivier Latour
c062d9d6d3 Use internal functions for date formatting in WebDAV 2014-04-11 22:39:50 -07:00
Pierre-Olivier Latour
bb32a721b6 Update README.md 2014-04-11 08:22:42 -07:00
Pierre-Olivier Latour
1b6e4f6491 #35 First pass at unit tests 2014-04-10 20:22:44 -07:00
Pierre-Olivier Latour
7b51023373 Fixed memory corruption under non-ARC 2014-04-10 20:19:37 -07:00
Pierre-Olivier Latour
f21c6ab667 Fix 2014-04-10 19:49:24 -07:00
Pierre-Olivier Latour
0dd6d8c5fc Fix memory leak 2014-04-10 15:28:40 -07:00
Pierre-Olivier Latour
d58b2122ed Improved CocoaPods integration 2014-04-10 14:37:55 -07:00
826 changed files with 11159 additions and 663 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
.DS_Store .DS_Store
xcuserdata xcuserdata
project.xcworkspace project.xcworkspace
Tests/Payload

2
.travis.yml Normal file
View File

@@ -0,0 +1,2 @@
language: objective-c
script: ./Run-Tests.sh

View File

@@ -29,14 +29,15 @@
@class GCDWebDAVServer; @class GCDWebDAVServer;
@protocol GCDWebDAVServerDelegate <NSObject> // These methods are always called on main thread
@protocol GCDWebDAVServerDelegate <GCDWebServerDelegate>
@optional @optional
- (void)davServer:(GCDWebDAVServer*)uploader didDownloadFileAtPath:(NSString*)path; - (void)davServer:(GCDWebDAVServer*)server didDownloadFileAtPath:(NSString*)path;
- (void)davServer:(GCDWebDAVServer*)uploader didUploadFileAtPath:(NSString*)path; - (void)davServer:(GCDWebDAVServer*)server didUploadFileAtPath:(NSString*)path;
- (void)davServer:(GCDWebDAVServer*)uploader didMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath; - (void)davServer:(GCDWebDAVServer*)server didMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath;
- (void)davServer:(GCDWebDAVServer*)uploader didCopyItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath; - (void)davServer:(GCDWebDAVServer*)server didCopyItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath;
- (void)davServer:(GCDWebDAVServer*)uploader didDeleteItemAtPath:(NSString*)path; - (void)davServer:(GCDWebDAVServer*)server didDeleteItemAtPath:(NSString*)path;
- (void)davServer:(GCDWebDAVServer*)uploader didCreateDirectoryAtPath:(NSString*)path; - (void)davServer:(GCDWebDAVServer*)server didCreateDirectoryAtPath:(NSString*)path;
@end @end
@interface GCDWebDAVServer : GCDWebServer @interface GCDWebDAVServer : GCDWebServer
@@ -47,6 +48,7 @@
- (instancetype)initWithUploadDirectory:(NSString*)path; - (instancetype)initWithUploadDirectory:(NSString*)path;
@end @end
// These methods can be called from any thread
@interface GCDWebDAVServer (Subclassing) @interface GCDWebDAVServer (Subclassing)
- (BOOL)shouldUploadFileAtPath:(NSString*)path withTemporaryFile:(NSString*)tempPath; // Default implementation returns YES - (BOOL)shouldUploadFileAtPath:(NSString*)path withTemporaryFile:(NSString*)tempPath; // Default implementation returns YES
- (BOOL)shouldMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath; // Default implementation returns YES - (BOOL)shouldMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath; // Default implementation returns YES

View File

@@ -32,6 +32,8 @@
#import "GCDWebDAVServer.h" #import "GCDWebDAVServer.h"
#import "GCDWebServerFunctions.h"
#import "GCDWebServerDataRequest.h" #import "GCDWebServerDataRequest.h"
#import "GCDWebServerFileRequest.h" #import "GCDWebServerFileRequest.h"
@@ -52,7 +54,6 @@ typedef NS_ENUM(NSInteger, DAVProperties) {
@interface GCDWebDAVServer () { @interface GCDWebDAVServer () {
@private @private
NSString* _uploadDirectory; NSString* _uploadDirectory;
id<GCDWebDAVServerDelegate> __unsafe_unretained _delegate;
NSArray* _allowedExtensions; NSArray* _allowedExtensions;
BOOL _showHidden; BOOL _showHidden;
} }
@@ -100,9 +101,9 @@ static inline BOOL _IsMacFinder(GCDWebServerRequest* request) {
return [GCDWebServerResponse response]; return [GCDWebServerResponse response];
} }
if ([_delegate respondsToSelector:@selector(davServer:didDownloadFileAtPath:)]) { if ([self.delegate respondsToSelector:@selector(davServer:didDownloadFileAtPath:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate davServer:self didDownloadFileAtPath:absolutePath]; [self.delegate davServer:self didDownloadFileAtPath:absolutePath];
}); });
} }
return [GCDWebServerFileResponse responseWithFile:absolutePath]; return [GCDWebServerFileResponse responseWithFile:absolutePath];
@@ -143,9 +144,9 @@ static inline BOOL _IsMacFinder(GCDWebServerRequest* request) {
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed moving uploaded file to \"%@\"", relativePath]; return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed moving uploaded file to \"%@\"", relativePath];
} }
if ([_delegate respondsToSelector:@selector(davServer:didUploadFileAtPath:)]) { if ([self.delegate respondsToSelector:@selector(davServer:didUploadFileAtPath:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate davServer:self didUploadFileAtPath:absolutePath]; [self.delegate davServer:self didUploadFileAtPath:absolutePath];
}); });
} }
return [GCDWebServerResponse responseWithStatusCode:(existing ? kGCDWebServerHTTPStatusCode_NoContent : kGCDWebServerHTTPStatusCode_Created)]; return [GCDWebServerResponse responseWithStatusCode:(existing ? kGCDWebServerHTTPStatusCode_NoContent : kGCDWebServerHTTPStatusCode_Created)];
@@ -178,9 +179,9 @@ static inline BOOL _IsMacFinder(GCDWebServerRequest* request) {
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed deleting \"%@\"", relativePath]; return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed deleting \"%@\"", relativePath];
} }
if ([_delegate respondsToSelector:@selector(davServer:didDeleteItemAtPath:)]) { if ([self.delegate respondsToSelector:@selector(davServer:didDeleteItemAtPath:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate davServer:self didDeleteItemAtPath:absolutePath]; [self.delegate davServer:self didDeleteItemAtPath:absolutePath];
}); });
} }
return [GCDWebServerResponse responseWithStatusCode:kGCDWebServerHTTPStatusCode_NoContent]; return [GCDWebServerResponse responseWithStatusCode:kGCDWebServerHTTPStatusCode_NoContent];
@@ -214,10 +215,19 @@ static inline BOOL _IsMacFinder(GCDWebServerRequest* request) {
if (![[NSFileManager defaultManager] createDirectoryAtPath:absolutePath withIntermediateDirectories:NO attributes:nil error:&error]) { if (![[NSFileManager defaultManager] createDirectoryAtPath:absolutePath withIntermediateDirectories:NO attributes:nil error:&error]) {
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed creating directory \"%@\"", relativePath]; return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed creating directory \"%@\"", relativePath];
} }
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
NSString* creationDateHeader = [request.headers objectForKey:@"X-GCDWebServer-CreationDate"];
if (creationDateHeader) {
NSDate* date = GCDWebServerParseISO8601(creationDateHeader);
if (!date || ![[NSFileManager defaultManager] setAttributes:@{NSFileCreationDate: date} ofItemAtPath:absolutePath error:&error]) {
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed setting creation date for directory \"%@\"", relativePath];
}
}
#endif
if ([_delegate respondsToSelector:@selector(davServer:didCreateDirectoryAtPath:)]) { if ([self.delegate respondsToSelector:@selector(davServer:didCreateDirectoryAtPath:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate davServer:self didCreateDirectoryAtPath:absolutePath]; [self.delegate davServer:self didCreateDirectoryAtPath:absolutePath];
}); });
} }
return [GCDWebServerResponse responseWithStatusCode:kGCDWebServerHTTPStatusCode_Created]; return [GCDWebServerResponse responseWithStatusCode:kGCDWebServerHTTPStatusCode_Created];
@@ -287,15 +297,15 @@ static inline BOOL _IsMacFinder(GCDWebServerRequest* request) {
} }
if (isMove) { if (isMove) {
if ([_delegate respondsToSelector:@selector(davServer:didMoveItemFromPath:toPath:)]) { if ([self.delegate respondsToSelector:@selector(davServer:didMoveItemFromPath:toPath:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate davServer:self didMoveItemFromPath:srcAbsolutePath toPath:dstAbsolutePath]; [self.delegate davServer:self didMoveItemFromPath:srcAbsolutePath toPath:dstAbsolutePath];
}); });
} }
} else { } else {
if ([_delegate respondsToSelector:@selector(davServer:didCopyItemFromPath:toPath:)]) { if ([self.delegate respondsToSelector:@selector(davServer:didCopyItemFromPath:toPath:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate davServer:self didCopyItemFromPath:srcAbsolutePath toPath:dstAbsolutePath]; [self.delegate davServer:self didCopyItemFromPath:srcAbsolutePath toPath:dstAbsolutePath];
}); });
} }
} }
@@ -335,19 +345,11 @@ static inline xmlNodePtr _XMLChildWithName(xmlNodePtr child, const xmlChar* name
} }
if ((properties & kDAVProperty_CreationDate) && [attributes objectForKey:NSFileCreationDate]) { if ((properties & kDAVProperty_CreationDate) && [attributes objectForKey:NSFileCreationDate]) {
NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; [xmlString appendFormat:@"<D:creationdate>%@</D:creationdate>", GCDWebServerFormatISO8601([attributes fileCreationDate])];
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
formatter.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'+00:00'";
[xmlString appendFormat:@"<D:creationdate>%@</D:creationdate>", [formatter stringFromDate:[attributes fileCreationDate]]];
} }
if ((properties & kDAVProperty_LastModified) && [attributes objectForKey:NSFileModificationDate]) { if ((properties & kDAVProperty_LastModified) && isFile && [attributes objectForKey:NSFileModificationDate]) { // Last modification date is not useful for directories as it changes implicitely and 'Last-Modified' header is not provided for directories anyway
NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; [xmlString appendFormat:@"<D:getlastmodified>%@</D:getlastmodified>", GCDWebServerFormatRFC822([attributes fileModificationDate])];
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
formatter.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
formatter.dateFormat = @"EEE', 'd' 'MMM' 'yyyy' 'HH:mm:ss' GMT'";
[xmlString appendFormat:@"<D:getlastmodified>%@</D:getlastmodified>", [formatter stringFromDate:[attributes fileModificationDate]]];
} }
if ((properties & kDAVProperty_ContentLength) && !isDirectory && [attributes objectForKey:NSFileSize]) { if ((properties & kDAVProperty_ContentLength) && !isDirectory && [attributes objectForKey:NSFileSize]) {
@@ -360,6 +362,8 @@ static inline xmlNodePtr _XMLChildWithName(xmlNodePtr child, const xmlChar* name
[xmlString appendString:@"</D:response>\n"]; [xmlString appendString:@"</D:response>\n"];
} }
CFRelease(escapedPath); CFRelease(escapedPath);
} else {
[self logError:@"Failed escaping path: %@", itemPath];
} }
} }
@@ -409,10 +413,10 @@ static inline xmlNodePtr _XMLChildWithName(xmlNodePtr child, const xmlChar* name
} }
if (!success) { if (!success) {
NSString* string = [[NSString alloc] initWithData:request.data encoding:NSUTF8StringEncoding]; NSString* string = [[NSString alloc] initWithData:request.data encoding:NSUTF8StringEncoding];
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_BadRequest message:@"Invalid DAV properties:\n%@", string];
#if !__has_feature(objc_arc) #if !__has_feature(objc_arc)
[string release]; [string autorelease];
#endif #endif
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_BadRequest message:@"Invalid DAV properties:\n%@", string];
} }
} else { } else {
properties = kDAVAllProperties; properties = kDAVAllProperties;
@@ -510,10 +514,10 @@ static inline xmlNodePtr _XMLChildWithName(xmlNodePtr child, const xmlChar* name
} }
if (!success) { if (!success) {
NSString* string = [[NSString alloc] initWithData:request.data encoding:NSUTF8StringEncoding]; NSString* string = [[NSString alloc] initWithData:request.data encoding:NSUTF8StringEncoding];
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_BadRequest message:@"Invalid DAV properties:\n%@", string];
#if !__has_feature(objc_arc) #if !__has_feature(objc_arc)
[string release]; [string autorelease];
#endif #endif
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_BadRequest message:@"Invalid DAV properties:\n%@", string];
} }
if (![scope isEqualToString:@"exclusive"] || ![type isEqualToString:@"write"] || ![depthHeader isEqualToString:@"0"]) { if (![scope isEqualToString:@"exclusive"] || ![type isEqualToString:@"write"] || ![depthHeader isEqualToString:@"0"]) {
@@ -525,6 +529,12 @@ static inline xmlNodePtr _XMLChildWithName(xmlNodePtr child, const xmlChar* name
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Locking item name \"%@\" is not allowed", itemName]; return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Locking item name \"%@\" is not allowed", itemName];
} }
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
NSString* lockTokenHeader = [request.headers objectForKey:@"X-GCDWebServer-LockToken"];
if (lockTokenHeader) {
token = lockTokenHeader;
}
#endif
if (!token) { if (!token) {
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef string = CFUUIDCreateString(kCFAllocatorDefault, uuid); CFStringRef string = CFUUIDCreateString(kCFAllocatorDefault, uuid);
@@ -587,7 +597,7 @@ static inline xmlNodePtr _XMLChildWithName(xmlNodePtr child, const xmlChar* name
@implementation GCDWebDAVServer @implementation GCDWebDAVServer
@synthesize uploadDirectory=_uploadDirectory, delegate=_delegate, allowedFileExtensions=_allowedExtensions, showHiddenFiles=_showHidden; @synthesize uploadDirectory=_uploadDirectory, allowedFileExtensions=_allowedExtensions, showHiddenFiles=_showHidden;
- (instancetype)initWithUploadDirectory:(NSString*)path { - (instancetype)initWithUploadDirectory:(NSString*)path {
if ((self = [super init])) { if ((self = [super init])) {

47
GCDWebServer.podspec Normal file
View File

@@ -0,0 +1,47 @@
# http://guides.cocoapods.org/syntax/podspec.html
# Verify Podspec with:
# sudo gem update cocoapods
# pod spec lint GCDWebServer.podspec --verbose
# Add to source line:
# :tag => s.version.to_s
Pod::Spec.new do |s|
s.name = 'GCDWebServer'
s.version = '2.2'
s.author = { 'Pierre-Olivier Latour' => 'info@pol-online.net' }
s.license = { :type => 'BSD', :file => 'LICENSE' }
s.homepage = 'https://github.com/swisspol/GCDWebServer'
s.summary = 'Lightweight GCD based HTTP server for OS X & iOS (includes web based uploader & WebDAV server)'
s.source = { :git => 'https://github.com/swisspol/GCDWebServer.git' }
s.ios.deployment_target = '5.0'
s.osx.deployment_target = '10.7'
s.requires_arc = true
s.default_subspec = 'Core'
s.subspec 'Core' do |cs|
cs.source_files = 'GCDWebServer/**/*.{h,m}'
cs.requires_arc = true
cs.ios.library = 'z'
cs.osx.library = 'z'
cs.compiler_flags = '-DNDEBUG' # TODO: Only set this for Release configuration
end
s.subspec 'WebDAV' do |cs|
cs.dependency 'GCDWebServer/Core'
cs.source_files = 'GCDWebDAVServer/*.{h,m}'
cs.requires_arc = true
cs.ios.library = 'xml2'
cs.osx.library = 'xml2'
cs.compiler_flags = '-I$(SDKROOT)/usr/include/libxml2'
end
s.subspec 'WebUploader' do |cs|
cs.dependency 'GCDWebServer/Core'
cs.source_files = 'GCDWebUploader/*.{h,m}'
cs.requires_arc = true
cs.resource = "GCDWebUploader/GCDWebUploader.bundle"
end
end

View File

@@ -24,36 +24,38 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
E208D149167B76B700500836 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E208D148167B76B700500836 /* CFNetwork.framework */; }; E208D149167B76B700500836 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E208D148167B76B700500836 /* CFNetwork.framework */; };
E208D1B3167BB17E00500836 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E208D1B2167BB17E00500836 /* CoreServices.framework */; }; E208D1B3167BB17E00500836 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E208D1B2167BB17E00500836 /* CoreServices.framework */; };
E22112851690B63A0048D2B2 /* GCDWebServer.m in Sources */ = {isa = PBXBuildFile; fileRef = E221127D1690B63A0048D2B2 /* GCDWebServer.m */; };
E22112861690B63A0048D2B2 /* GCDWebServer.m in Sources */ = {isa = PBXBuildFile; fileRef = E221127D1690B63A0048D2B2 /* GCDWebServer.m */; };
E22112871690B63A0048D2B2 /* GCDWebServerConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = E221127F1690B63A0048D2B2 /* GCDWebServerConnection.m */; };
E22112881690B63A0048D2B2 /* GCDWebServerConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = E221127F1690B63A0048D2B2 /* GCDWebServerConnection.m */; };
E22112891690B63A0048D2B2 /* GCDWebServerRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E22112821690B63A0048D2B2 /* GCDWebServerRequest.m */; };
E221128A1690B63A0048D2B2 /* GCDWebServerRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E22112821690B63A0048D2B2 /* GCDWebServerRequest.m */; };
E221128B1690B63A0048D2B2 /* GCDWebServerResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E22112841690B63A0048D2B2 /* GCDWebServerResponse.m */; };
E221128C1690B63A0048D2B2 /* GCDWebServerResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E22112841690B63A0048D2B2 /* GCDWebServerResponse.m */; };
E221128F1690B6470048D2B2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E221128E1690B6470048D2B2 /* main.m */; }; E221128F1690B6470048D2B2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E221128E1690B6470048D2B2 /* main.m */; };
E22112951690B64F0048D2B2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E22112921690B64F0048D2B2 /* AppDelegate.m */; }; E22112951690B64F0048D2B2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E22112921690B64F0048D2B2 /* AppDelegate.m */; };
E22112971690B64F0048D2B2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E22112941690B64F0048D2B2 /* main.m */; }; E22112971690B64F0048D2B2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E22112941690B64F0048D2B2 /* main.m */; };
E22112991690B7AA0048D2B2 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E22112981690B7AA0048D2B2 /* CFNetwork.framework */; }; E22112991690B7AA0048D2B2 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E22112981690B7AA0048D2B2 /* CFNetwork.framework */; };
E221129B1690B7B10048D2B2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E221129A1690B7B10048D2B2 /* UIKit.framework */; }; E221129B1690B7B10048D2B2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E221129A1690B7B10048D2B2 /* UIKit.framework */; };
E221129D1690B7BA0048D2B2 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E221129C1690B7BA0048D2B2 /* MobileCoreServices.framework */; }; E221129D1690B7BA0048D2B2 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E221129C1690B7BA0048D2B2 /* MobileCoreServices.framework */; };
E276647C18F3BC2100A034BA /* GCDWebServerErrorResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E276647B18F3BC2100A034BA /* GCDWebServerErrorResponse.m */; }; E28BAE3418F99C810095C089 /* GCDWebServer.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1718F99C810095C089 /* GCDWebServer.m */; };
E276647D18F3BC2100A034BA /* GCDWebServerErrorResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E276647B18F3BC2100A034BA /* GCDWebServerErrorResponse.m */; }; E28BAE3518F99C810095C089 /* GCDWebServer.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1718F99C810095C089 /* GCDWebServer.m */; };
E2A0E7ED18F1D03700C580B1 /* GCDWebServerDataResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E7EC18F1D03700C580B1 /* GCDWebServerDataResponse.m */; }; E28BAE3618F99C810095C089 /* GCDWebServerConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1918F99C810095C089 /* GCDWebServerConnection.m */; };
E2A0E7EE18F1D03700C580B1 /* GCDWebServerDataResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E7EC18F1D03700C580B1 /* GCDWebServerDataResponse.m */; }; E28BAE3718F99C810095C089 /* GCDWebServerConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1918F99C810095C089 /* GCDWebServerConnection.m */; };
E2A0E7F118F1D12E00C580B1 /* GCDWebServerFileResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E7F018F1D12E00C580B1 /* GCDWebServerFileResponse.m */; }; E28BAE3818F99C810095C089 /* GCDWebServerFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1B18F99C810095C089 /* GCDWebServerFunctions.m */; };
E2A0E7F218F1D12E00C580B1 /* GCDWebServerFileResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E7F018F1D12E00C580B1 /* GCDWebServerFileResponse.m */; }; E28BAE3918F99C810095C089 /* GCDWebServerFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1B18F99C810095C089 /* GCDWebServerFunctions.m */; };
E2A0E7F518F1D1E500C580B1 /* GCDWebServerStreamingResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E7F418F1D1E500C580B1 /* GCDWebServerStreamingResponse.m */; }; E28BAE3A18F99C810095C089 /* GCDWebServerRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1F18F99C810095C089 /* GCDWebServerRequest.m */; };
E2A0E7F618F1D1E500C580B1 /* GCDWebServerStreamingResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E7F418F1D1E500C580B1 /* GCDWebServerStreamingResponse.m */; }; E28BAE3B18F99C810095C089 /* GCDWebServerRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE1F18F99C810095C089 /* GCDWebServerRequest.m */; };
E2A0E7F918F1D24700C580B1 /* GCDWebServerDataRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E7F818F1D24700C580B1 /* GCDWebServerDataRequest.m */; }; E28BAE3C18F99C810095C089 /* GCDWebServerResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2118F99C810095C089 /* GCDWebServerResponse.m */; };
E2A0E7FA18F1D24700C580B1 /* GCDWebServerDataRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E7F818F1D24700C580B1 /* GCDWebServerDataRequest.m */; }; E28BAE3D18F99C810095C089 /* GCDWebServerResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2118F99C810095C089 /* GCDWebServerResponse.m */; };
E2A0E7FD18F1D36C00C580B1 /* GCDWebServerFileRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E7FC18F1D36C00C580B1 /* GCDWebServerFileRequest.m */; }; E28BAE3E18F99C810095C089 /* GCDWebServerDataRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2418F99C810095C089 /* GCDWebServerDataRequest.m */; };
E2A0E7FE18F1D36C00C580B1 /* GCDWebServerFileRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E7FC18F1D36C00C580B1 /* GCDWebServerFileRequest.m */; }; E28BAE3F18F99C810095C089 /* GCDWebServerDataRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2418F99C810095C089 /* GCDWebServerDataRequest.m */; };
E2A0E80118F1D3DE00C580B1 /* GCDWebServerMultiPartFormRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E80018F1D3DE00C580B1 /* GCDWebServerMultiPartFormRequest.m */; }; E28BAE4018F99C810095C089 /* GCDWebServerFileRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2618F99C810095C089 /* GCDWebServerFileRequest.m */; };
E2A0E80218F1D3DE00C580B1 /* GCDWebServerMultiPartFormRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E80018F1D3DE00C580B1 /* GCDWebServerMultiPartFormRequest.m */; }; E28BAE4118F99C810095C089 /* GCDWebServerFileRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2618F99C810095C089 /* GCDWebServerFileRequest.m */; };
E2A0E80518F1D4A700C580B1 /* GCDWebServerURLEncodedFormRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E80418F1D4A700C580B1 /* GCDWebServerURLEncodedFormRequest.m */; }; E28BAE4218F99C810095C089 /* GCDWebServerMultiPartFormRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2818F99C810095C089 /* GCDWebServerMultiPartFormRequest.m */; };
E2A0E80618F1D4A700C580B1 /* GCDWebServerURLEncodedFormRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E80418F1D4A700C580B1 /* GCDWebServerURLEncodedFormRequest.m */; }; E28BAE4318F99C810095C089 /* GCDWebServerMultiPartFormRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2818F99C810095C089 /* GCDWebServerMultiPartFormRequest.m */; };
E28BAE4418F99C810095C089 /* GCDWebServerURLEncodedFormRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2A18F99C810095C089 /* GCDWebServerURLEncodedFormRequest.m */; };
E28BAE4518F99C810095C089 /* GCDWebServerURLEncodedFormRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2A18F99C810095C089 /* GCDWebServerURLEncodedFormRequest.m */; };
E28BAE4618F99C810095C089 /* GCDWebServerDataResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2D18F99C810095C089 /* GCDWebServerDataResponse.m */; };
E28BAE4718F99C810095C089 /* GCDWebServerDataResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2D18F99C810095C089 /* GCDWebServerDataResponse.m */; };
E28BAE4818F99C810095C089 /* GCDWebServerErrorResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2F18F99C810095C089 /* GCDWebServerErrorResponse.m */; };
E28BAE4918F99C810095C089 /* GCDWebServerErrorResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE2F18F99C810095C089 /* GCDWebServerErrorResponse.m */; };
E28BAE4A18F99C810095C089 /* GCDWebServerFileResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE3118F99C810095C089 /* GCDWebServerFileResponse.m */; };
E28BAE4B18F99C810095C089 /* GCDWebServerFileResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE3118F99C810095C089 /* GCDWebServerFileResponse.m */; };
E28BAE4C18F99C810095C089 /* GCDWebServerStreamingResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE3318F99C810095C089 /* GCDWebServerStreamingResponse.m */; };
E28BAE4D18F99C810095C089 /* GCDWebServerStreamingResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE3318F99C810095C089 /* GCDWebServerStreamingResponse.m */; };
E2A0E80A18F3432600C580B1 /* GCDWebDAVServer.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E80918F3432600C580B1 /* GCDWebDAVServer.m */; }; E2A0E80A18F3432600C580B1 /* GCDWebDAVServer.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E80918F3432600C580B1 /* GCDWebDAVServer.m */; };
E2A0E80B18F3432600C580B1 /* GCDWebDAVServer.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E80918F3432600C580B1 /* GCDWebDAVServer.m */; }; E2A0E80B18F3432600C580B1 /* GCDWebDAVServer.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E80918F3432600C580B1 /* GCDWebDAVServer.m */; };
E2A0E80D18F35C9A00C580B1 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E2A0E80C18F35C9A00C580B1 /* libxml2.dylib */; }; E2A0E80D18F35C9A00C580B1 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E2A0E80C18F35C9A00C580B1 /* libxml2.dylib */; };
@@ -102,15 +104,6 @@
E208D148167B76B700500836 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; E208D148167B76B700500836 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
E208D1B2167BB17E00500836 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; }; E208D1B2167BB17E00500836 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
E221125A1690B4DE0048D2B2 /* GCDWebServer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GCDWebServer.app; sourceTree = BUILT_PRODUCTS_DIR; }; E221125A1690B4DE0048D2B2 /* GCDWebServer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GCDWebServer.app; sourceTree = BUILT_PRODUCTS_DIR; };
E221127C1690B63A0048D2B2 /* GCDWebServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServer.h; sourceTree = "<group>"; };
E221127D1690B63A0048D2B2 /* GCDWebServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServer.m; sourceTree = "<group>"; };
E221127E1690B63A0048D2B2 /* GCDWebServerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerConnection.h; sourceTree = "<group>"; };
E221127F1690B63A0048D2B2 /* GCDWebServerConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerConnection.m; sourceTree = "<group>"; };
E22112801690B63A0048D2B2 /* GCDWebServerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerPrivate.h; sourceTree = "<group>"; };
E22112811690B63A0048D2B2 /* GCDWebServerRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerRequest.h; sourceTree = "<group>"; };
E22112821690B63A0048D2B2 /* GCDWebServerRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerRequest.m; sourceTree = "<group>"; };
E22112831690B63A0048D2B2 /* GCDWebServerResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerResponse.h; sourceTree = "<group>"; };
E22112841690B63A0048D2B2 /* GCDWebServerResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerResponse.m; sourceTree = "<group>"; };
E221128E1690B6470048D2B2 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; E221128E1690B6470048D2B2 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
E22112911690B64F0048D2B2 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; }; E22112911690B64F0048D2B2 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
E22112921690B64F0048D2B2 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; }; E22112921690B64F0048D2B2 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -119,27 +112,38 @@
E22112981690B7AA0048D2B2 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/CFNetwork.framework; sourceTree = DEVELOPER_DIR; }; E22112981690B7AA0048D2B2 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/CFNetwork.framework; sourceTree = DEVELOPER_DIR; };
E221129A1690B7B10048D2B2 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; E221129A1690B7B10048D2B2 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
E221129C1690B7BA0048D2B2 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/MobileCoreServices.framework; sourceTree = DEVELOPER_DIR; }; E221129C1690B7BA0048D2B2 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/MobileCoreServices.framework; sourceTree = DEVELOPER_DIR; };
E276647A18F3BC2100A034BA /* GCDWebServerErrorResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerErrorResponse.h; sourceTree = "<group>"; }; E28BAE1618F99C810095C089 /* GCDWebServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServer.h; sourceTree = "<group>"; };
E276647B18F3BC2100A034BA /* GCDWebServerErrorResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerErrorResponse.m; sourceTree = "<group>"; }; E28BAE1718F99C810095C089 /* GCDWebServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServer.m; sourceTree = "<group>"; };
E2A0E7EB18F1D03700C580B1 /* GCDWebServerDataResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerDataResponse.h; sourceTree = "<group>"; }; E28BAE1818F99C810095C089 /* GCDWebServerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerConnection.h; sourceTree = "<group>"; };
E2A0E7EC18F1D03700C580B1 /* GCDWebServerDataResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerDataResponse.m; sourceTree = "<group>"; }; E28BAE1918F99C810095C089 /* GCDWebServerConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerConnection.m; sourceTree = "<group>"; };
E2A0E7EF18F1D12E00C580B1 /* GCDWebServerFileResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerFileResponse.h; sourceTree = "<group>"; }; E28BAE1A18F99C810095C089 /* GCDWebServerFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerFunctions.h; sourceTree = "<group>"; };
E2A0E7F018F1D12E00C580B1 /* GCDWebServerFileResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerFileResponse.m; sourceTree = "<group>"; }; E28BAE1B18F99C810095C089 /* GCDWebServerFunctions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerFunctions.m; sourceTree = "<group>"; };
E2A0E7F318F1D1E500C580B1 /* GCDWebServerStreamingResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerStreamingResponse.h; sourceTree = "<group>"; }; E28BAE1C18F99C810095C089 /* GCDWebServerHTTPStatusCodes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerHTTPStatusCodes.h; sourceTree = "<group>"; };
E2A0E7F418F1D1E500C580B1 /* GCDWebServerStreamingResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerStreamingResponse.m; sourceTree = "<group>"; }; E28BAE1D18F99C810095C089 /* GCDWebServerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerPrivate.h; sourceTree = "<group>"; };
E2A0E7F718F1D24700C580B1 /* GCDWebServerDataRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerDataRequest.h; sourceTree = "<group>"; }; E28BAE1E18F99C810095C089 /* GCDWebServerRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerRequest.h; sourceTree = "<group>"; };
E2A0E7F818F1D24700C580B1 /* GCDWebServerDataRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerDataRequest.m; sourceTree = "<group>"; }; E28BAE1F18F99C810095C089 /* GCDWebServerRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerRequest.m; sourceTree = "<group>"; };
E2A0E7FB18F1D36C00C580B1 /* GCDWebServerFileRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerFileRequest.h; sourceTree = "<group>"; }; E28BAE2018F99C810095C089 /* GCDWebServerResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerResponse.h; sourceTree = "<group>"; };
E2A0E7FC18F1D36C00C580B1 /* GCDWebServerFileRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerFileRequest.m; sourceTree = "<group>"; }; E28BAE2118F99C810095C089 /* GCDWebServerResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerResponse.m; sourceTree = "<group>"; };
E2A0E7FF18F1D3DE00C580B1 /* GCDWebServerMultiPartFormRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerMultiPartFormRequest.h; sourceTree = "<group>"; }; E28BAE2318F99C810095C089 /* GCDWebServerDataRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerDataRequest.h; sourceTree = "<group>"; };
E2A0E80018F1D3DE00C580B1 /* GCDWebServerMultiPartFormRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerMultiPartFormRequest.m; sourceTree = "<group>"; }; E28BAE2418F99C810095C089 /* GCDWebServerDataRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerDataRequest.m; sourceTree = "<group>"; };
E2A0E80318F1D4A700C580B1 /* GCDWebServerURLEncodedFormRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerURLEncodedFormRequest.h; sourceTree = "<group>"; }; E28BAE2518F99C810095C089 /* GCDWebServerFileRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerFileRequest.h; sourceTree = "<group>"; };
E2A0E80418F1D4A700C580B1 /* GCDWebServerURLEncodedFormRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerURLEncodedFormRequest.m; sourceTree = "<group>"; }; E28BAE2618F99C810095C089 /* GCDWebServerFileRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerFileRequest.m; sourceTree = "<group>"; };
E28BAE2718F99C810095C089 /* GCDWebServerMultiPartFormRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerMultiPartFormRequest.h; sourceTree = "<group>"; };
E28BAE2818F99C810095C089 /* GCDWebServerMultiPartFormRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerMultiPartFormRequest.m; sourceTree = "<group>"; };
E28BAE2918F99C810095C089 /* GCDWebServerURLEncodedFormRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerURLEncodedFormRequest.h; sourceTree = "<group>"; };
E28BAE2A18F99C810095C089 /* GCDWebServerURLEncodedFormRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerURLEncodedFormRequest.m; sourceTree = "<group>"; };
E28BAE2C18F99C810095C089 /* GCDWebServerDataResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerDataResponse.h; sourceTree = "<group>"; };
E28BAE2D18F99C810095C089 /* GCDWebServerDataResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerDataResponse.m; sourceTree = "<group>"; };
E28BAE2E18F99C810095C089 /* GCDWebServerErrorResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerErrorResponse.h; sourceTree = "<group>"; };
E28BAE2F18F99C810095C089 /* GCDWebServerErrorResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerErrorResponse.m; sourceTree = "<group>"; };
E28BAE3018F99C810095C089 /* GCDWebServerFileResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerFileResponse.h; sourceTree = "<group>"; };
E28BAE3118F99C810095C089 /* GCDWebServerFileResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerFileResponse.m; sourceTree = "<group>"; };
E28BAE3218F99C810095C089 /* GCDWebServerStreamingResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerStreamingResponse.h; sourceTree = "<group>"; };
E28BAE3318F99C810095C089 /* GCDWebServerStreamingResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServerStreamingResponse.m; sourceTree = "<group>"; };
E2A0E80818F3432600C580B1 /* GCDWebDAVServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebDAVServer.h; sourceTree = "<group>"; }; E2A0E80818F3432600C580B1 /* GCDWebDAVServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebDAVServer.h; sourceTree = "<group>"; };
E2A0E80918F3432600C580B1 /* GCDWebDAVServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebDAVServer.m; sourceTree = "<group>"; }; E2A0E80918F3432600C580B1 /* GCDWebDAVServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebDAVServer.m; sourceTree = "<group>"; };
E2A0E80C18F35C9A00C580B1 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/usr/lib/libxml2.dylib; sourceTree = DEVELOPER_DIR; }; E2A0E80C18F35C9A00C580B1 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/usr/lib/libxml2.dylib; sourceTree = DEVELOPER_DIR; };
E2A0E80E18F35CA300C580B1 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; }; E2A0E80E18F35CA300C580B1 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
E2A0E81018F3737B00C580B1 /* GCDWebServerHTTPStatusCodes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GCDWebServerHTTPStatusCodes.h; sourceTree = "<group>"; };
E2B0D4A618F13495009A7927 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; E2B0D4A618F13495009A7927 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
E2B0D4A818F134A8009A7927 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/usr/lib/libz.dylib; sourceTree = DEVELOPER_DIR; }; E2B0D4A818F134A8009A7927 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/usr/lib/libz.dylib; sourceTree = DEVELOPER_DIR; };
E2BE850718E77ECA0061360B /* GCDWebUploader.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = GCDWebUploader.bundle; sourceTree = "<group>"; }; E2BE850718E77ECA0061360B /* GCDWebUploader.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = GCDWebUploader.bundle; sourceTree = "<group>"; };
@@ -179,7 +183,7 @@
08FB7794FE84155DC02AAC07 /* LittleCMS */ = { 08FB7794FE84155DC02AAC07 /* LittleCMS */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
E221127B1690B63A0048D2B2 /* CGDWebServer */, E28BAE1418F99C810095C089 /* GCDWebServer */,
E2A0E80718F3432600C580B1 /* GCDWebDAVServer */, E2A0E80718F3432600C580B1 /* GCDWebDAVServer */,
E2BE850618E77ECA0061360B /* GCDWebUploader */, E2BE850618E77ECA0061360B /* GCDWebUploader */,
E221128D1690B6470048D2B2 /* Mac */, E221128D1690B6470048D2B2 /* Mac */,
@@ -200,39 +204,6 @@
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
E221127B1690B63A0048D2B2 /* CGDWebServer */ = {
isa = PBXGroup;
children = (
E221127C1690B63A0048D2B2 /* GCDWebServer.h */,
E221127D1690B63A0048D2B2 /* GCDWebServer.m */,
E221127E1690B63A0048D2B2 /* GCDWebServerConnection.h */,
E221127F1690B63A0048D2B2 /* GCDWebServerConnection.m */,
E2A0E7F718F1D24700C580B1 /* GCDWebServerDataRequest.h */,
E2A0E7F818F1D24700C580B1 /* GCDWebServerDataRequest.m */,
E2A0E7EB18F1D03700C580B1 /* GCDWebServerDataResponse.h */,
E2A0E7EC18F1D03700C580B1 /* GCDWebServerDataResponse.m */,
E276647A18F3BC2100A034BA /* GCDWebServerErrorResponse.h */,
E276647B18F3BC2100A034BA /* GCDWebServerErrorResponse.m */,
E2A0E7FB18F1D36C00C580B1 /* GCDWebServerFileRequest.h */,
E2A0E7FC18F1D36C00C580B1 /* GCDWebServerFileRequest.m */,
E2A0E7EF18F1D12E00C580B1 /* GCDWebServerFileResponse.h */,
E2A0E7F018F1D12E00C580B1 /* GCDWebServerFileResponse.m */,
E2A0E81018F3737B00C580B1 /* GCDWebServerHTTPStatusCodes.h */,
E2A0E7FF18F1D3DE00C580B1 /* GCDWebServerMultiPartFormRequest.h */,
E2A0E80018F1D3DE00C580B1 /* GCDWebServerMultiPartFormRequest.m */,
E22112801690B63A0048D2B2 /* GCDWebServerPrivate.h */,
E22112811690B63A0048D2B2 /* GCDWebServerRequest.h */,
E22112821690B63A0048D2B2 /* GCDWebServerRequest.m */,
E22112831690B63A0048D2B2 /* GCDWebServerResponse.h */,
E22112841690B63A0048D2B2 /* GCDWebServerResponse.m */,
E2A0E7F318F1D1E500C580B1 /* GCDWebServerStreamingResponse.h */,
E2A0E7F418F1D1E500C580B1 /* GCDWebServerStreamingResponse.m */,
E2A0E80318F1D4A700C580B1 /* GCDWebServerURLEncodedFormRequest.h */,
E2A0E80418F1D4A700C580B1 /* GCDWebServerURLEncodedFormRequest.m */,
);
path = CGDWebServer;
sourceTree = "<group>";
};
E221128D1690B6470048D2B2 /* Mac */ = { E221128D1690B6470048D2B2 /* Mac */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@@ -276,6 +247,65 @@
name = "Mac Frameworks and Libraries"; name = "Mac Frameworks and Libraries";
sourceTree = "<group>"; sourceTree = "<group>";
}; };
E28BAE1418F99C810095C089 /* GCDWebServer */ = {
isa = PBXGroup;
children = (
E28BAE1518F99C810095C089 /* Core */,
E28BAE2218F99C810095C089 /* Requests */,
E28BAE2B18F99C810095C089 /* Responses */,
);
path = GCDWebServer;
sourceTree = "<group>";
};
E28BAE1518F99C810095C089 /* Core */ = {
isa = PBXGroup;
children = (
E28BAE1618F99C810095C089 /* GCDWebServer.h */,
E28BAE1718F99C810095C089 /* GCDWebServer.m */,
E28BAE1818F99C810095C089 /* GCDWebServerConnection.h */,
E28BAE1918F99C810095C089 /* GCDWebServerConnection.m */,
E28BAE1A18F99C810095C089 /* GCDWebServerFunctions.h */,
E28BAE1B18F99C810095C089 /* GCDWebServerFunctions.m */,
E28BAE1C18F99C810095C089 /* GCDWebServerHTTPStatusCodes.h */,
E28BAE1D18F99C810095C089 /* GCDWebServerPrivate.h */,
E28BAE1E18F99C810095C089 /* GCDWebServerRequest.h */,
E28BAE1F18F99C810095C089 /* GCDWebServerRequest.m */,
E28BAE2018F99C810095C089 /* GCDWebServerResponse.h */,
E28BAE2118F99C810095C089 /* GCDWebServerResponse.m */,
);
path = Core;
sourceTree = "<group>";
};
E28BAE2218F99C810095C089 /* Requests */ = {
isa = PBXGroup;
children = (
E28BAE2318F99C810095C089 /* GCDWebServerDataRequest.h */,
E28BAE2418F99C810095C089 /* GCDWebServerDataRequest.m */,
E28BAE2518F99C810095C089 /* GCDWebServerFileRequest.h */,
E28BAE2618F99C810095C089 /* GCDWebServerFileRequest.m */,
E28BAE2718F99C810095C089 /* GCDWebServerMultiPartFormRequest.h */,
E28BAE2818F99C810095C089 /* GCDWebServerMultiPartFormRequest.m */,
E28BAE2918F99C810095C089 /* GCDWebServerURLEncodedFormRequest.h */,
E28BAE2A18F99C810095C089 /* GCDWebServerURLEncodedFormRequest.m */,
);
path = Requests;
sourceTree = "<group>";
};
E28BAE2B18F99C810095C089 /* Responses */ = {
isa = PBXGroup;
children = (
E28BAE2C18F99C810095C089 /* GCDWebServerDataResponse.h */,
E28BAE2D18F99C810095C089 /* GCDWebServerDataResponse.m */,
E28BAE2E18F99C810095C089 /* GCDWebServerErrorResponse.h */,
E28BAE2F18F99C810095C089 /* GCDWebServerErrorResponse.m */,
E28BAE3018F99C810095C089 /* GCDWebServerFileResponse.h */,
E28BAE3118F99C810095C089 /* GCDWebServerFileResponse.m */,
E28BAE3218F99C810095C089 /* GCDWebServerStreamingResponse.h */,
E28BAE3318F99C810095C089 /* GCDWebServerStreamingResponse.m */,
);
path = Responses;
sourceTree = "<group>";
};
E2A0E80718F3432600C580B1 /* GCDWebDAVServer */ = { E2A0E80718F3432600C580B1 /* GCDWebDAVServer */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@@ -302,6 +332,7 @@
isa = PBXNativeTarget; isa = PBXNativeTarget;
buildConfigurationList = 1DEB928508733DD80010E9CD /* Build configuration list for PBXNativeTarget "GCDWebServer (Mac)" */; buildConfigurationList = 1DEB928508733DD80010E9CD /* Build configuration list for PBXNativeTarget "GCDWebServer (Mac)" */;
buildPhases = ( buildPhases = (
E21F038418FB37D80043AD1E /* Delete GCDWebUploader.bundle */,
E2BE850E18E788910061360B /* CopyFiles */, E2BE850E18E788910061360B /* CopyFiles */,
8DD76FAB0486AB0100D96B5E /* Sources */, 8DD76FAB0486AB0100D96B5E /* Sources */,
8DD76FAD0486AB0100D96B5E /* Frameworks */, 8DD76FAD0486AB0100D96B5E /* Frameworks */,
@@ -374,26 +405,45 @@
}; };
/* End PBXResourcesBuildPhase section */ /* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
E21F038418FB37D80043AD1E /* Delete GCDWebUploader.bundle */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Delete GCDWebUploader.bundle";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cd \"$BUILT_PRODUCTS_DIR\"\nrm -rf \"GCDWebUploader.bundle\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */
8DD76FAB0486AB0100D96B5E /* Sources */ = { 8DD76FAB0486AB0100D96B5E /* Sources */ = {
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
E22112851690B63A0048D2B2 /* GCDWebServer.m in Sources */, E28BAE4618F99C810095C089 /* GCDWebServerDataResponse.m in Sources */,
E2A0E7FD18F1D36C00C580B1 /* GCDWebServerFileRequest.m in Sources */, E28BAE3818F99C810095C089 /* GCDWebServerFunctions.m in Sources */,
E22112871690B63A0048D2B2 /* GCDWebServerConnection.m in Sources */, E28BAE4A18F99C810095C089 /* GCDWebServerFileResponse.m in Sources */,
E2A0E80518F1D4A700C580B1 /* GCDWebServerURLEncodedFormRequest.m in Sources */, E28BAE4418F99C810095C089 /* GCDWebServerURLEncodedFormRequest.m in Sources */,
E2A0E7F918F1D24700C580B1 /* GCDWebServerDataRequest.m in Sources */, E28BAE3A18F99C810095C089 /* GCDWebServerRequest.m in Sources */,
E22112891690B63A0048D2B2 /* GCDWebServerRequest.m in Sources */, E28BAE3418F99C810095C089 /* GCDWebServer.m in Sources */,
E276647C18F3BC2100A034BA /* GCDWebServerErrorResponse.m in Sources */, E28BAE3618F99C810095C089 /* GCDWebServerConnection.m in Sources */,
E2A0E7ED18F1D03700C580B1 /* GCDWebServerDataResponse.m in Sources */, E28BAE3C18F99C810095C089 /* GCDWebServerResponse.m in Sources */,
E2A0E7F518F1D1E500C580B1 /* GCDWebServerStreamingResponse.m in Sources */, E28BAE4018F99C810095C089 /* GCDWebServerFileRequest.m in Sources */,
E2A0E80118F1D3DE00C580B1 /* GCDWebServerMultiPartFormRequest.m in Sources */, E28BAE4C18F99C810095C089 /* GCDWebServerStreamingResponse.m in Sources */,
E221128B1690B63A0048D2B2 /* GCDWebServerResponse.m in Sources */, E28BAE3E18F99C810095C089 /* GCDWebServerDataRequest.m in Sources */,
E2A0E80A18F3432600C580B1 /* GCDWebDAVServer.m in Sources */, E2A0E80A18F3432600C580B1 /* GCDWebDAVServer.m in Sources */,
E28BAE4218F99C810095C089 /* GCDWebServerMultiPartFormRequest.m in Sources */,
E2BE850C18E785940061360B /* GCDWebUploader.m in Sources */, E2BE850C18E785940061360B /* GCDWebUploader.m in Sources */,
E221128F1690B6470048D2B2 /* main.m in Sources */, E221128F1690B6470048D2B2 /* main.m in Sources */,
E2A0E7F118F1D12E00C580B1 /* GCDWebServerFileResponse.m in Sources */, E28BAE4818F99C810095C089 /* GCDWebServerErrorResponse.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@@ -402,21 +452,22 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
E2A0E80B18F3432600C580B1 /* GCDWebDAVServer.m in Sources */, E2A0E80B18F3432600C580B1 /* GCDWebDAVServer.m in Sources */,
E22112861690B63A0048D2B2 /* GCDWebServer.m in Sources */, E28BAE4918F99C810095C089 /* GCDWebServerErrorResponse.m in Sources */,
E276647D18F3BC2100A034BA /* GCDWebServerErrorResponse.m in Sources */, E28BAE4518F99C810095C089 /* GCDWebServerURLEncodedFormRequest.m in Sources */,
E2A0E7EE18F1D03700C580B1 /* GCDWebServerDataResponse.m in Sources */, E28BAE4B18F99C810095C089 /* GCDWebServerFileResponse.m in Sources */,
E2A0E80218F1D3DE00C580B1 /* GCDWebServerMultiPartFormRequest.m in Sources */, E28BAE3918F99C810095C089 /* GCDWebServerFunctions.m in Sources */,
E22112881690B63A0048D2B2 /* GCDWebServerConnection.m in Sources */, E28BAE4118F99C810095C089 /* GCDWebServerFileRequest.m in Sources */,
E221128A1690B63A0048D2B2 /* GCDWebServerRequest.m in Sources */, E28BAE4D18F99C810095C089 /* GCDWebServerStreamingResponse.m in Sources */,
E221128C1690B63A0048D2B2 /* GCDWebServerResponse.m in Sources */, E28BAE3F18F99C810095C089 /* GCDWebServerDataRequest.m in Sources */,
E2A0E7FA18F1D24700C580B1 /* GCDWebServerDataRequest.m in Sources */,
E2A0E80618F1D4A700C580B1 /* GCDWebServerURLEncodedFormRequest.m in Sources */,
E2BE850B18E77ECA0061360B /* GCDWebUploader.m in Sources */, E2BE850B18E77ECA0061360B /* GCDWebUploader.m in Sources */,
E22112951690B64F0048D2B2 /* AppDelegate.m in Sources */, E22112951690B64F0048D2B2 /* AppDelegate.m in Sources */,
E2A0E7FE18F1D36C00C580B1 /* GCDWebServerFileRequest.m in Sources */, E28BAE4718F99C810095C089 /* GCDWebServerDataResponse.m in Sources */,
E2A0E7F618F1D1E500C580B1 /* GCDWebServerStreamingResponse.m in Sources */, E28BAE3D18F99C810095C089 /* GCDWebServerResponse.m in Sources */,
E2A0E7F218F1D12E00C580B1 /* GCDWebServerFileResponse.m in Sources */, E28BAE3518F99C810095C089 /* GCDWebServer.m in Sources */,
E28BAE3718F99C810095C089 /* GCDWebServerConnection.m in Sources */,
E28BAE3B18F99C810095C089 /* GCDWebServerRequest.m in Sources */,
E22112971690B64F0048D2B2 /* main.m in Sources */, E22112971690B64F0048D2B2 /* main.m in Sources */,
E28BAE4318F99C810095C089 /* GCDWebServerMultiPartFormRequest.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@@ -461,6 +512,7 @@
buildSettings = { buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_ARC = YES;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = __GCDWEBSERVER_ENABLE_TESTING__;
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"; HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
WARNING_CFLAGS = ( WARNING_CFLAGS = (
@@ -488,6 +540,7 @@
buildSettings = { buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_ARC = YES;
GCC_PREPROCESSOR_DEFINITIONS = NDEBUG; GCC_PREPROCESSOR_DEFINITIONS = NDEBUG;
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = __GCDWEBSERVER_ENABLE_TESTING__;
GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_TREAT_WARNINGS_AS_ERRORS = YES;
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"; HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
WARNING_CFLAGS = "-Wall"; WARNING_CFLAGS = "-Wall";

View File

@@ -42,37 +42,41 @@ typedef NS_ENUM(int, GCDWebServerLogLevel) {
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);
#ifdef __cplusplus extern NSString* const GCDWebServerOption_Port; // NSNumber / NSUInteger (default is 0 i.e. use a random port)
extern "C" { extern NSString* const GCDWebServerOption_BonjourName; // NSString (default is empty string i.e. use computer name)
extern NSString* const GCDWebServerOption_MaxPendingConnections; // NSNumber / NSUInteger (default is 16)
extern NSString* const GCDWebServerOption_ServerName; // NSString (default is server class name)
extern NSString* const GCDWebServerOption_ConnectionClass; // Subclass of GCDWebServerConnection (default is GCDWebServerConnection class)
extern NSString* const GCDWebServerOption_AutomaticallyMapHEADToGET; // NSNumber / BOOL (default is YES)
extern NSString* const GCDWebServerOption_ConnectedStateCoalescingInterval; // NSNumber / double (default is 1.0 seconds - set to <=0.0 to disable coaslescing of -webServerDidConnect: / -webServerDidDisconnect:)
#if TARGET_OS_IPHONE
extern NSString* const GCDWebServerOption_AutomaticallySuspendInBackground; // NSNumber / BOOL (default is YES)
#endif #endif
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension); @class GCDWebServer;
NSString* GCDWebServerEscapeURLString(NSString* string);
NSString* GCDWebServerUnescapeURLString(NSString* string);
NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form);
NSString* GCDWebServerGetPrimaryIPv4Address(); // Returns IPv4 address of primary connected service on OS X or of WiFi interface on iOS if connected
#ifdef __cplusplus // These methods are always called on main thread
} @protocol GCDWebServerDelegate <NSObject>
#endif @optional
- (void)webServerDidStart:(GCDWebServer*)server;
- (void)webServerDidConnect:(GCDWebServer*)server; // Called when first connection is opened
- (void)webServerDidDisconnect:(GCDWebServer*)server; // Called when last connection is closed
- (void)webServerDidStop:(GCDWebServer*)server;
@end
@interface GCDWebServer : NSObject @interface GCDWebServer : NSObject
@property(nonatomic, assign) id<GCDWebServerDelegate> delegate;
@property(nonatomic, readonly, getter=isRunning) BOOL running; @property(nonatomic, readonly, getter=isRunning) BOOL running;
@property(nonatomic, readonly) NSUInteger port; @property(nonatomic, readonly) NSUInteger port; // Only non-zero if running
@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
- (instancetype)init; - (instancetype)init;
- (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock; - (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock;
- (void)removeAllHandlers; - (void)removeAllHandlers;
- (BOOL)start; // Default is port 8080 (OS X & iOS Simulator) or 80 (iOS) and computer name - (BOOL)start; // Default is port 8080 (OS X & iOS Simulator) or 80 (iOS) and computer / device name for Bonjour
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name; // Pass nil name to disable Bonjour or empty string to use computer name - (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name; // Pass nil name to disable Bonjour or empty string to use computer name
- (void)stop; - (BOOL)startWithOptions:(NSDictionary*)options;
@end - (void)stop; // Does not abort any currently opened connections
@interface GCDWebServer (Subclassing)
+ (Class)connectionClass;
+ (NSString*)serverName; // Default is class name
+ (BOOL)shouldAutomaticallyMapHEADToGET; // Default is YES which means HEAD requests are mapped to GET requests with the response body being discarded
@end @end
@interface GCDWebServer (Extensions) @interface GCDWebServer (Extensions)
@@ -104,3 +108,12 @@ NSString* GCDWebServerGetPrimaryIPv4Address(); // Returns IPv4 address of prima
- (void)logWarning:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2); - (void)logWarning:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
- (void)logError:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2); - (void)logError:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
@end @end
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
@interface GCDWebServer (Testing)
@property(nonatomic, getter=isRecordingEnabled) BOOL recordingEnabled; // Creates files in the current directory containing the raw data for all requests and responses (directory most NOT contain prior recordings)
- (NSInteger)runTestsInDirectory:(NSString*)path withPort:(NSUInteger)port; // Returns number of failed tests or -1 if server failed to start
@end
#endif

View File

@@ -27,15 +27,13 @@
#import <TargetConditionals.h> #import <TargetConditionals.h>
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
#import <MobileCoreServices/MobileCoreServices.h> #import <UIKit/UIKit.h>
#else #else
#import <SystemConfiguration/SystemConfiguration.h> #ifdef __GCDWEBSERVER_ENABLE_TESTING__
#import <AppKit/AppKit.h>
#endif
#endif #endif
#import <netinet/in.h> #import <netinet/in.h>
#import <ifaddrs.h>
#import <net/if.h>
#import <netdb.h>
#import "GCDWebServerPrivate.h" #import "GCDWebServerPrivate.h"
@@ -44,15 +42,31 @@
#else #else
#define kDefaultPort 8080 #define kDefaultPort 8080
#endif #endif
#define kMaxPendingConnections 16
@interface GCDWebServer () { @interface GCDWebServer () {
@private @private
id<GCDWebServerDelegate> __unsafe_unretained _delegate;
dispatch_queue_t _syncQueue;
NSMutableArray* _handlers; NSMutableArray* _handlers;
NSInteger _activeConnections; // Accessed only with _syncQueue
BOOL _connected;
CFRunLoopTimerRef _connectedTimer;
NSDictionary* _options;
NSString* _serverName;
Class _connectionClass;
BOOL _mapHEADToGET;
CFTimeInterval _disconnectDelay;
NSUInteger _port; NSUInteger _port;
dispatch_source_t _source; dispatch_source_t _source;
CFNetServiceRef _service; CFNetServiceRef _service;
#if TARGET_OS_IPHONE
BOOL _suspendInBackground;
UIBackgroundTaskIdentifier _backgroundTask;
#endif
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
BOOL _recording;
#endif
} }
@end @end
@@ -63,6 +77,17 @@
} }
@end @end
NSString* const GCDWebServerOption_Port = @"Port";
NSString* const GCDWebServerOption_BonjourName = @"BonjourName";
NSString* const GCDWebServerOption_MaxPendingConnections = @"MaxPendingConnections";
NSString* const GCDWebServerOption_ServerName = @"ServerName";
NSString* const GCDWebServerOption_ConnectionClass = @"ConnectionClass";
NSString* const GCDWebServerOption_AutomaticallyMapHEADToGET = @"AutomaticallyMapHEADToGET";
NSString* const GCDWebServerOption_ConnectedStateCoalescingInterval = @"ConnectedStateCoalescingInterval";
#if TARGET_OS_IPHONE
NSString* const GCDWebServerOption_AutomaticallySuspendInBackground = @"AutomaticallySuspendInBackground";
#endif
#ifndef __GCDWEBSERVER_LOGGING_HEADER__ #ifndef __GCDWEBSERVER_LOGGING_HEADER__
#ifdef NDEBUG #ifdef NDEBUG
GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Info; GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Info;
@@ -71,8 +96,6 @@ GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Debug;
#endif #endif
#endif #endif
static NSDateFormatter* _dateFormatterRFC822 = nil;
static dispatch_queue_t _dateFormatterQueue = NULL;
#if !TARGET_OS_IPHONE #if !TARGET_OS_IPHONE
static BOOL _run; static BOOL _run;
#endif #endif
@@ -91,187 +114,6 @@ void GCDLogMessage(GCDWebServerLogLevel level, NSString* format, ...) {
#endif #endif
NSString* GCDWebServerNormalizeHeaderValue(NSString* value) {
if (value) {
NSRange range = [value rangeOfString:@";"]; // Assume part before ";" separator is case-insensitive
if (range.location != NSNotFound) {
value = [[[value substringToIndex:range.location] lowercaseString] stringByAppendingString:[value substringFromIndex:range.location]];
} else {
value = [value lowercaseString];
}
}
return value;
}
NSString* GCDWebServerTruncateHeaderValue(NSString* value) {
DCHECK([value isEqualToString:GCDWebServerNormalizeHeaderValue(value)]);
NSRange range = [value rangeOfString:@";"];
return range.location != NSNotFound ? [value substringToIndex:range.location] : value;
}
NSString* GCDWebServerExtractHeaderValueParameter(NSString* value, NSString* name) {
DCHECK([value isEqualToString:GCDWebServerNormalizeHeaderValue(value)]);
NSString* parameter = nil;
NSScanner* scanner = [[NSScanner alloc] initWithString:value];
[scanner setCaseSensitive:NO]; // Assume parameter names are case-insensitive
NSString* string = [NSString stringWithFormat:@"%@=", name];
if ([scanner scanUpToString:string intoString:NULL]) {
[scanner scanString:string intoString:NULL];
if ([scanner scanString:@"\"" intoString:NULL]) {
[scanner scanUpToString:@"\"" intoString:&parameter];
} else {
[scanner scanUpToCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:&parameter];
}
}
ARC_RELEASE(scanner);
return parameter;
}
// http://www.w3schools.com/tags/ref_charactersets.asp
NSStringEncoding GCDWebServerStringEncodingFromCharset(NSString* charset) {
NSStringEncoding encoding = kCFStringEncodingInvalidId;
if (charset) {
encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)charset));
}
return (encoding != kCFStringEncodingInvalidId ? encoding : NSUTF8StringEncoding);
}
NSString* GCDWebServerFormatHTTPDate(NSDate* date) {
__block NSString* string;
dispatch_sync(_dateFormatterQueue, ^{
string = [_dateFormatterRFC822 stringFromDate:date]; // HTTP/1.1 server must use RFC822
});
return string;
}
NSDate* GCDWebServerParseHTTPDate(NSString* string) {
__block NSDate* date;
dispatch_sync(_dateFormatterQueue, ^{
date = [_dateFormatterRFC822 dateFromString:string]; // TODO: Handle RFC 850 and ANSI C's asctime() format (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3)
});
return date;
}
NSString* GCDWebServerDescribeData(NSData* data, NSString* contentType) {
if ([contentType hasPrefix:@"text/"] || [contentType isEqualToString:@"application/json"] || [contentType isEqualToString:@"application/xml"]) {
NSString* charset = GCDWebServerExtractHeaderValueParameter(contentType, @"charset");
NSString* string = [[NSString alloc] initWithData:data encoding:GCDWebServerStringEncodingFromCharset(charset)];
if (string) {
return ARC_AUTORELEASE(string);
}
}
return [NSString stringWithFormat:@"<%lu bytes>", (unsigned long)data.length];
}
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension) {
static NSDictionary* _overrides = nil;
if (_overrides == nil) {
_overrides = [[NSDictionary alloc] initWithObjectsAndKeys:
@"text/css", @"css",
nil];
}
NSString* mimeType = nil;
extension = [extension lowercaseString];
if (extension.length) {
mimeType = [_overrides objectForKey:extension];
if (mimeType == nil) {
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (ARC_BRIDGE CFStringRef)extension, NULL);
if (uti) {
mimeType = ARC_BRIDGE_RELEASE(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));
CFRelease(uti);
}
}
}
return mimeType ? mimeType : kGCDWebServerDefaultMimeType;
}
NSString* GCDWebServerEscapeURLString(NSString* string) {
return ARC_BRIDGE_RELEASE(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR(":@/?&=+"), kCFStringEncodingUTF8));
}
NSString* GCDWebServerUnescapeURLString(NSString* string) {
return ARC_BRIDGE_RELEASE(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)string, CFSTR(""), kCFStringEncodingUTF8));
}
// http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form) {
NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
NSScanner* scanner = [[NSScanner alloc] initWithString:form];
[scanner setCharactersToBeSkipped:nil];
while (1) {
NSString* key = nil;
if (![scanner scanUpToString:@"=" intoString:&key] || [scanner isAtEnd]) {
break;
}
[scanner setScanLocation:([scanner scanLocation] + 1)];
NSString* value = nil;
if (![scanner scanUpToString:@"&" intoString:&value]) {
break;
}
key = [key stringByReplacingOccurrencesOfString:@"+" withString:@" "];
value = [value stringByReplacingOccurrencesOfString:@"+" withString:@" "];
if (key && value) {
[parameters setObject:GCDWebServerUnescapeURLString(value) forKey:GCDWebServerUnescapeURLString(key)];
} else {
DNOT_REACHED();
}
if ([scanner isAtEnd]) {
break;
}
[scanner setScanLocation:([scanner scanLocation] + 1)];
}
ARC_RELEASE(scanner);
return parameters;
}
NSString* GCDWebServerGetPrimaryIPv4Address() {
NSString* address = nil;
#if TARGET_OS_IPHONE
#if !TARGET_IPHONE_SIMULATOR
const char* primaryInterface = "en0"; // WiFi interface on iOS
#endif
#else
const char* primaryInterface = NULL;
SCDynamicStoreRef store = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("GCDWebServer"), NULL, NULL);
if (store) {
CFPropertyListRef info = SCDynamicStoreCopyValue(store, CFSTR("State:/Network/Global/IPv4"));
if (info) {
primaryInterface = [[(ARC_BRIDGE NSDictionary*)info objectForKey:@"PrimaryInterface"] UTF8String];
CFRelease(info);
}
CFRelease(store);
}
if (primaryInterface == NULL) {
primaryInterface = "lo0";
}
#endif
struct ifaddrs* list;
if (getifaddrs(&list) >= 0) {
for (struct ifaddrs* ifap = list; ifap; ifap = ifap->ifa_next) {
#if TARGET_IPHONE_SIMULATOR
if (strcmp(ifap->ifa_name, "en0") && strcmp(ifap->ifa_name, "en1")) // Assume en0 is Ethernet and en1 is WiFi since there is no way to use SystemConfiguration framework in iOS Simulator
#else
if (strcmp(ifap->ifa_name, primaryInterface))
#endif
{
continue;
}
if ((ifap->ifa_flags & IFF_UP) && (ifap->ifa_addr->sa_family == AF_INET)) {
char buffer[NI_MAXHOST];
if (getnameinfo(ifap->ifa_addr, ifap->ifa_addr->sa_len, buffer, sizeof(buffer), NULL, 0, NI_NUMERICHOST | NI_NOFQDN) >= 0) {
address = [NSString stringWithUTF8String:buffer];
}
break;
}
}
freeifaddrs(list);
}
return address;
}
#if !TARGET_OS_IPHONE #if !TARGET_OS_IPHONE
static void _SignalHandler(int signal) { static void _SignalHandler(int signal) {
@@ -304,7 +146,7 @@ static void _SignalHandler(int signal) {
@implementation GCDWebServer @implementation GCDWebServer
@synthesize handlers=_handlers, port=_port; @synthesize delegate=_delegate, handlers=_handlers, port=_port, serverName=_serverName, shouldAutomaticallyMapHEADToGET=_mapHEADToGET;
#ifndef __GCDWEBSERVER_LOGGING_HEADER__ #ifndef __GCDWEBSERVER_LOGGING_HEADER__
@@ -318,58 +160,169 @@ static void _SignalHandler(int signal) {
#endif #endif
+ (void)initialize { + (void)initialize {
if (_dateFormatterRFC822 == nil) { GCDWebServerInitializeFunctions();
DCHECK([NSThread isMainThread]); // NSDateFormatter should be initialized on main thread }
_dateFormatterRFC822 = [[NSDateFormatter alloc] init];
_dateFormatterRFC822.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; static void _ConnectedTimerCallBack(CFRunLoopTimerRef timer, void* info) {
_dateFormatterRFC822.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'"; @autoreleasepool {
_dateFormatterRFC822.locale = ARC_AUTORELEASE([[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]); [(ARC_BRIDGE GCDWebServer*)info _didDisconnect];
DCHECK(_dateFormatterRFC822);
}
if (_dateFormatterQueue == NULL) {
_dateFormatterQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
DCHECK(_dateFormatterQueue);
} }
} }
- (instancetype)init { - (instancetype)init {
if ((self = [super init])) { if ((self = [super init])) {
_syncQueue = dispatch_queue_create([NSStringFromClass([self class]) UTF8String], DISPATCH_QUEUE_SERIAL);
_handlers = [[NSMutableArray alloc] init]; _handlers = [[NSMutableArray alloc] init];
CFRunLoopTimerContext context = {0, (ARC_BRIDGE void*)self, NULL, NULL, NULL};
_connectedTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, HUGE_VAL, HUGE_VAL, 0, 0, _ConnectedTimerCallBack, &context);
CFRunLoopAddTimer(CFRunLoopGetMain(), _connectedTimer, kCFRunLoopCommonModes);
#if TARGET_OS_IPHONE
_backgroundTask = UIBackgroundTaskInvalid;
#endif
} }
return self; return self;
} }
- (void)dealloc { - (void)dealloc {
if (_source) { DCHECK(_connected == NO);
DCHECK(_activeConnections == 0);
_delegate = nil;
if (_options) {
[self stop]; [self stop];
} }
CFRunLoopTimerInvalidate(_connectedTimer);
CFRelease(_connectedTimer);
ARC_RELEASE(_handlers); ARC_RELEASE(_handlers);
ARC_DISPATCH_RELEASE(_syncQueue);
ARC_DEALLOC(super); ARC_DEALLOC(super);
} }
#if TARGET_OS_IPHONE
// Always called on main thread
- (void)_startBackgroundTask {
DCHECK([NSThread isMainThread]);
if (_backgroundTask == UIBackgroundTaskInvalid) {
LOG_DEBUG(@"Did start background task");
_backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
LOG_WARNING(@"Application is being suspended while %@ is still connected", [self class]);
[self _endBackgroundTask];
}];
} else {
DNOT_REACHED();
}
}
#endif
// Always called on main thread
- (void)_didConnect {
DCHECK([NSThread isMainThread]);
DCHECK(_connected == NO);
_connected = YES;
LOG_DEBUG(@"Did connect");
#if TARGET_OS_IPHONE
[self _startBackgroundTask];
#endif
if ([_delegate respondsToSelector:@selector(webServerDidConnect:)]) {
[_delegate webServerDidConnect:self];
}
}
- (void)willStartConnection:(GCDWebServerConnection*)connection {
dispatch_sync(_syncQueue, ^{
DCHECK(_activeConnections >= 0);
if (_activeConnections == 0) {
dispatch_async(dispatch_get_main_queue(), ^{
if (_disconnectDelay > 0.0) {
CFRunLoopTimerSetNextFireDate(_connectedTimer, HUGE_VAL);
}
if (_connected == NO) {
[self _didConnect];
}
});
}
_activeConnections += 1;
});
}
#if TARGET_OS_IPHONE
// Always called on main thread
- (void)_endBackgroundTask {
DCHECK([NSThread isMainThread]);
if (_backgroundTask != UIBackgroundTaskInvalid) {
if (_suspendInBackground && ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) && _source) {
[self _stop];
}
[[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
_backgroundTask = UIBackgroundTaskInvalid;
LOG_DEBUG(@"Did end background task");
} else {
DNOT_REACHED();
}
}
#endif
// Always called on main thread
- (void)_didDisconnect {
DCHECK([NSThread isMainThread]);
DCHECK(_connected == YES);
_connected = NO;
LOG_DEBUG(@"Did disconnect");
#if TARGET_OS_IPHONE
[self _endBackgroundTask];
#endif
if ([_delegate respondsToSelector:@selector(webServerDidDisconnect:)]) {
[_delegate webServerDidDisconnect:self];
}
}
- (void)didEndConnection:(GCDWebServerConnection*)connection {
dispatch_sync(_syncQueue, ^{
DCHECK(_activeConnections > 0);
_activeConnections -= 1;
if (_activeConnections == 0) {
dispatch_async(dispatch_get_main_queue(), ^{
if (_disconnectDelay > 0.0) {
CFRunLoopTimerSetNextFireDate(_connectedTimer, CFAbsoluteTimeGetCurrent() + _disconnectDelay);
} else {
[self _didDisconnect];
}
});
}
});
}
- (NSString*)bonjourName { - (NSString*)bonjourName {
CFStringRef name = _service ? CFNetServiceGetName(_service) : NULL; CFStringRef name = _service ? CFNetServiceGetName(_service) : NULL;
return name && CFStringGetLength(name) ? ARC_BRIDGE_RELEASE(CFStringCreateCopy(kCFAllocatorDefault, name)) : nil; return name && CFStringGetLength(name) ? ARC_BRIDGE_RELEASE(CFStringCreateCopy(kCFAllocatorDefault, name)) : nil;
} }
- (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)handlerBlock { - (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)handlerBlock {
DCHECK(_source == NULL); DCHECK(_options == nil);
GCDWebServerHandler* handler = [[GCDWebServerHandler alloc] initWithMatchBlock:matchBlock processBlock:handlerBlock]; GCDWebServerHandler* handler = [[GCDWebServerHandler alloc] initWithMatchBlock:matchBlock processBlock:handlerBlock];
[_handlers insertObject:handler atIndex:0]; [_handlers insertObject:handler atIndex:0];
ARC_RELEASE(handler); ARC_RELEASE(handler);
} }
- (void)removeAllHandlers { - (void)removeAllHandlers {
DCHECK(_source == NULL); DCHECK(_options == nil);
[_handlers removeAllObjects]; [_handlers removeAllObjects];
} }
- (BOOL)start {
return [self startWithPort:kDefaultPort bonjourName:@""];
}
static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* error, void* info) { static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* error, void* info) {
@autoreleasepool { @autoreleasepool {
if (error->error) { if (error->error) {
@@ -381,8 +334,16 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
} }
} }
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name { static inline id _GetOption(NSDictionary* options, NSString* key, id defaultValue) {
id value = [options objectForKey:key];
return value ? value : defaultValue;
}
- (BOOL)_start {
DCHECK(_source == NULL); DCHECK(_source == NULL);
NSUInteger port = [_GetOption(_options, GCDWebServerOption_Port, @0) unsignedIntegerValue];
NSString* name = _GetOption(_options, GCDWebServerOption_BonjourName, @"");
NSUInteger maxPendingConnections = [_GetOption(_options, GCDWebServerOption_MaxPendingConnections, @16) unsignedIntegerValue];
int listeningSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); int listeningSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (listeningSocket > 0) { if (listeningSocket > 0) {
int yes = 1; int yes = 1;
@@ -395,16 +356,21 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
addr4.sin_port = htons(port); addr4.sin_port = htons(port);
addr4.sin_addr.s_addr = htonl(INADDR_ANY); addr4.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(listeningSocket, (void*)&addr4, sizeof(addr4)) == 0) { if (bind(listeningSocket, (void*)&addr4, sizeof(addr4)) == 0) {
if (listen(listeningSocket, kMaxPendingConnections) == 0) { if (listen(listeningSocket, (int)maxPendingConnections) == 0) {
LOG_DEBUG(@"Did open listening socket %i", listeningSocket);
_serverName = [_GetOption(_options, GCDWebServerOption_ServerName, NSStringFromClass([self class])) copy];
_connectionClass = _GetOption(_options, GCDWebServerOption_ConnectionClass, [GCDWebServerConnection class]);
_mapHEADToGET = [_GetOption(_options, GCDWebServerOption_AutomaticallyMapHEADToGET, @YES) boolValue];
_disconnectDelay = [_GetOption(_options, GCDWebServerOption_ConnectedStateCoalescingInterval, @1.0) doubleValue];
_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, listeningSocket, 0, kGCDWebServerGCDQueue); _source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, listeningSocket, 0, kGCDWebServerGCDQueue);
dispatch_source_set_cancel_handler(_source, ^{ dispatch_source_set_cancel_handler(_source, ^{
@autoreleasepool { @autoreleasepool {
int result = close(listeningSocket); int result = close(listeningSocket);
if (result != 0) { if (result != 0) {
LOG_ERROR(@"Failed closing socket (%i): %s", errno, strerror(errno)); LOG_ERROR(@"Failed closing listening socket: %s (%i)", strerror(errno), errno);
} else { } else {
LOG_DEBUG(@"Closed listening socket"); LOG_DEBUG(@"Did close listening socket %i", listeningSocket);
} }
} }
@@ -430,28 +396,27 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
int noSigPipe = 1; int noSigPipe = 1;
setsockopt(socket, SOL_SOCKET, SO_NOSIGPIPE, &noSigPipe, sizeof(noSigPipe)); // Make sure this socket cannot generate SIG_PIPE setsockopt(socket, SOL_SOCKET, SO_NOSIGPIPE, &noSigPipe, sizeof(noSigPipe)); // Make sure this socket cannot generate SIG_PIPE
Class connectionClass = [[self class] connectionClass]; GCDWebServerConnection* connection = [[_connectionClass alloc] initWithServer:self localAddress:localAddress remoteAddress:remoteAddress socket:socket]; // Connection will automatically retain itself while opened
GCDWebServerConnection* connection = [[connectionClass alloc] initWithServer:self localAddress:localAddress remoteAddress:remoteAddress socket:socket]; // Connection will automatically retain itself while opened
#if __has_feature(objc_arc) #if __has_feature(objc_arc)
[connection self]; // Prevent compiler from complaining about unused variable / useless statement [connection self]; // Prevent compiler from complaining about unused variable / useless statement
#else #else
[connection release]; [connection release];
#endif #endif
} else { } else {
LOG_ERROR(@"Failed accepting socket (%i): %s", errno, strerror(errno)); LOG_ERROR(@"Failed accepting socket: %s (%i)", strerror(errno), errno);
} }
} }
}); });
if (port == 0) { // Determine the actual port we are listening on if (port == 0) {
struct sockaddr addr; struct sockaddr addr;
socklen_t addrlen = sizeof(addr); socklen_t addrlen = sizeof(addr);
if (getsockname(listeningSocket, &addr, &addrlen) == 0) { if (getsockname(listeningSocket, &addr, &addrlen) == 0) {
struct sockaddr_in* sockaddr = (struct sockaddr_in*)&addr; struct sockaddr_in* sockaddr = (struct sockaddr_in*)&addr;
_port = ntohs(sockaddr->sin_port); _port = ntohs(sockaddr->sin_port);
} else { } else {
LOG_ERROR(@"Failed retrieving socket address (%i): %s", errno, strerror(errno)); LOG_ERROR(@"Failed retrieving socket address: %s (%i)", strerror(errno), errno);
} }
} else { } else {
_port = port; _port = port;
@@ -472,57 +437,129 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
dispatch_resume(_source); dispatch_resume(_source);
LOG_INFO(@"%@ started on port %i and reachable at %@", [self class], (int)_port, self.serverURL); LOG_INFO(@"%@ started on port %i and reachable at %@", [self class], (int)_port, self.serverURL);
if ([_delegate respondsToSelector:@selector(webServerDidStart:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
[_delegate webServerDidStart:self];
});
}
} else { } else {
LOG_ERROR(@"Failed listening on socket (%i): %s", errno, strerror(errno)); LOG_ERROR(@"Failed listening on socket: %s (%i)", strerror(errno), errno);
close(listeningSocket); close(listeningSocket);
} }
} else { } else {
LOG_ERROR(@"Failed binding socket (%i): %s", errno, strerror(errno)); LOG_ERROR(@"Failed binding socket: %s (%i)", strerror(errno), errno);
close(listeningSocket); close(listeningSocket);
} }
} else { } else {
LOG_ERROR(@"Failed creating socket (%i): %s", errno, strerror(errno)); LOG_ERROR(@"Failed creating socket: %s (%i)", strerror(errno), errno);
} }
return (_source ? YES : NO); return (_source ? YES : NO);
} }
- (void)_stop {
DCHECK(_source != NULL);
if (_service) {
CFNetServiceUnscheduleFromRunLoop(_service, CFRunLoopGetMain(), kCFRunLoopCommonModes);
CFNetServiceSetClient(_service, NULL, NULL);
CFRelease(_service);
_service = NULL;
}
dispatch_source_cancel(_source); // This will close the socket
ARC_DISPATCH_RELEASE(_source);
_source = NULL;
_port = 0;
ARC_RELEASE(_serverName);
_serverName = nil;
LOG_INFO(@"%@ stopped", [self class]);
if ([_delegate respondsToSelector:@selector(webServerDidStop:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
[_delegate webServerDidStop:self];
});
}
}
- (BOOL)start {
return [self startWithPort:kDefaultPort bonjourName:@""];
}
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name {
NSMutableDictionary* options = [NSMutableDictionary dictionary];
[options setObject:[NSNumber numberWithInteger:port] forKey:GCDWebServerOption_Port];
[options setValue:name forKey:GCDWebServerOption_BonjourName];
return [self startWithOptions:options];
}
#if TARGET_OS_IPHONE
- (void)_didEnterBackground:(NSNotification*)notification {
DCHECK([NSThread isMainThread]);
LOG_DEBUG(@"Did enter background");
if ((_backgroundTask == UIBackgroundTaskInvalid) && _source) {
[self _stop];
}
}
- (void)_willEnterForeground:(NSNotification*)notification {
DCHECK([NSThread isMainThread]);
LOG_DEBUG(@"Will enter foreground");
if (!_source) {
[self _start]; // TODO: There's probably nothing we can do on failure
}
}
#endif
- (BOOL)startWithOptions:(NSDictionary*)options {
if (_options == nil) {
_options = [options copy];
#if TARGET_OS_IPHONE
_suspendInBackground = [_GetOption(_options, GCDWebServerOption_AutomaticallySuspendInBackground, @YES) boolValue];
if (((_suspendInBackground == NO) || ([[UIApplication sharedApplication] applicationState] != UIApplicationStateBackground)) && ![self _start])
#else
if (![self _start])
#endif
{
ARC_RELEASE(_options);
_options = nil;
return NO;
}
#if TARGET_OS_IPHONE
if (_suspendInBackground) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_willEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
}
#endif
return YES;
} else {
DNOT_REACHED();
}
return NO;
}
- (BOOL)isRunning { - (BOOL)isRunning {
return (_source ? YES : NO); return (_source ? YES : NO);
} }
- (void)stop { - (void)stop {
DCHECK(_source != NULL); if (_options) {
if (_source) { #if TARGET_OS_IPHONE
if (_service) { if (_suspendInBackground) {
CFNetServiceUnscheduleFromRunLoop(_service, CFRunLoopGetMain(), kCFRunLoopCommonModes); [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
CFNetServiceSetClient(_service, NULL, NULL); [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
CFRelease(_service);
_service = NULL;
} }
#endif
dispatch_source_cancel(_source); // This will close the socket if (_source) {
ARC_DISPATCH_RELEASE(_source); [self _stop];
_source = NULL; }
ARC_RELEASE(_options);
LOG_INFO(@"%@ stopped", [self class]); _options = nil;
} else {
DNOT_REACHED();
} }
_port = 0;
}
@end
@implementation GCDWebServer (Subclassing)
+ (Class)connectionClass {
return [GCDWebServerConnection class];
}
+ (NSString*)serverName {
return NSStringFromClass(self);
}
+ (BOOL)shouldAutomaticallyMapHEADToGET {
return YES;
} }
@end @end
@@ -560,6 +597,7 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
#if !TARGET_OS_IPHONE #if !TARGET_OS_IPHONE
- (BOOL)runWithPort:(NSUInteger)port { - (BOOL)runWithPort:(NSUInteger)port {
DCHECK([NSThread isMainThread]);
BOOL success = NO; BOOL success = NO;
_run = YES; _run = YES;
void (*handler)(int) = signal(SIGINT, _SignalHandler); void (*handler)(int) = signal(SIGINT, _SignalHandler);
@@ -789,3 +827,186 @@ static void _NetServiceClientCallBack(CFNetServiceRef service, CFStreamError* er
} }
@end @end
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
@implementation GCDWebServer (Testing)
- (void)setRecordingEnabled:(BOOL)flag {
_recording = flag;
}
- (BOOL)isRecordingEnabled {
return _recording;
}
static CFHTTPMessageRef _CreateHTTPMessageFromData(NSData* data, BOOL isRequest) {
CFHTTPMessageRef message = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, isRequest);
if (CFHTTPMessageAppendBytes(message, data.bytes, data.length)) {
return message;
}
CFRelease(message);
return NULL;
}
static CFHTTPMessageRef _CreateHTTPMessageFromPerformingRequest(NSData* inData, NSUInteger port) {
CFHTTPMessageRef response = NULL;
int httpSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (httpSocket > 0) {
struct sockaddr_in addr4;
bzero(&addr4, sizeof(addr4));
addr4.sin_len = sizeof(port);
addr4.sin_family = AF_INET;
addr4.sin_port = htons(8080);
addr4.sin_addr.s_addr = htonl(INADDR_ANY);
if (connect(httpSocket, (void*)&addr4, sizeof(addr4)) == 0) {
if (write(httpSocket, inData.bytes, inData.length) == (ssize_t)inData.length) {
NSMutableData* outData = [[NSMutableData alloc] initWithLength:(256 * 1024)];
NSUInteger length = 0;
while (1) {
ssize_t result = read(httpSocket, (char*)outData.mutableBytes + length, outData.length - length);
if (result < 0) {
length = NSNotFound;
break;
} else if (result == 0) {
break;
}
length += result;
if (length >= outData.length) {
outData.length = 2 * outData.length;
}
}
if (length != NSNotFound) {
outData.length = length;
response = _CreateHTTPMessageFromData(outData, NO);
} else {
DNOT_REACHED();
}
ARC_RELEASE(outData);
}
}
close(httpSocket);
}
return response;
}
static void _LogResult(NSString* format, ...) {
va_list arguments;
va_start(arguments, format);
NSString* message = [[NSString alloc] initWithFormat:format arguments:arguments];
va_end(arguments);
fprintf(stdout, "%s\n", [message UTF8String]);
ARC_RELEASE(message);
}
- (NSInteger)runTestsInDirectory:(NSString*)path withPort:(NSUInteger)port {
NSArray* ignoredHeaders = @[@"Date", @"Etag"]; // Dates are always different by definition and ETags depend on file system node IDs
NSInteger result = -1;
if ([self startWithPort:port bonjourName:nil]) {
result = 0;
NSArray* files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
for (NSString* requestFile in files) {
if (![requestFile hasSuffix:@".request"]) {
continue;
}
@autoreleasepool {
NSString* index = [[requestFile componentsSeparatedByString:@"-"] firstObject];
BOOL success = NO;
NSData* requestData = [NSData dataWithContentsOfFile:[path stringByAppendingPathComponent:requestFile]];
if (requestData) {
CFHTTPMessageRef request = _CreateHTTPMessageFromData(requestData, YES);
if (request) {
NSString* requestMethod = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyRequestMethod(request));
NSURL* requestURL = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyRequestURL(request));
_LogResult(@"[%i] %@ %@", (int)[index integerValue], requestMethod, requestURL.path);
NSString* prefix = [index stringByAppendingString:@"-"];
for (NSString* responseFile in files) {
if ([responseFile hasPrefix:prefix] && [responseFile hasSuffix:@".response"]) {
NSData* responseData = [NSData dataWithContentsOfFile:[path stringByAppendingPathComponent:responseFile]];
if (responseData) {
CFHTTPMessageRef expectedResponse = _CreateHTTPMessageFromData(responseData, NO);
if (expectedResponse) {
CFHTTPMessageRef actualResponse = _CreateHTTPMessageFromPerformingRequest(requestData, port);
if (actualResponse) {
success = YES;
CFIndex expectedStatusCode = CFHTTPMessageGetResponseStatusCode(expectedResponse);
CFIndex actualStatusCode = CFHTTPMessageGetResponseStatusCode(actualResponse);
if (actualStatusCode != expectedStatusCode) {
_LogResult(@" Status code not matching:\n Expected: %i\n Actual: %i", (int)expectedStatusCode, (int)actualStatusCode);
success = NO;
}
NSDictionary* expectedHeaders = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyAllHeaderFields(expectedResponse));
NSDictionary* actualHeaders = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyAllHeaderFields(actualResponse));
for (NSString* expectedHeader in expectedHeaders) {
if ([ignoredHeaders containsObject:expectedHeader]) {
continue;
}
NSString* expectedValue = [expectedHeaders objectForKey:expectedHeader];
NSString* actualValue = [actualHeaders objectForKey:expectedHeader];
if (![actualValue isEqualToString:expectedValue]) {
_LogResult(@" Header '%@' not matching:\n Expected: \"%@\"\n Actual: \"%@\"", expectedHeader, expectedValue, actualValue);
success = NO;
}
}
for (NSString* actualHeader in actualHeaders) {
if (![expectedHeaders objectForKey:actualHeader]) {
_LogResult(@" Header '%@' not matching:\n Expected: \"%@\"\n Actual: \"%@\"", actualHeader, nil, [actualHeaders objectForKey:actualHeader]);
success = NO;
}
}
NSData* expectedBody = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyBody(expectedResponse));
NSData* actualBody = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyBody(actualResponse));
if (![actualBody isEqualToData:expectedBody]) {
_LogResult(@" Bodies not matching:\n Expected: %lu bytes\n Actual: %lu bytes", (unsigned long)expectedBody.length, (unsigned long)actualBody.length);
success = NO;
#if !TARGET_OS_IPHONE
#ifndef NDEBUG
if (GCDWebServerIsTextContentType([expectedHeaders objectForKey:@"Content-Type"])) {
NSString* expectedPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];
NSString* actualPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];
if ([expectedBody writeToFile:expectedPath atomically:YES] && [actualBody writeToFile:actualPath atomically:YES]) {
NSTask* task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/opendiff"];
[task setArguments:@[expectedPath, actualPath]];
[task launch];
ARC_RELEASE(task);
}
}
#endif
#endif
}
CFRelease(actualResponse);
}
CFRelease(expectedResponse);
}
} else {
DNOT_REACHED();
}
break;
}
}
CFRelease(request);
}
} else {
DNOT_REACHED();
}
_LogResult(@"");
if (!success) {
++result;
}
}
}
[self stop];
}
return result;
}
@end
#endif

View File

@@ -39,10 +39,11 @@
@property(nonatomic, readonly) NSUInteger totalBytesWritten; @property(nonatomic, readonly) NSUInteger totalBytesWritten;
@end @end
// These methods can be called from any thread
@interface GCDWebServerConnection (Subclassing) @interface GCDWebServerConnection (Subclassing)
- (void)open; - (BOOL)open; // Return NO to reject connection e.g. after validating local or remote addresses
- (void)didUpdateBytesRead; // Called from arbitrary thread after @totalBytesRead is updated - Default implementation does nothing - (void)didReadBytes:(const void*)bytes length:(NSUInteger)length; // Called after data has been read from the connection
- (void)didUpdateBytesWritten; // Called from arbitrary thread after @totalBytesWritten is updated - Default implementation does nothing - (void)didWriteBytes:(const void*)bytes length:(NSUInteger)length; // Called after data has been written to the connection
- (GCDWebServerResponse*)processRequest:(GCDWebServerRequest*)request withBlock:(GCDWebServerProcessBlock)block; // Only called if the request can be processed - (GCDWebServerResponse*)processRequest:(GCDWebServerRequest*)request withBlock:(GCDWebServerProcessBlock)block; // Only called if the request can be processed
- (GCDWebServerResponse*)replaceResponse:(GCDWebServerResponse*)response forRequest:(GCDWebServerRequest*)request; // Default implementation replaces any response matching the "ETag" or "Last-Modified-Date" header of the request by a barebone "Not-Modified" (304) one - (GCDWebServerResponse*)replaceResponse:(GCDWebServerResponse*)response forRequest:(GCDWebServerRequest*)request; // Default implementation replaces any response matching the "ETag" or "Last-Modified-Date" header of the request by a barebone "Not-Modified" (304) one
- (void)abortRequest:(GCDWebServerRequest*)request withStatusCode:(NSInteger)statusCode; // If request headers was malformed, "request" will be nil - (void)abortRequest:(GCDWebServerRequest*)request withStatusCode:(NSInteger)statusCode; // If request headers was malformed, "request" will be nil

View File

@@ -25,18 +25,21 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#import <TargetConditionals.h>
#import <netdb.h> #import <netdb.h>
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
#import <libkern/OSAtomic.h>
#endif
#import "GCDWebServerPrivate.h" #import "GCDWebServerPrivate.h"
#define kHeadersReadBuffer 1024 #define kHeadersReadCapacity (1 * 1024)
#define kBodyReadCapacity (256 * 1024)
typedef void (^ReadBufferCompletionBlock)(dispatch_data_t buffer); typedef void (^ReadDataCompletionBlock)(BOOL success);
typedef void (^ReadDataCompletionBlock)(NSData* data);
typedef void (^ReadHeadersCompletionBlock)(NSData* extraData); typedef void (^ReadHeadersCompletionBlock)(NSData* extraData);
typedef void (^ReadBodyCompletionBlock)(BOOL success); typedef void (^ReadBodyCompletionBlock)(BOOL success);
typedef void (^WriteBufferCompletionBlock)(BOOL success);
typedef void (^WriteDataCompletionBlock)(BOOL success); typedef void (^WriteDataCompletionBlock)(BOOL success);
typedef void (^WriteHeadersCompletionBlock)(BOOL success); typedef void (^WriteHeadersCompletionBlock)(BOOL success);
typedef void (^WriteBodyCompletionBlock)(BOOL success); typedef void (^WriteBodyCompletionBlock)(BOOL success);
@@ -45,6 +48,9 @@ static NSData* _CRLFData = nil;
static NSData* _CRLFCRLFData = nil; static NSData* _CRLFCRLFData = nil;
static NSData* _continueData = nil; static NSData* _continueData = nil;
static NSData* _lastChunkData = nil; static NSData* _lastChunkData = nil;
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
static int32_t _connectionCounter = 0;
#endif
@interface GCDWebServerConnection () { @interface GCDWebServerConnection () {
@private @private
@@ -62,80 +68,64 @@ static NSData* _lastChunkData = nil;
CFHTTPMessageRef _responseMessage; CFHTTPMessageRef _responseMessage;
GCDWebServerResponse* _response; GCDWebServerResponse* _response;
NSInteger _statusCode; NSInteger _statusCode;
BOOL _opened;
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
NSUInteger _connectionIndex;
NSString* _requestPath;
int _requestFD;
NSString* _responsePath;
int _responseFD;
#endif
} }
@end @end
@implementation GCDWebServerConnection (Read) @implementation GCDWebServerConnection (Read)
- (void)_readBufferWithLength:(NSUInteger)length completionBlock:(ReadBufferCompletionBlock)block { - (void)_readData:(NSMutableData*)data withLength:(NSUInteger)length completionBlock:(ReadDataCompletionBlock)block {
dispatch_read(_socket, length, kGCDWebServerGCDQueue, ^(dispatch_data_t buffer, int error) { dispatch_read(_socket, length, kGCDWebServerGCDQueue, ^(dispatch_data_t buffer, int error) {
@autoreleasepool { @autoreleasepool {
if (error == 0) { if (error == 0) {
size_t size = dispatch_data_get_size(buffer); size_t size = dispatch_data_get_size(buffer);
if (size > 0) { if (size > 0) {
LOG_DEBUG(@"Connection received %zu bytes on socket %i", size, _socket); NSUInteger originalLength = data.length;
_bytesRead += size; dispatch_data_apply(buffer, ^bool(dispatch_data_t region, size_t chunkOffset, const void* chunkBytes, size_t chunkSize) {
[self didUpdateBytesRead]; [data appendBytes:chunkBytes length:chunkSize];
block(buffer); return true;
});
[self didReadBytes:((char*)data.bytes + originalLength) length:(data.length - originalLength)];
block(YES);
} else { } else {
if (_bytesRead > 0) { if (_bytesRead > 0) {
LOG_ERROR(@"No more data available on socket %i", _socket); LOG_ERROR(@"No more data available on socket %i", _socket);
} else { } else {
LOG_WARNING(@"No data received from socket %i", _socket); LOG_WARNING(@"No data received from socket %i", _socket);
} }
block(NULL); block(NO);
} }
} else { } else {
LOG_ERROR(@"Error while reading from socket %i: %s (%i)", _socket, strerror(error), error); LOG_ERROR(@"Error while reading from socket %i: %s (%i)", _socket, strerror(error), error);
block(NULL); block(NO);
} }
} }
}); });
} }
- (void)_readDataWithCompletionBlock:(ReadDataCompletionBlock)block { - (void)_readHeaders:(NSMutableData*)headersData withCompletionBlock:(ReadHeadersCompletionBlock)block {
[self _readBufferWithLength:SIZE_T_MAX completionBlock:^(dispatch_data_t buffer) {
if (buffer) {
NSMutableData* data = [[NSMutableData alloc] initWithCapacity:dispatch_data_get_size(buffer)];
dispatch_data_apply(buffer, ^bool(dispatch_data_t region, size_t offset, const void* bufferChunk, size_t size) {
[data appendBytes:bufferChunk length:size];
return true;
});
block(data);
ARC_RELEASE(data);
} else {
block(nil);
}
}];
}
- (void)_readHeadersWithCompletionBlock:(ReadHeadersCompletionBlock)block {
DCHECK(_requestMessage); DCHECK(_requestMessage);
[self _readBufferWithLength:SIZE_T_MAX completionBlock:^(dispatch_data_t buffer) { [self _readData:headersData withLength:NSUIntegerMax completionBlock:^(BOOL success) {
if (buffer) { if (success) {
NSMutableData* data = [NSMutableData dataWithCapacity:kHeadersReadBuffer]; NSRange range = [headersData rangeOfData:_CRLFCRLFData options:0 range:NSMakeRange(0, headersData.length)];
dispatch_data_apply(buffer, ^bool(dispatch_data_t region, size_t offset, const void* bufferChunk, size_t size) {
[data appendBytes:bufferChunk length:size];
return true;
});
NSRange range = [data rangeOfData:_CRLFCRLFData options:0 range:NSMakeRange(0, data.length)];
if (range.location == NSNotFound) { if (range.location == NSNotFound) {
if (CFHTTPMessageAppendBytes(_requestMessage, data.bytes, data.length)) { [self _readHeaders:headersData withCompletionBlock:block];
[self _readHeadersWithCompletionBlock:block];
} else {
LOG_ERROR(@"Failed appending request headers data from socket %i", _socket);
block(nil);
}
} else { } else {
NSUInteger length = range.location + range.length; NSUInteger length = range.location + range.length;
if (CFHTTPMessageAppendBytes(_requestMessage, data.bytes, length)) { if (CFHTTPMessageAppendBytes(_requestMessage, headersData.bytes, length)) {
if (CFHTTPMessageIsHeaderComplete(_requestMessage)) { if (CFHTTPMessageIsHeaderComplete(_requestMessage)) {
block([data subdataWithRange:NSMakeRange(length, data.length - length)]); block([headersData subdataWithRange:NSMakeRange(length, headersData.length - length)]);
} else { } else {
LOG_ERROR(@"Failed parsing request headers from socket %i", _socket); LOG_ERROR(@"Failed parsing request headers from socket %i", _socket);
block(nil); block(nil);
@@ -154,27 +144,21 @@ static NSData* _lastChunkData = nil;
- (void)_readBodyWithRemainingLength:(NSUInteger)length completionBlock:(ReadBodyCompletionBlock)block { - (void)_readBodyWithRemainingLength:(NSUInteger)length completionBlock:(ReadBodyCompletionBlock)block {
DCHECK([_request hasBody] && ![_request usesChunkedTransferEncoding]); DCHECK([_request hasBody] && ![_request usesChunkedTransferEncoding]);
[self _readBufferWithLength:length completionBlock:^(dispatch_data_t buffer) { NSMutableData* bodyData = [[NSMutableData alloc] initWithCapacity:kBodyReadCapacity];
[self _readData:bodyData withLength:length completionBlock:^(BOOL success) {
if (buffer) { if (success) {
if (dispatch_data_get_size(buffer) <= length) { if (bodyData.length <= length) {
bool success = dispatch_data_apply(buffer, ^bool(dispatch_data_t region, size_t offset, const void* chunkBytes, size_t chunkSize) { NSError* error = nil;
NSData* data = [NSData dataWithBytesNoCopy:(void*)chunkBytes length:chunkSize freeWhenDone:NO]; if ([_request performWriteData:bodyData error:&error]) {
NSError* error = nil; NSUInteger remainingLength = length - bodyData.length;
if (![_request performWriteData:data error:&error]) {
LOG_ERROR(@"Failed writing request body on socket %i: %@", _socket, error);
return false;
}
return true;
});
if (success) {
NSUInteger remainingLength = length - dispatch_data_get_size(buffer);
if (remainingLength) { if (remainingLength) {
[self _readBodyWithRemainingLength:remainingLength completionBlock:block]; [self _readBodyWithRemainingLength:remainingLength completionBlock:block];
} else { } else {
block(YES); block(YES);
} }
} else { } else {
LOG_ERROR(@"Failed writing request body on socket %i: %@", _socket, error);
block(NO); block(NO);
} }
} else { } else {
@@ -187,6 +171,7 @@ static NSData* _lastChunkData = nil;
} }
}]; }];
ARC_RELEASE(bodyData);
} }
static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) { static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
@@ -242,13 +227,9 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
} }
} }
[self _readBufferWithLength:SIZE_T_MAX completionBlock:^(dispatch_data_t buffer) { [self _readData:chunkData withLength:NSUIntegerMax completionBlock:^(BOOL success) {
if (buffer) { if (success) {
dispatch_data_apply(buffer, ^bool(dispatch_data_t region, size_t offset, const void* chunkBytes, size_t chunkSize) {
[chunkData appendBytes:chunkBytes length:chunkSize];
return true;
});
[self _readNextBodyChunk:chunkData completionBlock:block]; [self _readNextBodyChunk:chunkData completionBlock:block];
} else { } else {
block(NO); block(NO);
@@ -261,16 +242,23 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
@implementation GCDWebServerConnection (Write) @implementation GCDWebServerConnection (Write)
- (void)_writeBuffer:(dispatch_data_t)buffer withCompletionBlock:(WriteBufferCompletionBlock)block { - (void)_writeData:(NSData*)data withCompletionBlock:(WriteDataCompletionBlock)block {
size_t size = dispatch_data_get_size(buffer); #if !__has_feature(objc_arc)
dispatch_write(_socket, buffer, kGCDWebServerGCDQueue, ^(dispatch_data_t data, int error) { [data retain];
#endif
dispatch_data_t buffer = dispatch_data_create(data.bytes, data.length, kGCDWebServerGCDQueue, ^{
#if __has_feature(objc_arc)
[data self]; // Keeps ARC from releasing data too early
#else
[data release];
#endif
});
dispatch_write(_socket, buffer, kGCDWebServerGCDQueue, ^(dispatch_data_t remainingData, int error) {
@autoreleasepool { @autoreleasepool {
if (error == 0) { if (error == 0) {
DCHECK(data == NULL); DCHECK(remainingData == NULL);
LOG_DEBUG(@"Connection sent %zu bytes on socket %i", size, _socket); [self didWriteBytes:data.bytes length:data.length];
_bytesWritten += size;
[self didUpdateBytesWritten];
block(YES); block(YES);
} else { } else {
LOG_ERROR(@"Error while writing to socket %i: %s (%i)", _socket, strerror(error), error); LOG_ERROR(@"Error while writing to socket %i: %s (%i)", _socket, strerror(error), error);
@@ -279,28 +267,14 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
} }
}); });
}
- (void)_writeData:(NSData*)data withCompletionBlock:(WriteDataCompletionBlock)block {
#if !__has_feature(objc_arc)
[data retain];
#endif
dispatch_data_t buffer = dispatch_data_create(data.bytes, data.length, dispatch_get_main_queue(), ^{
#if __has_feature(objc_arc)
[data self]; // Keeps ARC from releasing data too early
#else
[data release];
#endif
});
[self _writeBuffer:buffer withCompletionBlock:block];
ARC_DISPATCH_RELEASE(buffer); ARC_DISPATCH_RELEASE(buffer);
} }
- (void)_writeHeadersWithCompletionBlock:(WriteHeadersCompletionBlock)block { - (void)_writeHeadersWithCompletionBlock:(WriteHeadersCompletionBlock)block {
DCHECK(_responseMessage); DCHECK(_responseMessage);
CFDataRef message = CFHTTPMessageCopySerializedMessage(_responseMessage); CFDataRef data = CFHTTPMessageCopySerializedMessage(_responseMessage);
[self _writeData:(ARC_BRIDGE NSData*)message withCompletionBlock:block]; [self _writeData:(ARC_BRIDGE NSData*)data withCompletionBlock:block];
CFRelease(message); CFRelease(data);
} }
- (void)_writeBodyWithCompletionBlock:(WriteBodyCompletionBlock)block { - (void)_writeBodyWithCompletionBlock:(WriteBodyCompletionBlock)block {
@@ -389,8 +363,8 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
_statusCode = statusCode; _statusCode = statusCode;
_responseMessage = CFHTTPMessageCreateResponse(kCFAllocatorDefault, statusCode, NULL, kCFHTTPVersion1_1); _responseMessage = CFHTTPMessageCreateResponse(kCFAllocatorDefault, statusCode, NULL, kCFHTTPVersion1_1);
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Connection"), CFSTR("Close")); CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Connection"), CFSTR("Close"));
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Server"), (ARC_BRIDGE CFStringRef)[[_server class] serverName]); CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Server"), (ARC_BRIDGE CFStringRef)_server.serverName);
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Date"), (ARC_BRIDGE CFStringRef)GCDWebServerFormatHTTPDate([NSDate date])); CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Date"), (ARC_BRIDGE CFStringRef)GCDWebServerFormatRFC822([NSDate date]));
} }
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
@@ -418,7 +392,7 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
if (_response) { if (_response) {
[self _initializeResponseHeadersWithStatusCode:_response.statusCode]; [self _initializeResponseHeadersWithStatusCode:_response.statusCode];
if (_response.lastModifiedDate) { if (_response.lastModifiedDate) {
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Last-Modified"), (ARC_BRIDGE CFStringRef)GCDWebServerFormatHTTPDate(_response.lastModifiedDate)); CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Last-Modified"), (ARC_BRIDGE CFStringRef)GCDWebServerFormatRFC822(_response.lastModifiedDate));
} }
if (_response.eTag) { if (_response.eTag) {
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("ETag"), (ARC_BRIDGE CFStringRef)_response.eTag); CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("ETag"), (ARC_BRIDGE CFStringRef)_response.eTag);
@@ -530,79 +504,78 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
- (void)_readRequestHeaders { - (void)_readRequestHeaders {
_requestMessage = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, true); _requestMessage = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, true);
[self _readHeadersWithCompletionBlock:^(NSData* extraData) { NSMutableData* headersData = [[NSMutableData alloc] initWithCapacity:kHeadersReadCapacity];
[self _readHeaders:headersData withCompletionBlock:^(NSData* extraData) {
if (extraData) { if (extraData) {
NSString* requestMethod = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyRequestMethod(_requestMessage)); // Method verbs are case-sensitive and uppercase NSString* requestMethod = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyRequestMethod(_requestMessage)); // Method verbs are case-sensitive and uppercase
DCHECK(requestMethod); if (_server.shouldAutomaticallyMapHEADToGET && [requestMethod isEqualToString:@"HEAD"]) {
if ([[_server class] shouldAutomaticallyMapHEADToGET] && [requestMethod isEqualToString:@"HEAD"]) {
requestMethod = @"GET"; requestMethod = @"GET";
_virtualHEAD = YES; _virtualHEAD = YES;
} }
NSURL* requestURL = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyRequestURL(_requestMessage)); NSURL* requestURL = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyRequestURL(_requestMessage));
DCHECK(requestURL); NSString* requestPath = requestURL ? GCDWebServerUnescapeURLString(ARC_BRIDGE_RELEASE(CFURLCopyPath((CFURLRef)requestURL))) : nil; // Don't use -[NSURL path] which strips the ending slash
NSString* requestPath = GCDWebServerUnescapeURLString(ARC_BRIDGE_RELEASE(CFURLCopyPath((CFURLRef)requestURL))); // Don't use -[NSURL path] which strips the ending slash NSString* queryString = requestURL ? ARC_BRIDGE_RELEASE(CFURLCopyQueryString((CFURLRef)requestURL, NULL)) : nil; // Don't use -[NSURL query] to make sure query is not unescaped;
DCHECK(requestPath); NSDictionary* requestQuery = queryString ? GCDWebServerParseURLEncodedForm(queryString) : @{};
NSDictionary* requestQuery = nil;
NSString* queryString = ARC_BRIDGE_RELEASE(CFURLCopyQueryString((CFURLRef)requestURL, NULL)); // Don't use -[NSURL query] to make sure query is not unescaped;
if (queryString.length) {
requestQuery = GCDWebServerParseURLEncodedForm(queryString);
DCHECK(requestQuery);
}
NSDictionary* requestHeaders = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyAllHeaderFields(_requestMessage)); // Header names are case-insensitive but CFHTTPMessageCopyAllHeaderFields() will standardize the common ones NSDictionary* requestHeaders = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyAllHeaderFields(_requestMessage)); // Header names are case-insensitive but CFHTTPMessageCopyAllHeaderFields() will standardize the common ones
DCHECK(requestHeaders); if (requestMethod && requestURL && requestHeaders && requestPath && requestQuery) {
for (_handler in _server.handlers) { for (_handler in _server.handlers) {
_request = ARC_RETAIN(_handler.matchBlock(requestMethod, requestURL, requestHeaders, requestPath, requestQuery)); _request = ARC_RETAIN(_handler.matchBlock(requestMethod, requestURL, requestHeaders, requestPath, requestQuery));
if (_request) { if (_request) {
break; break;
}
} }
} if (_request) {
if (_request) { if ([_request hasBody]) {
if ([_request hasBody]) { [_request prepareForWriting];
[_request prepareForWriting]; if (_request.usesChunkedTransferEncoding || (extraData.length <= _request.contentLength)) {
if (_request.usesChunkedTransferEncoding || (extraData.length <= _request.contentLength)) { NSString* expectHeader = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyHeaderFieldValue(_requestMessage, CFSTR("Expect")));
NSString* expectHeader = ARC_BRIDGE_RELEASE(CFHTTPMessageCopyHeaderFieldValue(_requestMessage, CFSTR("Expect"))); if (expectHeader) {
if (expectHeader) { if ([expectHeader caseInsensitiveCompare:@"100-continue"] == NSOrderedSame) {
if ([expectHeader caseInsensitiveCompare:@"100-continue"] == NSOrderedSame) { [self _writeData:_continueData withCompletionBlock:^(BOOL success) {
[self _writeData:_continueData withCompletionBlock:^(BOOL success) {
if (success) { if (success) {
if (_request.usesChunkedTransferEncoding) { if (_request.usesChunkedTransferEncoding) {
[self _readChunkedBodyWithInitialData:extraData]; [self _readChunkedBodyWithInitialData:extraData];
} else { } else {
[self _readBodyWithLength:_request.contentLength initialData:extraData]; [self _readBodyWithLength:_request.contentLength initialData:extraData];
}
} }
}
}]; }];
} else {
LOG_ERROR(@"Unsupported 'Expect' / 'Content-Length' header combination on socket %i", _socket);
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_ExpectationFailed];
}
} else { } else {
LOG_ERROR(@"Unsupported 'Expect' / 'Content-Length' header combination on socket %i", _socket); if (_request.usesChunkedTransferEncoding) {
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_ExpectationFailed]; [self _readChunkedBodyWithInitialData:extraData];
} else {
[self _readBodyWithLength:_request.contentLength initialData:extraData];
}
} }
} else { } else {
if (_request.usesChunkedTransferEncoding) { LOG_ERROR(@"Unexpected 'Content-Length' header value on socket %i", _socket);
[self _readChunkedBodyWithInitialData:extraData]; [self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_BadRequest];
} else {
[self _readBodyWithLength:_request.contentLength initialData:extraData];
}
} }
} else { } else {
LOG_ERROR(@"Unexpected 'Content-Length' header value on socket %i", _socket); [self _processRequest];
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_BadRequest];
} }
} else { } else {
[self _processRequest]; _request = [[GCDWebServerRequest alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:requestPath query:requestQuery];
DCHECK(_request);
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_MethodNotAllowed];
} }
} else { } else {
_request = [[GCDWebServerRequest alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:requestPath query:requestQuery]; [self abortRequest:nil withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError];
DCHECK(_request); DNOT_REACHED();
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_MethodNotAllowed];
} }
} else { } else {
[self abortRequest:nil withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError]; [self abortRequest:nil withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError];
} }
}]; }];
ARC_RELEASE(headersData);
} }
- (id)initWithServer:(GCDWebServer*)server localAddress:(NSData*)localAddress remoteAddress:(NSData*)remoteAddress socket:(CFSocketNativeHandle)socket { - (id)initWithServer:(GCDWebServer*)server localAddress:(NSData*)localAddress remoteAddress:(NSData*)remoteAddress socket:(CFSocketNativeHandle)socket {
@@ -611,8 +584,18 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
_localAddress = ARC_RETAIN(localAddress); _localAddress = ARC_RETAIN(localAddress);
_remoteAddress = ARC_RETAIN(remoteAddress); _remoteAddress = ARC_RETAIN(remoteAddress);
_socket = socket; _socket = socket;
LOG_DEBUG(@"Did open connection on socket %i", _socket);
[self open]; [_server willStartConnection:self];
if (![self open]) {
close(_socket);
ARC_RELEASE(self);
return nil;
}
_opened = YES;
[self _readRequestHeaders];
} }
return self; return self;
} }
@@ -639,8 +622,18 @@ static NSString* _StringFromAddressData(NSData* data) {
} }
- (void)dealloc { - (void)dealloc {
[self close]; int result = close(_socket);
if (result != 0) {
LOG_ERROR(@"Failed closing socket %i for connection: %s (%i)", _socket, strerror(errno), errno);
} else {
LOG_DEBUG(@"Did close connection on socket %i", _socket);
}
if (_opened) {
[self close];
}
[_server didEndConnection:self];
ARC_RELEASE(_server); ARC_RELEASE(_server);
ARC_RELEASE(_localAddress); ARC_RELEASE(_localAddress);
ARC_RELEASE(_remoteAddress); ARC_RELEASE(_remoteAddress);
@@ -655,6 +648,11 @@ static NSString* _StringFromAddressData(NSData* data) {
} }
ARC_RELEASE(_response); ARC_RELEASE(_response);
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
ARC_RELEASE(_requestPath);
ARC_RELEASE(_responsePath);
#endif
ARC_DEALLOC(super); ARC_DEALLOC(super);
} }
@@ -662,17 +660,48 @@ static NSString* _StringFromAddressData(NSData* data) {
@implementation GCDWebServerConnection (Subclassing) @implementation GCDWebServerConnection (Subclassing)
- (void)open { - (BOOL)open {
LOG_DEBUG(@"Did open connection on socket %i", _socket); #ifdef __GCDWEBSERVER_ENABLE_TESTING__
[self _readRequestHeaders]; if (_server.recordingEnabled) {
_connectionIndex = OSAtomicIncrement32(&_connectionCounter);
_requestPath = ARC_RETAIN([NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]);
_requestFD = open([_requestPath fileSystemRepresentation], O_CREAT | O_TRUNC | O_WRONLY);
DCHECK(_requestFD > 0);
_responsePath = ARC_RETAIN([NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]);
_responseFD = open([_responsePath fileSystemRepresentation], O_CREAT | O_TRUNC | O_WRONLY);
DCHECK(_responseFD > 0);
}
#endif
return YES;
} }
- (void)didUpdateBytesRead { - (void)didReadBytes:(const void*)bytes length:(NSUInteger)length {
; LOG_DEBUG(@"Connection received %lu bytes on socket %i", (unsigned long)length, _socket);
_bytesRead += length;
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
if ((_requestFD > 0) && (write(_requestFD, bytes, length) != (ssize_t)length)) {
LOG_ERROR(@"Failed recording request data: %s (%i)", strerror(errno), errno);
close(_requestFD);
_requestFD = 0;
}
#endif
} }
- (void)didUpdateBytesWritten { - (void)didWriteBytes:(const void*)bytes length:(NSUInteger)length {
; LOG_DEBUG(@"Connection sent %lu bytes on socket %i", (unsigned long)length, _socket);
_bytesWritten += length;
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
if ((_responseFD > 0) && (write(_responseFD, bytes, length) != (ssize_t)length)) {
LOG_ERROR(@"Failed recording response data: %s (%i)", strerror(errno), errno);
close(_responseFD);
_responseFD = 0;
}
#endif
} }
- (GCDWebServerResponse*)processRequest:(GCDWebServerRequest*)request withBlock:(GCDWebServerProcessBlock)block { - (GCDWebServerResponse*)processRequest:(GCDWebServerRequest*)request withBlock:(GCDWebServerProcessBlock)block {
@@ -726,13 +755,43 @@ static inline BOOL _CompareResources(NSString* responseETag, NSString* requestET
} }
- (void)close { - (void)close {
int result = close(_socket); #ifdef __GCDWEBSERVER_ENABLE_TESTING__
if (result != 0) { if (_requestPath) {
LOG_ERROR(@"Failed closing socket %i for connection (%i): %s", _socket, errno, strerror(errno)); BOOL success = NO;
} else { NSError* error = nil;
LOG_DEBUG(@"Did close connection on socket %i", _socket); if (_requestFD > 0) {
close(_requestFD);
NSString* name = [NSString stringWithFormat:@"%03lu-%@.request", (unsigned long)_connectionIndex, _virtualHEAD ? @"HEAD" : _request.method];
success = [[NSFileManager defaultManager] moveItemAtPath:_requestPath toPath:[[[NSFileManager defaultManager] currentDirectoryPath] stringByAppendingPathComponent:name] error:&error];
}
if (!success) {
LOG_ERROR(@"Failed saving recorded request: %@", error);
DNOT_REACHED();
}
unlink([_requestPath fileSystemRepresentation]);
}
if (_responsePath) {
BOOL success = NO;
NSError* error = nil;
if (_responseFD > 0) {
close(_responseFD);
NSString* name = [NSString stringWithFormat:@"%03lu-%i.response", (unsigned long)_connectionIndex, (int)_statusCode];
success = [[NSFileManager defaultManager] moveItemAtPath:_responsePath toPath:[[[NSFileManager defaultManager] currentDirectoryPath] stringByAppendingPathComponent:name] error:&error];
}
if (!success) {
LOG_ERROR(@"Failed saving recorded response: %@", error);
DNOT_REACHED();
}
unlink([_responsePath fileSystemRepresentation]);
}
#endif
if (_request) {
LOG_VERBOSE(@"[%@] %@ %i \"%@ %@\" (%lu | %lu)", self.localAddressString, self.remoteAddressString, (int)_statusCode, _virtualHEAD ? @"HEAD" : _request.method, _request.path, (unsigned long)_bytesRead, (unsigned long)_bytesWritten);
} else {
LOG_VERBOSE(@"[%@] %@ %i \"(invalid request)\" (%lu | %lu)", self.localAddressString, self.remoteAddressString, (int)_statusCode, (unsigned long)_bytesRead, (unsigned long)_bytesWritten);
} }
LOG_VERBOSE(@"[%@] %@ %i \"%@ %@\" (%lu | %lu)", self.localAddressString, self.remoteAddressString, (int)_statusCode, _virtualHEAD ? @"HEAD" : _request.method, _request.path, (unsigned long)_bytesRead, (unsigned long)_bytesWritten);
} }
@end @end

View File

@@ -0,0 +1,46 @@
/*
Copyright (c) 2012-2014, Pierre-Olivier Latour
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* The name of Pierre-Olivier Latour may not be used to endorse
or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import <Foundation/Foundation.h>
#ifdef __cplusplus
extern "C" {
#endif
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension);
NSString* GCDWebServerEscapeURLString(NSString* string);
NSString* GCDWebServerUnescapeURLString(NSString* string);
NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form);
NSString* GCDWebServerGetPrimaryIPv4Address(); // Returns IPv4 address of primary connected service on OS X or of WiFi interface on iOS if connected
NSString* GCDWebServerFormatRFC822(NSDate* date);
NSDate* GCDWebServerParseRFC822(NSString* string);
NSString* GCDWebServerFormatISO8601(NSDate* date);
NSDate* GCDWebServerParseISO8601(NSString* string);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,268 @@
/*
Copyright (c) 2012-2014, Pierre-Olivier Latour
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* The name of Pierre-Olivier Latour may not be used to endorse
or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import <TargetConditionals.h>
#if TARGET_OS_IPHONE
#import <MobileCoreServices/MobileCoreServices.h>
#else
#import <SystemConfiguration/SystemConfiguration.h>
#endif
#import <ifaddrs.h>
#import <net/if.h>
#import <netdb.h>
#import "GCDWebServerPrivate.h"
static NSDateFormatter* _dateFormatterRFC822 = nil;
static NSDateFormatter* _dateFormatterISO8601 = nil;
static dispatch_queue_t _dateFormatterQueue = NULL;
// HTTP/1.1 server must use RFC822
// TODO: Handle RFC 850 and ANSI C's asctime() format (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3)
void GCDWebServerInitializeFunctions() {
DCHECK([NSThread isMainThread]); // NSDateFormatter should be initialized on main thread
if (_dateFormatterRFC822 == nil) {
_dateFormatterRFC822 = [[NSDateFormatter alloc] init];
_dateFormatterRFC822.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
_dateFormatterRFC822.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";
_dateFormatterRFC822.locale = ARC_AUTORELEASE([[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]);
DCHECK(_dateFormatterRFC822);
}
if (_dateFormatterISO8601 == nil) {
_dateFormatterISO8601 = [[NSDateFormatter alloc] init];
_dateFormatterISO8601.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
_dateFormatterISO8601.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'+00:00'";
_dateFormatterISO8601.locale = ARC_AUTORELEASE([[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]);
DCHECK(_dateFormatterISO8601);
}
if (_dateFormatterQueue == NULL) {
_dateFormatterQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
DCHECK(_dateFormatterQueue);
}
}
NSString* GCDWebServerNormalizeHeaderValue(NSString* value) {
if (value) {
NSRange range = [value rangeOfString:@";"]; // Assume part before ";" separator is case-insensitive
if (range.location != NSNotFound) {
value = [[[value substringToIndex:range.location] lowercaseString] stringByAppendingString:[value substringFromIndex:range.location]];
} else {
value = [value lowercaseString];
}
}
return value;
}
NSString* GCDWebServerTruncateHeaderValue(NSString* value) {
DCHECK([value isEqualToString:GCDWebServerNormalizeHeaderValue(value)]);
NSRange range = [value rangeOfString:@";"];
return range.location != NSNotFound ? [value substringToIndex:range.location] : value;
}
NSString* GCDWebServerExtractHeaderValueParameter(NSString* value, NSString* name) {
DCHECK([value isEqualToString:GCDWebServerNormalizeHeaderValue(value)]);
NSString* parameter = nil;
NSScanner* scanner = [[NSScanner alloc] initWithString:value];
[scanner setCaseSensitive:NO]; // Assume parameter names are case-insensitive
NSString* string = [NSString stringWithFormat:@"%@=", name];
if ([scanner scanUpToString:string intoString:NULL]) {
[scanner scanString:string intoString:NULL];
if ([scanner scanString:@"\"" intoString:NULL]) {
[scanner scanUpToString:@"\"" intoString:&parameter];
} else {
[scanner scanUpToCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:&parameter];
}
}
ARC_RELEASE(scanner);
return parameter;
}
// http://www.w3schools.com/tags/ref_charactersets.asp
NSStringEncoding GCDWebServerStringEncodingFromCharset(NSString* charset) {
NSStringEncoding encoding = kCFStringEncodingInvalidId;
if (charset) {
encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)charset));
}
return (encoding != kCFStringEncodingInvalidId ? encoding : NSUTF8StringEncoding);
}
NSString* GCDWebServerFormatRFC822(NSDate* date) {
__block NSString* string;
dispatch_sync(_dateFormatterQueue, ^{
string = [_dateFormatterRFC822 stringFromDate:date];
});
return string;
}
NSDate* GCDWebServerParseRFC822(NSString* string) {
__block NSDate* date;
dispatch_sync(_dateFormatterQueue, ^{
date = [_dateFormatterRFC822 dateFromString:string];
});
return date;
}
NSString* GCDWebServerFormatISO8601(NSDate* date) {
__block NSString* string;
dispatch_sync(_dateFormatterQueue, ^{
string = [_dateFormatterISO8601 stringFromDate:date];
});
return string;
}
NSDate* GCDWebServerParseISO8601(NSString* string) {
__block NSDate* date;
dispatch_sync(_dateFormatterQueue, ^{
date = [_dateFormatterISO8601 dateFromString:string];
});
return date;
}
BOOL GCDWebServerIsTextContentType(NSString* type) {
return ([type hasPrefix:@"text/"] || [type hasPrefix:@"application/json"] || [type hasPrefix:@"application/xml"]);
}
NSString* GCDWebServerDescribeData(NSData* data, NSString* type) {
if (GCDWebServerIsTextContentType(type)) {
NSString* charset = GCDWebServerExtractHeaderValueParameter(type, @"charset");
NSString* string = [[NSString alloc] initWithData:data encoding:GCDWebServerStringEncodingFromCharset(charset)];
if (string) {
return ARC_AUTORELEASE(string);
}
}
return [NSString stringWithFormat:@"<%lu bytes>", (unsigned long)data.length];
}
NSString* GCDWebServerGetMimeTypeForExtension(NSString* extension) {
static NSDictionary* _overrides = nil;
if (_overrides == nil) {
_overrides = [[NSDictionary alloc] initWithObjectsAndKeys:
@"text/css", @"css",
nil];
}
NSString* mimeType = nil;
extension = [extension lowercaseString];
if (extension.length) {
mimeType = [_overrides objectForKey:extension];
if (mimeType == nil) {
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (ARC_BRIDGE CFStringRef)extension, NULL);
if (uti) {
mimeType = ARC_BRIDGE_RELEASE(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));
CFRelease(uti);
}
}
}
return mimeType ? mimeType : kGCDWebServerDefaultMimeType;
}
NSString* GCDWebServerEscapeURLString(NSString* string) {
return ARC_BRIDGE_RELEASE(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR(":@/?&=+"), kCFStringEncodingUTF8));
}
NSString* GCDWebServerUnescapeURLString(NSString* string) {
return ARC_BRIDGE_RELEASE(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)string, CFSTR(""), kCFStringEncodingUTF8));
}
// http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form) {
NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
NSScanner* scanner = [[NSScanner alloc] initWithString:form];
[scanner setCharactersToBeSkipped:nil];
while (1) {
NSString* key = nil;
if (![scanner scanUpToString:@"=" intoString:&key] || [scanner isAtEnd]) {
break;
}
[scanner setScanLocation:([scanner scanLocation] + 1)];
NSString* value = nil;
if (![scanner scanUpToString:@"&" intoString:&value]) {
break;
}
key = [key stringByReplacingOccurrencesOfString:@"+" withString:@" "];
value = [value stringByReplacingOccurrencesOfString:@"+" withString:@" "];
if (key && value) {
[parameters setObject:GCDWebServerUnescapeURLString(value) forKey:GCDWebServerUnescapeURLString(key)];
} else {
DNOT_REACHED();
}
if ([scanner isAtEnd]) {
break;
}
[scanner setScanLocation:([scanner scanLocation] + 1)];
}
ARC_RELEASE(scanner);
return parameters;
}
NSString* GCDWebServerGetPrimaryIPv4Address() {
NSString* address = nil;
#if TARGET_OS_IPHONE
#if !TARGET_IPHONE_SIMULATOR
const char* primaryInterface = "en0"; // WiFi interface on iOS
#endif
#else
const char* primaryInterface = NULL;
SCDynamicStoreRef store = SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("GCDWebServer"), NULL, NULL);
if (store) {
CFPropertyListRef info = SCDynamicStoreCopyValue(store, CFSTR("State:/Network/Global/IPv4"));
if (info) {
primaryInterface = [[NSString stringWithString:[(ARC_BRIDGE NSDictionary*)info objectForKey:@"PrimaryInterface"]] UTF8String];
CFRelease(info);
}
CFRelease(store);
}
if (primaryInterface == NULL) {
primaryInterface = "lo0";
}
#endif
struct ifaddrs* list;
if (getifaddrs(&list) >= 0) {
for (struct ifaddrs* ifap = list; ifap; ifap = ifap->ifa_next) {
#if TARGET_IPHONE_SIMULATOR
if (strcmp(ifap->ifa_name, "en0") && strcmp(ifap->ifa_name, "en1")) // Assume en0 is Ethernet and en1 is WiFi since there is no way to use SystemConfiguration framework in iOS Simulator
#else
if (strcmp(ifap->ifa_name, primaryInterface))
#endif
{
continue;
}
if ((ifap->ifa_flags & IFF_UP) && (ifap->ifa_addr->sa_family == AF_INET)) {
char buffer[NI_MAXHOST];
if (getnameinfo(ifap->ifa_addr, ifap->ifa_addr->sa_len, buffer, sizeof(buffer), NULL, 0, NI_NUMERICHOST | NI_NOFQDN) >= 0) {
address = [NSString stringWithUTF8String:buffer];
}
break;
}
}
freeifaddrs(list);
}
return address;
}

View File

@@ -36,8 +36,10 @@
#define ARC_AUTORELEASE(__OBJECT__) __OBJECT__ #define ARC_AUTORELEASE(__OBJECT__) __OBJECT__
#define ARC_DEALLOC(__OBJECT__) #define ARC_DEALLOC(__OBJECT__)
#if (TARGET_OS_IPHONE && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0)) || (!TARGET_OS_IPHONE && (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_8)) #if (TARGET_OS_IPHONE && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0)) || (!TARGET_OS_IPHONE && (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_8))
#define ARC_DISPATCH_RETAIN(__OBJECT__)
#define ARC_DISPATCH_RELEASE(__OBJECT__) #define ARC_DISPATCH_RELEASE(__OBJECT__)
#else #else
#define ARC_DISPATCH_RETAIN(__OBJECT__) dispatch_retain(__OBJECT__)
#define ARC_DISPATCH_RELEASE(__OBJECT__) dispatch_release(__OBJECT__) #define ARC_DISPATCH_RELEASE(__OBJECT__) dispatch_release(__OBJECT__)
#endif #endif
#else #else
@@ -47,11 +49,14 @@
#define ARC_RELEASE(__OBJECT__) [__OBJECT__ release] #define ARC_RELEASE(__OBJECT__) [__OBJECT__ release]
#define ARC_AUTORELEASE(__OBJECT__) [__OBJECT__ autorelease] #define ARC_AUTORELEASE(__OBJECT__) [__OBJECT__ autorelease]
#define ARC_DEALLOC(__OBJECT__) [__OBJECT__ dealloc] #define ARC_DEALLOC(__OBJECT__) [__OBJECT__ dealloc]
#define ARC_DISPATCH_RETAIN(__OBJECT__) dispatch_retain(__OBJECT__)
#define ARC_DISPATCH_RELEASE(__OBJECT__) dispatch_release(__OBJECT__) #define ARC_DISPATCH_RELEASE(__OBJECT__) dispatch_release(__OBJECT__)
#endif #endif
#import "GCDWebServerHTTPStatusCodes.h" #import "GCDWebServerHTTPStatusCodes.h"
#import "GCDWebServerFunctions.h"
#import "GCDWebServer.h"
#import "GCDWebServerConnection.h" #import "GCDWebServerConnection.h"
#import "GCDWebServerDataRequest.h" #import "GCDWebServerDataRequest.h"
@@ -109,12 +114,12 @@ static inline BOOL GCDWebServerIsValidByteRange(NSRange range) {
return ((range.location != NSNotFound) || (range.length > 0)); return ((range.location != NSNotFound) || (range.length > 0));
} }
extern void GCDWebServerInitializeFunctions();
extern NSString* GCDWebServerNormalizeHeaderValue(NSString* value); extern NSString* GCDWebServerNormalizeHeaderValue(NSString* value);
extern NSString* GCDWebServerTruncateHeaderValue(NSString* value); extern NSString* GCDWebServerTruncateHeaderValue(NSString* value);
extern NSString* GCDWebServerExtractHeaderValueParameter(NSString* header, NSString* attribute); extern NSString* GCDWebServerExtractHeaderValueParameter(NSString* header, NSString* attribute);
extern NSStringEncoding GCDWebServerStringEncodingFromCharset(NSString* charset); extern NSStringEncoding GCDWebServerStringEncodingFromCharset(NSString* charset);
extern NSString* GCDWebServerFormatHTTPDate(NSDate* date); extern BOOL GCDWebServerIsTextContentType(NSString* type);
extern NSDate* GCDWebServerParseHTTPDate(NSString* string);
extern NSString* GCDWebServerDescribeData(NSData* data, NSString* contentType); extern NSString* GCDWebServerDescribeData(NSData* data, NSString* contentType);
@interface GCDWebServerConnection () @interface GCDWebServerConnection ()
@@ -123,6 +128,10 @@ extern NSString* GCDWebServerDescribeData(NSData* data, NSString* contentType);
@interface GCDWebServer () @interface GCDWebServer ()
@property(nonatomic, readonly) NSArray* handlers; @property(nonatomic, readonly) NSArray* handlers;
@property(nonatomic, readonly) NSString* serverName;
@property(nonatomic, readonly) BOOL shouldAutomaticallyMapHEADToGET;
- (void)willStartConnection:(GCDWebServerConnection*)connection;
- (void)didEndConnection:(GCDWebServerConnection*)connection;
@end @end
@interface GCDWebServerHandler : NSObject @interface GCDWebServerHandler : NSObject

View File

@@ -43,8 +43,8 @@
@property(nonatomic, readonly) NSUInteger contentLength; // Automatically parsed from headers (NSNotFound if request has no "Content-Length" header) @property(nonatomic, readonly) NSUInteger contentLength; // Automatically parsed from headers (NSNotFound if request has no "Content-Length" header)
@property(nonatomic, readonly) NSDate* ifModifiedSince; // Automatically parsed from headers (nil if request has no "If-Modified-Since" header or it is malformatted) @property(nonatomic, readonly) NSDate* ifModifiedSince; // Automatically parsed from headers (nil if request has no "If-Modified-Since" header or it is malformatted)
@property(nonatomic, readonly) NSString* ifNoneMatch; // Automatically parsed from headers (nil if request has no "If-None-Match" header) @property(nonatomic, readonly) NSString* ifNoneMatch; // Automatically parsed from headers (nil if request has no "If-None-Match" header)
@property(nonatomic, readonly) NSRange byteRange; // Automatically parsed from headers ([NSNotFound, 0] if request has no "Range" header, [offset, length] for byte range from beginning or [NSNotFound, -bytes] from end) @property(nonatomic, readonly) NSRange byteRange; // Automatically parsed from headers ([NSNotFound, 0] if request has no "Range" header, [offset, length] for byte range from beginning or [NSNotFound, -length] from end)
@property(nonatomic, readonly) BOOL acceptsGzipContentEncoding; @property(nonatomic, readonly) BOOL acceptsGzipContentEncoding; // Automatically parsed from headers
- (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*)headers path:(NSString*)path query:(NSDictionary*)query;
- (BOOL)hasBody; // Convenience method that checks if "contentType" is not nil - (BOOL)hasBody; // Convenience method that checks if "contentType" is not nil
- (BOOL)hasByteRange; // Convenience method that checks "byteRange" - (BOOL)hasByteRange; // Convenience method that checks "byteRange"

View File

@@ -199,7 +199,7 @@
NSString* modifiedHeader = [_headers objectForKey:@"If-Modified-Since"]; NSString* modifiedHeader = [_headers objectForKey:@"If-Modified-Since"];
if (modifiedHeader) { if (modifiedHeader) {
_modifiedSince = [GCDWebServerParseHTTPDate(modifiedHeader) copy]; _modifiedSince = [GCDWebServerParseRFC822(modifiedHeader) copy];
} }
_noneMatch = ARC_RETAIN([_headers objectForKey:@"If-None-Match"]); _noneMatch = ARC_RETAIN([_headers objectForKey:@"If-None-Match"]);

View File

@@ -78,6 +78,22 @@ static inline NSError* _MakePosixError(int code) {
*error = _MakePosixError(errno); *error = _MakePosixError(errno);
return NO; return NO;
} }
#ifdef __GCDWEBSERVER_ENABLE_TESTING__
NSString* creationDateHeader = [self.headers objectForKey:@"X-GCDWebServer-CreationDate"];
if (creationDateHeader) {
NSDate* date = GCDWebServerParseISO8601(creationDateHeader);
if (!date || ![[NSFileManager defaultManager] setAttributes:@{NSFileCreationDate: date} ofItemAtPath:_temporaryPath error:error]) {
return NO;
}
}
NSString* modifiedDateHeader = [self.headers objectForKey:@"X-GCDWebServer-ModifiedDate"];
if (modifiedDateHeader) {
NSDate* date = GCDWebServerParseRFC822(modifiedDateHeader);
if (!date || ![[NSFileManager defaultManager] setAttributes:@{NSFileModificationDate: date} ofItemAtPath:_temporaryPath error:error]) {
return NO;
}
}
#endif
return YES; return YES;
} }

View File

@@ -28,7 +28,7 @@
#import "GCDWebServerRequest.h" #import "GCDWebServerRequest.h"
@interface GCDWebServerMultiPart : NSObject @interface GCDWebServerMultiPart : NSObject
@property(nonatomic, readonly) NSString* contentType; // Defaults to "text/plain" per specifications if undefined @property(nonatomic, readonly) NSString* contentType; // Defaults to "text/plain" per specification if undefined
@property(nonatomic, readonly) NSString* mimeType; @property(nonatomic, readonly) NSString* mimeType;
@end @end

View File

@@ -33,7 +33,7 @@
+ (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range; + (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range;
+ (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment; + (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment;
- (instancetype)initWithFile:(NSString*)path; - (instancetype)initWithFile:(NSString*)path;
- (instancetype)initWithFile:(NSString*)path isAttachment:(BOOL)attachment; - (instancetype)initWithFile:(NSString*)path isAttachment:(BOOL)attachment; // If in attachment mode, "Content-Disposition" header will be set accordingly
- (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range; // Pass [NSNotFound, 0] to disable byte range entirely, [offset, length] to enable byte range from beginning of file or [NSNotFound, -bytes] from end of file - (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range; // Pass [NSNotFound, 0] to disable byte range entirely, [offset, length] to enable byte range from beginning of file or [NSNotFound, -length] from end of file
- (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment; - (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment;
@end @end

View File

@@ -29,7 +29,7 @@
typedef NSData* (^GCDWebServerStreamBlock)(NSError** error); typedef NSData* (^GCDWebServerStreamBlock)(NSError** error);
@interface GCDWebServerStreamingResponse : GCDWebServerResponse // Automatically enables chunked transfer encoding @interface GCDWebServerStreamingResponse : GCDWebServerResponse
+ (instancetype)responseWithContentType:(NSString*)type streamBlock:(GCDWebServerStreamBlock)block; + (instancetype)responseWithContentType:(NSString*)type streamBlock:(GCDWebServerStreamBlock)block;
- (instancetype)initWithContentType:(NSString*)type streamBlock:(GCDWebServerStreamBlock)block; // Block must return empty NSData when done or nil on error - (instancetype)initWithContentType:(NSString*)type streamBlock:(GCDWebServerStreamBlock)block; // Block must return empty NSData when done or nil on error and set the "error" argument accordingly
@end @end

View File

@@ -138,7 +138,7 @@
</div> </div>
<script type="text/x-tmpl" id="template-listing"> <script type="text/x-tmpl" id="template-listing">
<tr class="row-file" data-path="{%=o.path%}" data-name="{%=o.name%}"> <tr class="row-file">
<td class="column-icon"> <td class="column-icon">
{% if (o.size != null) { %} {% if (o.size != null) { %}
<button type="button" class="btn btn-default btn-xs button-download"> <button type="button" class="btn btn-default btn-xs button-download">

View File

@@ -25,9 +25,11 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
var ENTER_KEYCODE = 13;
var _path = null; var _path = null;
var _reloading = false;
var _pendingReloads = []; var _pendingReloads = [];
var _reloadingDisabled = 0;
function formatFileSize(bytes) { function formatFileSize(bytes) {
if (bytes >= 1000000000) { if (bytes >= 1000000000) {
@@ -47,15 +49,27 @@ function _showError(message, textStatus, errorThrown) {
})); }));
} }
function _disableReloads() {
_reloadingDisabled += 1;
}
function _enableReloads() {
_reloadingDisabled -= 1;
if (_pendingReloads.length > 0) {
_reload(_pendingReloads.shift());
}
}
function _reload(path) { function _reload(path) {
if (_reloading) { if (_reloadingDisabled) {
if ($.inArray(path, _pendingReloads) < 0) { if ($.inArray(path, _pendingReloads) < 0) {
_pendingReloads.push(path); _pendingReloads.push(path);
} }
return; return;
} }
_reloading = true; _disableReloads();
$.ajax({ $.ajax({
url: 'list', url: 'list',
type: 'GET', type: 'GET',
@@ -64,6 +78,7 @@ function _reload(path) {
}).fail(function(jqXHR, textStatus, errorThrown) { }).fail(function(jqXHR, textStatus, errorThrown) {
_showError("Failed retrieving contents of \"" + path + "\"", textStatus, errorThrown); _showError("Failed retrieving contents of \"" + path + "\"", textStatus, errorThrown);
}).done(function(data, textStatus, jqXHR) { }).done(function(data, textStatus, jqXHR) {
var scrollPosition = $(document).scrollTop();
if (path != _path) { if (path != _path) {
$("#path").empty(); $("#path").empty();
@@ -77,7 +92,7 @@ function _reload(path) {
$("#path").append('<li data-path="' + subpath + '"><a>' + components[i] + '</a></li>'); $("#path").append('<li data-path="' + subpath + '"><a>' + components[i] + '</a></li>');
} }
$("#path > li").click(function(event) { $("#path > li").click(function(event) {
_reload($(this).attr("data-path")); _reload($(this).data("path"));
event.preventDefault(); event.preventDefault();
}); });
$("#path").append('<li class="active">' + components[components.length - 1] + '</li>'); $("#path").append('<li class="active">' + components[components.length - 1] + '</li>');
@@ -87,13 +102,13 @@ function _reload(path) {
$("#listing").empty(); $("#listing").empty();
for (var i = 0, file; file = data[i]; ++i) { for (var i = 0, file; file = data[i]; ++i) {
$("#listing").append(tmpl("template-listing", file)); $(tmpl("template-listing", file)).data(file).appendTo("#listing");
} }
$(".edit").editable(function(value, settings) { $(".edit").editable(function(value, settings) {
var name = $(this).parent().parent().attr("data-name"); var name = $(this).parent().parent().data("name");
if (value != name) { if (value != name) {
var path = $(this).parent().parent().attr("data-path"); var path = $(this).parent().parent().data("path");
$.ajax({ $.ajax({
url: 'move', url: 'move',
type: 'POST', type: 'POST',
@@ -107,33 +122,42 @@ function _reload(path) {
} }
return value; return value;
}, { }, {
onedit: function(settings, original) {
_disableReloads();
},
onsubmit: function(settings, original) {
_enableReloads();
},
onreset: function(settings, original) {
_enableReloads();
},
tooltip: 'Click to rename...' tooltip: 'Click to rename...'
}); });
$(".button-download").click(function(event) { $(".button-download").click(function(event) {
var path = $(this).parent().parent().attr("data-path"); var path = $(this).parent().parent().data("path");
setTimeout(function() { setTimeout(function() {
window.location = "download?path=" + encodeURIComponent(path); window.location = "download?path=" + encodeURIComponent(path);
}, 0); }, 0);
}); });
$(".button-open").click(function(event) { $(".button-open").click(function(event) {
var path = $(this).parent().parent().attr("data-path"); var path = $(this).parent().parent().data("path");
_reload(path); _reload(path);
}); });
$(".button-move").click(function(event) { $(".button-move").click(function(event) {
var path = $(this).parent().parent().attr("data-path"); var path = $(this).parent().parent().data("path");
if (path[path.length - 1] == "/") { if (path[path.length - 1] == "/") {
path = path.slice(0, path.length - 1); path = path.slice(0, path.length - 1);
} }
$("#move-input").attr("data-path", path); $("#move-input").data("path", path);
$("#move-input").val(path); $("#move-input").val(path);
$("#move-modal").modal("show"); $("#move-modal").modal("show");
}); });
$(".button-delete").click(function(event) { $(".button-delete").click(function(event) {
var path = $(this).parent().parent().attr("data-path"); var path = $(this).parent().parent().data("path");
$.ajax({ $.ajax({
url: 'delete', url: 'delete',
type: 'POST', type: 'POST',
@@ -146,11 +170,9 @@ function _reload(path) {
}); });
}); });
$(document).scrollTop(scrollPosition);
}).always(function() { }).always(function() {
_reloading = false; _enableReloads();
if (_pendingReloads.length > 0) {
_reload(_pendingReloads.shift());
}
}); });
} }
@@ -212,10 +234,16 @@ $(document).ready(function() {
}); });
$("#create-input").keypress(function(event) {
if (event.keyCode == ENTER_KEYCODE) {
$("#create-confirm").click();
};
});
$("#create-modal").on("shown.bs.modal", function(event) { $("#create-modal").on("shown.bs.modal", function(event) {
$("#create-input").focus(); $("#create-input").focus();
$("#create-input").select(); $("#create-input").select();
}) });
$("#create-folder").click(function(event) { $("#create-folder").click(function(event) {
$("#create-input").val("Untitled folder"); $("#create-input").val("Untitled folder");
@@ -239,6 +267,12 @@ $(document).ready(function() {
} }
}); });
$("#move-input").keypress(function(event) {
if (event.keyCode == ENTER_KEYCODE) {
$("#move-confirm").click();
};
});
$("#move-modal").on("shown.bs.modal", function(event) { $("#move-modal").on("shown.bs.modal", function(event) {
$("#move-input").focus(); $("#move-input").focus();
$("#move-input").select(); $("#move-input").select();
@@ -246,7 +280,7 @@ $(document).ready(function() {
$("#move-confirm").click(function(event) { $("#move-confirm").click(function(event) {
$("#move-modal").modal("hide"); $("#move-modal").modal("hide");
var oldPath = $("#move-input").attr("data-path"); var oldPath = $("#move-input").data("path");
var newPath = $("#move-input").val(); var newPath = $("#move-input").val();
if ((newPath != "") && (newPath[0] == "/") && (newPath != oldPath)) { if ((newPath != "") && (newPath[0] == "/") && (newPath != oldPath)) {
$.ajax({ $.ajax({

View File

@@ -29,7 +29,8 @@
@class GCDWebUploader; @class GCDWebUploader;
@protocol GCDWebUploaderDelegate <NSObject> // These methods are always called on main thread
@protocol GCDWebUploaderDelegate <GCDWebServerDelegate>
@optional @optional
- (void)webUploader:(GCDWebUploader*)uploader didDownloadFileAtPath:(NSString*)path; - (void)webUploader:(GCDWebUploader*)uploader didDownloadFileAtPath:(NSString*)path;
- (void)webUploader:(GCDWebUploader*)uploader didUploadFileAtPath:(NSString*)path; - (void)webUploader:(GCDWebUploader*)uploader didUploadFileAtPath:(NSString*)path;
@@ -51,6 +52,7 @@
- (instancetype)initWithUploadDirectory:(NSString*)path; - (instancetype)initWithUploadDirectory:(NSString*)path;
@end @end
// These methods can be called from any thread
@interface GCDWebUploader (Subclassing) @interface GCDWebUploader (Subclassing)
- (BOOL)shouldUploadFileAtPath:(NSString*)path withTemporaryFile:(NSString*)tempPath; // Default implementation returns YES - (BOOL)shouldUploadFileAtPath:(NSString*)path withTemporaryFile:(NSString*)tempPath; // Default implementation returns YES
- (BOOL)shouldMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath; // Default implementation returns YES - (BOOL)shouldMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath; // Default implementation returns YES

View File

@@ -45,7 +45,6 @@
@interface GCDWebUploader () { @interface GCDWebUploader () {
@private @private
NSString* _uploadDirectory; NSString* _uploadDirectory;
id<GCDWebUploaderDelegate> __unsafe_unretained _delegate;
NSArray* _allowedExtensions; NSArray* _allowedExtensions;
BOOL _showHidden; BOOL _showHidden;
NSString* _title; NSString* _title;
@@ -143,9 +142,9 @@
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Downlading file name \"%@\" is not allowed", fileName]; return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Downlading file name \"%@\" is not allowed", fileName];
} }
if ([_delegate respondsToSelector:@selector(webUploader:didDownloadFileAtPath: )]) { if ([self.delegate respondsToSelector:@selector(webUploader:didDownloadFileAtPath: )]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate webUploader:self didDownloadFileAtPath:absolutePath]; [self.delegate webUploader:self didDownloadFileAtPath:absolutePath];
}); });
} }
return [GCDWebServerFileResponse responseWithFile:absolutePath isAttachment:YES]; return [GCDWebServerFileResponse responseWithFile:absolutePath isAttachment:YES];
@@ -171,9 +170,9 @@
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed moving uploaded file to \"%@\"", relativePath]; return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed moving uploaded file to \"%@\"", relativePath];
} }
if ([_delegate respondsToSelector:@selector(webUploader:didUploadFileAtPath:)]) { if ([self.delegate respondsToSelector:@selector(webUploader:didUploadFileAtPath:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate webUploader:self didUploadFileAtPath:absolutePath]; [self.delegate webUploader:self didUploadFileAtPath:absolutePath];
}); });
} }
return [GCDWebServerDataResponse responseWithJSONObject:@{} contentType:contentType]; return [GCDWebServerDataResponse responseWithJSONObject:@{} contentType:contentType];
@@ -204,9 +203,9 @@
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed moving \"%@\" to \"%@\"", oldRelativePath, newRelativePath]; return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed moving \"%@\" to \"%@\"", oldRelativePath, newRelativePath];
} }
if ([_delegate respondsToSelector:@selector(webUploader:didMoveItemFromPath:toPath:)]) { if ([self.delegate respondsToSelector:@selector(webUploader:didMoveItemFromPath:toPath:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate webUploader:self didMoveItemFromPath:oldAbsolutePath toPath:newAbsolutePath]; [self.delegate webUploader:self didMoveItemFromPath:oldAbsolutePath toPath:newAbsolutePath];
}); });
} }
return [GCDWebServerDataResponse responseWithJSONObject:@{}]; return [GCDWebServerDataResponse responseWithJSONObject:@{}];
@@ -234,9 +233,9 @@
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed deleting \"%@\"", relativePath]; return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed deleting \"%@\"", relativePath];
} }
if ([_delegate respondsToSelector:@selector(webUploader:didDeleteItemAtPath:)]) { if ([self.delegate respondsToSelector:@selector(webUploader:didDeleteItemAtPath:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate webUploader:self didDeleteItemAtPath:absolutePath]; [self.delegate webUploader:self didDeleteItemAtPath:absolutePath];
}); });
} }
return [GCDWebServerDataResponse responseWithJSONObject:@{}]; return [GCDWebServerDataResponse responseWithJSONObject:@{}];
@@ -260,9 +259,9 @@
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed creating directory \"%@\"", relativePath]; return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed creating directory \"%@\"", relativePath];
} }
if ([_delegate respondsToSelector:@selector(webUploader:didCreateDirectoryAtPath:)]) { if ([self.delegate respondsToSelector:@selector(webUploader:didCreateDirectoryAtPath:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate webUploader:self didCreateDirectoryAtPath:absolutePath]; [self.delegate webUploader:self didCreateDirectoryAtPath:absolutePath];
}); });
} }
return [GCDWebServerDataResponse responseWithJSONObject:@{}]; return [GCDWebServerDataResponse responseWithJSONObject:@{}];
@@ -272,7 +271,7 @@
@implementation GCDWebUploader @implementation GCDWebUploader
@synthesize uploadDirectory=_uploadDirectory, delegate=_delegate, allowedFileExtensions=_allowedExtensions, showHiddenFiles=_showHidden, @synthesize uploadDirectory=_uploadDirectory, allowedFileExtensions=_allowedExtensions, showHiddenFiles=_showHidden,
title=_title, header=_header, prologue=_prologue, epilogue=_epilogue, footer=_footer; title=_title, header=_header, prologue=_prologue, epilogue=_epilogue, footer=_footer;
- (instancetype)initWithUploadDirectory:(NSString*)path { - (instancetype)initWithUploadDirectory:(NSString*)path {

View File

@@ -25,6 +25,8 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#import <libgen.h>
#import "GCDWebServer.h" #import "GCDWebServer.h"
#import "GCDWebServerDataRequest.h" #import "GCDWebServerDataRequest.h"
@@ -37,22 +39,146 @@
#import "GCDWebUploader.h" #import "GCDWebUploader.h"
#ifndef __GCDWEBSERVER_ENABLE_TESTING__
#error __GCDWEBSERVER_ENABLE_TESTING__ must be defined
#endif
typedef enum {
kMode_WebServer = 0,
kMode_HTMLPage,
kMode_HTMLForm,
kMode_WebDAV,
kMode_WebUploader,
kMode_StreamingResponse
} Mode;
@interface Delegate : NSObject <GCDWebServerDelegate, GCDWebDAVServerDelegate, GCDWebUploaderDelegate>
@end
@implementation Delegate
- (void)_logDelegateCall:(SEL)selector {
fprintf(stdout, "<DELEGATE METHOD \"%s\" CALLED>\n", [NSStringFromSelector(selector) UTF8String]);
}
- (void)webServerDidStart:(GCDWebServer*)server {
[self _logDelegateCall:_cmd];
}
- (void)webServerDidConnect:(GCDWebServer*)server {
[self _logDelegateCall:_cmd];
}
- (void)webServerDidDisconnect:(GCDWebServer*)server {
[self _logDelegateCall:_cmd];
}
- (void)webServerDidStop:(GCDWebServer*)server {
[self _logDelegateCall:_cmd];
}
- (void)davServer:(GCDWebDAVServer*)server didDownloadFileAtPath:(NSString*)path {
[self _logDelegateCall:_cmd];
}
- (void)davServer:(GCDWebDAVServer*)server didUploadFileAtPath:(NSString*)path {
[self _logDelegateCall:_cmd];
}
- (void)davServer:(GCDWebDAVServer*)server didMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath {
[self _logDelegateCall:_cmd];
}
- (void)davServer:(GCDWebDAVServer*)server didCopyItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath {
[self _logDelegateCall:_cmd];
}
- (void)davServer:(GCDWebDAVServer*)server didDeleteItemAtPath:(NSString*)path {
[self _logDelegateCall:_cmd];
}
- (void)davServer:(GCDWebDAVServer*)server didCreateDirectoryAtPath:(NSString*)path {
[self _logDelegateCall:_cmd];
}
- (void)webUploader:(GCDWebUploader*)uploader didDownloadFileAtPath:(NSString*)path {
[self _logDelegateCall:_cmd];
}
- (void)webUploader:(GCDWebUploader*)uploader didUploadFileAtPath:(NSString*)path {
[self _logDelegateCall:_cmd];
}
- (void)webUploader:(GCDWebUploader*)uploader didMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath {
[self _logDelegateCall:_cmd];
}
- (void)webUploader:(GCDWebUploader*)uploader didDeleteItemAtPath:(NSString*)path {
[self _logDelegateCall:_cmd];
}
- (void)webUploader:(GCDWebUploader*)uploader didCreateDirectoryAtPath:(NSString*)path {
[self _logDelegateCall:_cmd];
}
@end
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
BOOL success = NO; int result = -1;
int mode = (argc == 2 ? MIN(MAX(atoi(argv[1]), 0), 5) : 0);
@autoreleasepool { @autoreleasepool {
Mode mode = kMode_WebServer;
BOOL recording = NO;
NSString* rootDirectory = NSHomeDirectory();
NSString* testDirectory = nil;
if (argc == 1) {
fprintf(stdout, "Usage: %s [-mode webServer | htmlPage | htmlForm | webDAV | webUploader | streamingResponse] [-record] [-root directory] [-tests directory]\n\n", basename((char*)argv[0]));
} else {
for (int i = 1; i < argc; ++i) {
if (argv[i][0] != '-') {
continue;
}
if (!strcmp(argv[i], "-mode") && (i + 1 < argc)) {
++i;
if (!strcmp(argv[i], "webServer")) {
mode = kMode_WebServer;
} else if (!strcmp(argv[i], "htmlPage")) {
mode = kMode_HTMLPage;
} else if (!strcmp(argv[i], "htmlForm")) {
mode = kMode_HTMLForm;
} else if (!strcmp(argv[i], "webDAV")) {
mode = kMode_WebDAV;
} else if (!strcmp(argv[i], "webUploader")) {
mode = kMode_WebUploader;
} else if (!strcmp(argv[i], "streamingResponse")) {
mode = kMode_StreamingResponse;
}
} else if (!strcmp(argv[i], "-record")) {
recording = YES;
} else if (!strcmp(argv[i], "-root") && (i + 1 < argc)) {
++i;
rootDirectory = [[[NSFileManager defaultManager] stringWithFileSystemRepresentation:argv[i] length:strlen(argv[i])] stringByStandardizingPath];
} else if (!strcmp(argv[i], "-tests") && (i + 1 < argc)) {
++i;
testDirectory = [[[NSFileManager defaultManager] stringWithFileSystemRepresentation:argv[i] length:strlen(argv[i])] stringByStandardizingPath];
}
}
}
GCDWebServer* webServer = nil; GCDWebServer* webServer = nil;
switch (mode) { switch (mode) {
// Simply serve contents of home directory // Simply serve contents of home directory
case 0: { case kMode_WebServer: {
fprintf(stdout, "Running in Web Server mode from \"%s\"", [rootDirectory UTF8String]);
webServer = [[GCDWebServer alloc] init]; webServer = [[GCDWebServer alloc] init];
[webServer addGETHandlerForBasePath:@"/" directoryPath:NSHomeDirectory() indexFilename:nil cacheAge:0 allowRangeRequests:YES]; [webServer addGETHandlerForBasePath:@"/" directoryPath:rootDirectory indexFilename:nil cacheAge:0 allowRangeRequests:YES];
break; break;
} }
// Renders a HTML page // Renders a HTML page
case 1: { case kMode_HTMLPage: {
fprintf(stdout, "Running in HTML Page mode");
webServer = [[GCDWebServer alloc] init]; webServer = [[GCDWebServer alloc] init];
[webServer addDefaultHandlerForMethod:@"GET" [webServer addDefaultHandlerForMethod:@"GET"
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
@@ -65,7 +191,8 @@ int main(int argc, const char* argv[]) {
} }
// Implements an HTML form // Implements an HTML form
case 2: { case kMode_HTMLForm: {
fprintf(stdout, "Running in HTML Form mode");
webServer = [[GCDWebServer alloc] init]; webServer = [[GCDWebServer alloc] init];
[webServer addHandlerForMethod:@"GET" [webServer addHandlerForMethod:@"GET"
path:@"/" path:@"/"
@@ -96,17 +223,23 @@ int main(int argc, const char* argv[]) {
break; break;
} }
case 3: { // Serve home directory through WebDAV
webServer = [[GCDWebDAVServer alloc] initWithUploadDirectory:[[NSFileManager defaultManager] currentDirectoryPath]]; case kMode_WebDAV: {
fprintf(stdout, "Running in WebDAV mode from \"%s\"", [rootDirectory UTF8String]);
webServer = [[GCDWebDAVServer alloc] initWithUploadDirectory:rootDirectory];
break; break;
} }
case 4: { // Serve home directory through web uploader
webServer = [[GCDWebUploader alloc] initWithUploadDirectory:[[NSFileManager defaultManager] currentDirectoryPath]]; case kMode_WebUploader: {
fprintf(stdout, "Running in Web Uploader mode from \"%s\"", [rootDirectory UTF8String]);
webServer = [[GCDWebUploader alloc] initWithUploadDirectory:rootDirectory];
break; break;
} }
case 5: { // Test streaming responses
case kMode_StreamingResponse: {
fprintf(stdout, "Running in Streaming Response mode");
webServer = [[GCDWebServer alloc] init]; webServer = [[GCDWebServer alloc] init];
[webServer addHandlerForMethod:@"GET" [webServer addHandlerForMethod:@"GET"
path:@"/" path:@"/"
@@ -130,10 +263,33 @@ int main(int argc, const char* argv[]) {
} }
} }
success = [webServer runWithPort:8080]; #if __has_feature(objc_arc)
#if !__has_feature(objc_arc) fprintf(stdout, " (ARC is ON)\n");
[webServer release]; #else
fprintf(stdout, " (ARC is OFF)\n");
#endif #endif
if (webServer) {
Delegate* delegate = [[Delegate alloc] init];
webServer.delegate = delegate;
if (testDirectory) {
fprintf(stdout, "<RUNNING TESTS FROM \"%s\">\n\n", [testDirectory UTF8String]);
result = (int)[webServer runTestsInDirectory:testDirectory withPort:8080];
} else {
if (recording) {
fprintf(stdout, "<RECORDING ENABLED>\n");
webServer.recordingEnabled = YES;
}
fprintf(stdout, "\n");
if ([webServer runWithPort:8080]) {
result = 0;
}
}
#if !__has_feature(objc_arc)
[webServer release];
[delegate release];
#endif
}
} }
return success ? 0 : -1; return result;
} }

123
README.md
View File

@@ -1,8 +1,10 @@
Overview Overview
======== ========
GCDWebServer is a lightweight GCD based HTTP 1.1 server designed to be embedded in Mac & iOS apps. It was written from scratch with the following goals in mind: [![Build Status](https://travis-ci.org/swisspol/GCDWebServer.svg?branch=master)](https://travis-ci.org/swisspol/GCDWebServer)
* Easy to use and understand architecture with only 4 core classes: server, connection, request and response
GCDWebServer is a modern and lightweight GCD based HTTP 1.1 server designed to be embedded in OS X & iOS apps. It was written from scratch with the following goals in mind:
* Easy to use and understand architecture with only 4 core classes: server, connection, request and response (see "Understanding GCDWebServer's Architecture" below)
* Well designed API for easy integration and customization * Well designed API for easy integration and customization
* Entirely built with an event-driven design using [Grand Central Dispatch](http://en.wikipedia.org/wiki/Grand_Central_Dispatch) for maximal performance and concurrency * Entirely built with an event-driven design using [Grand Central Dispatch](http://en.wikipedia.org/wiki/Grand_Central_Dispatch) for maximal performance and concurrency
* No dependencies on third-party source code * No dependencies on third-party source code
@@ -14,10 +16,11 @@ Extra built-in features:
* [JSON](http://www.json.org/) parsing and serialization for request and response HTTP bodies * [JSON](http://www.json.org/) parsing and serialization for request and response HTTP bodies
* [Chunked transfer encoding](https://en.wikipedia.org/wiki/Chunked_transfer_encoding) for request and response HTTP bodies * [Chunked transfer encoding](https://en.wikipedia.org/wiki/Chunked_transfer_encoding) for request and response HTTP bodies
* [HTTP compression](https://en.wikipedia.org/wiki/HTTP_compression) with gzip for request and response HTTP bodies * [HTTP compression](https://en.wikipedia.org/wiki/HTTP_compression) with gzip for request and response HTTP bodies
* [HTTP range](https://en.wikipedia.org/wiki/Byte_serving) support for requests of local files
Included extensions: Included extensions:
* [GCDWebUploader](GCDWebUploader/GCDWebUploader.h): subclass of GCDWebServer that implements an interface for uploading and downloading files from an iOS app's sandbox using a web browser * [GCDWebUploader](GCDWebUploader/GCDWebUploader.h): subclass of ```GCDWebServer``` that implements an interface for uploading and downloading files from an iOS app's sandbox using a web browser
* [GCDWebDAVServer](GCDWebDAVServer/GCDWebDAVServer.h): subclass of GCDWebServer that implements a class 1 [WebDAV](https://en.wikipedia.org/wiki/WebDAV) server (with partial class 2 support for OS X Finder) * [GCDWebDAVServer](GCDWebDAVServer/GCDWebDAVServer.h): subclass of ```GCDWebServer``` that implements a class 1 [WebDAV](https://en.wikipedia.org/wiki/WebDAV) server (with partial class 2 support for OS X Finder)
What's not available out of the box but can be implemented on top of the API: What's not available out of the box but can be implemented on top of the API:
* Authentication like [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) * Authentication like [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication)
@@ -40,12 +43,21 @@ Alternatively, you can install GCDWebServer using [CocoaPods](http://cocoapods.o
``` ```
pod "GCDWebServer", "~> 2.0" pod "GCDWebServer", "~> 2.0"
``` ```
If you want to use GCDWebUploader, use this line instead:
```
pod "GCDWebServer/WebUploader", "~> 2.0"
```
Or this line for GCDWebDAVServer:
```
pod "GCDWebServer/WebDAV", "~> 2.0"
```
Hello World Hello World
=========== ===========
This code snippet shows how to implement a custom HTTP server that runs on port 8080 and returns a "Hello World" HTML page to any request &mdash; since GCDWebServer uses GCD blocks to handle requests, no subclassing or delegates are needed: These codes snippets show how to implement a custom HTTP server that runs on port 8080 and returns a "Hello World" HTML page to any request. Since GCDWebServer uses GCD blocks to handle requests, no subclassing or delegates are needed, which results in very clean code.
**OS X version (command line tool):**
```objectivec ```objectivec
#import "GCDWebServer.h" #import "GCDWebServer.h"
@@ -55,7 +67,7 @@ int main(int argc, const char* argv[]) {
// Create server // Create server
GCDWebServer* webServer = [[GCDWebServer alloc] init]; GCDWebServer* webServer = [[GCDWebServer alloc] init];
// Add a handler to respond to requests on any URL // Add a handler to respond to GET requests on any URL
[webServer addDefaultHandlerForMethod:@"GET" [webServer addDefaultHandlerForMethod:@"GET"
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) { processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
@@ -64,10 +76,10 @@ int main(int argc, const char* argv[]) {
}]; }];
// Use convenience method that runs server on port 8080 until SIGINT received // Use convenience method that runs server on port 8080 until SIGINT received (i.e. Ctrl-C in Terminal)
[webServer runWithPort:8080]; [webServer runWithPort:8080];
// Destroy server // Destroy server (unnecessary if using ARC)
[webServer release]; [webServer release];
} }
@@ -75,21 +87,50 @@ int main(int argc, const char* argv[]) {
} }
``` ```
**iOS Version:**
```objectivec
#import "GCDWebServer.h"
static GCDWebServer* _webServer = nil; // This should really be an ivar of your application delegate class
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Create server
_webServer = [[GCDWebServer alloc] init];
// Add a handler to respond to GET requests on any URL
[_webServer addDefaultHandlerForMethod:@"GET"
requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
return [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello World</p></body></html>"];
}];
// Start server on port 8080
[_webServer startWithPort:8080 bonjourName:nil];
return YES;
}
```
Web Based Uploads in iOS Apps Web Based Uploads in iOS Apps
============================= =============================
GCDWebUploader is a subclass of GCDWebServer that provides a ready-to-use HTML 5 file uploader & downloader. This lets users upload, download, delete files and create directories from a directory inside your iOS app's sandbox using a clean user interface in their web browser. GCDWebUploader is a subclass of ```GCDWebServer``` that provides a ready-to-use HTML 5 file uploader & downloader. This lets users upload, download, delete files and create directories from a directory inside your iOS app's sandbox using a clean user interface in their web browser.
Simply instantiate and run a GCDWebUploader instance then visit http://{YOUR-IOS-DEVICE-IP-ADDRESS}/ from your web browser: Simply instantiate and run a GCDWebUploader instance then visit http://{YOUR-IOS-DEVICE-IP-ADDRESS}/ from your web browser:
```objectivec ```objectivec
#import "GCDWebUploader.h" #import "GCDWebUploader.h"
static GCDWebUploader* _webUploader = nil; // This should really be an ivar of your application delegate class
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
GCDWebUploader* webUploader = [[GCDWebUploader alloc] initWithUploadDirectory:documentsPath]; _webUploader = [[GCDWebUploader alloc] initWithUploadDirectory:documentsPath];
[webUploader start]; [_webUploader start];
NSLog(@"Visit %@ in your web browser", webUploader.serverURL); NSLog(@"Visit %@ in your web browser", _webUploader.serverURL);
return YES; return YES;
} }
``` ```
@@ -97,7 +138,7 @@ Simply instantiate and run a GCDWebUploader instance then visit http://{YOUR-IOS
WebDAV Server in iOS Apps WebDAV Server in iOS Apps
========================= =========================
GCDWebDAVServer is a subclass of GCDWebServer that provides a class 1 compliant [WebDAV](https://en.wikipedia.org/wiki/WebDAV) server. This lets users upload, download, delete files and create directories from a directory inside your iOS app's sandbox using any WebDAV client like [Transmit](https://panic.com/transmit/) (Mac), [ForkLift](http://binarynights.com/forklift/) (Mac) or [CyberDuck](http://cyberduck.io/) (Mac / Windows). GCDWebDAVServer is a subclass of ```GCDWebServer``` that provides a class 1 compliant [WebDAV](https://en.wikipedia.org/wiki/WebDAV) server. This lets users upload, download, delete files and create directories from a directory inside your iOS app's sandbox using any WebDAV client like [Transmit](https://panic.com/transmit/) (Mac), [ForkLift](http://binarynights.com/forklift/) (Mac) or [CyberDuck](http://cyberduck.io/) (Mac / Windows).
GCDWebDAVServer should also work with the [OS X Finder](http://support.apple.com/kb/PH13859) as it is partially class 2 compliant (but only when the client is the OS X WebDAV implementation). GCDWebDAVServer should also work with the [OS X Finder](http://support.apple.com/kb/PH13859) as it is partially class 2 compliant (but only when the client is the OS X WebDAV implementation).
@@ -106,11 +147,13 @@ Simply instantiate and run a GCDWebDAVServer instance then connect to http://{YO
```objectivec ```objectivec
#import "GCDWebDAVServer.h" #import "GCDWebDAVServer.h"
static GCDWebDAVServer* _davServer = nil; // This should really be an ivar of your application delegate class
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
GCDWebDAVServer* davServer = [[GCDWebDAVServer alloc] initWithUploadDirectory:documentsPath]; _davServer = [[GCDWebDAVServer alloc] initWithUploadDirectory:documentsPath];
[davServer start]; [_davServer start];
NSLog(@"Visit %@ in your WebDAV client", davServer.serverURL); NSLog(@"Visit %@ in your WebDAV client", _davServer.serverURL);
return YES; return YES;
} }
``` ```
@@ -118,7 +161,7 @@ Simply instantiate and run a GCDWebDAVServer instance then connect to http://{YO
Serving a Static Website Serving a Static Website
======================== ========================
GCDWebServer includes a built-in handler that can recursively serve a directory (it also lets you control how the "Cache-Control" header should be set): GCDWebServer includes a built-in handler that can recursively serve a directory (it also lets you control how the ["Cache-Control"](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9) header should be set):
```objectivec ```objectivec
#import "GCDWebServer.h" #import "GCDWebServer.h"
@@ -129,7 +172,7 @@ int main(int argc, const char* argv[]) {
GCDWebServer* webServer = [[GCDWebServer alloc] init]; GCDWebServer* webServer = [[GCDWebServer alloc] init];
[webServer addGETHandlerForBasePath:@"/" directoryPath:NSHomeDirectory() indexFilename:nil cacheAge:3600 allowRangeRequests:YES]; [webServer addGETHandlerForBasePath:@"/" directoryPath:NSHomeDirectory() indexFilename:nil cacheAge:3600 allowRangeRequests:YES];
[webServer runWithPort:8080]; [webServer runWithPort:8080];
[webServer release]; [webServer release]; // Remove if using ARC
} }
return 0; return 0;
@@ -139,20 +182,20 @@ int main(int argc, const char* argv[]) {
Using GCDWebServer Using GCDWebServer
================== ==================
You start by creating an instance of the 'GCDWebServer' class. Note that you can have multiple web servers running in the same app as long as they listen on different ports. You start by creating an instance of the ```GCDWebServer``` class. Note that you can have multiple web servers running in the same app as long as they listen on different ports.
Then you add one or more "handlers" to the server: each handler gets a chance to handle an incoming web request and provide a response. Handlers are called in a LIFO queue, so the latest added handler overrides any previously added ones. Then you add one or more "handlers" to the server: each handler gets a chance to handle an incoming web request and provide a response. Handlers are called in a LIFO queue, so the latest added handler overrides any previously added ones.
Finally you start the server on a given port. Finally you start the server on a given port.
Understanding GCDWebServer Architecture Understanding GCDWebServer's Architecture
======================================= =========================================
GCDWebServer is made of only 4 core classes: GCDWebServer's architecture consists of only 4 core classes:
* 'GCDWebServer' manages the socket that listens for new HTTP connections and the list of handlers used by the server. * [GCDWebServer](GCDWebServer/Core/GCDWebServer.h) manages the socket that listens for new HTTP connections and the list of handlers used by the server.
* 'GCDWebServerConnection' is instantiated by 'GCDWebServer' to handle each new HTTP connection. Each instance stays alive until the connection is closed. You cannot use this class directly, but it is exposed so you can subclass it to override some hooks. * [GCDWebServerConnection](GCDWebServer/Core/GCDWebServerConnection.h) is instantiated by ```GCDWebServer``` to handle each new HTTP connection. Each instance stays alive until the connection is closed. You cannot use this class directly, but it is exposed so you can subclass it to override some hooks.
* 'GCDWebServerRequest' is created by the 'GCDWebServerConnection' instance after HTTP headers have been received. It wraps the request and handles the HTTP body if any. GCDWebServer comes with several subclasses of 'GCDWebServerRequest' to handle common cases like storing the body in memory or stream it to a file on disk. See [GCDWebServerRequest.h](CGDWebServer/GCDWebServerRequest.h) for the full list. * [GCDWebServerRequest](GCDWebServer/Core/GCDWebServerRequest.h) is created by the ```GCDWebServerConnection``` instance after HTTP headers have been received. It wraps the request and handles the HTTP body if any. GCDWebServer comes with [several subclasses](GCDWebServer/Requests) of ```GCDWebServerRequest``` to handle common cases like storing the body in memory or stream it to a file on disk.
* 'GCDWebServerResponse' is created by the request handler and wraps the response HTTP headers and optional body. GCDWebServer provides several subclasses of 'GCDWebServerResponse' to handle common cases like HTML text in memory or streaming a file from disk. See [GCDWebServerResponse.h](CGDWebServer/GCDWebServerResponse.h) for the full list. * [GCDWebServerResponse](GCDWebServer/Core/GCDWebServerResponse.h) is created by the request handler and wraps the response HTTP headers and optional body. GCDWebServer comes with [several subclasses](GCDWebServer/Responses) of ```GCDWebServerResponse``` to handle common cases like HTML text in memory or streaming a file from disk.
Implementing Handlers Implementing Handlers
===================== =====================
@@ -160,15 +203,29 @@ Implementing Handlers
GCDWebServer relies on "handlers" to process incoming web requests and generating responses. Handlers are implemented with GCD blocks which makes it very easy to provide your owns. However, they are executed on arbitrary threads within GCD so __special attention must be paid to thread-safety and re-entrancy__. GCDWebServer relies on "handlers" to process incoming web requests and generating responses. Handlers are implemented with GCD blocks which makes it very easy to provide your owns. However, they are executed on arbitrary threads within GCD so __special attention must be paid to thread-safety and re-entrancy__.
Handlers require 2 GCD blocks: Handlers require 2 GCD blocks:
* The 'GCDWebServerMatchBlock' is called on every handler added to the 'GCDWebServer' instance whenever a web request has started (i.e. HTTP headers have been received). It is passed the basic info for the web request (HTTP method, URL, headers...) and must decide if it wants to handle it or not. If yes, it must return a 'GCDWebServerRequest' instance (see above). Otherwise, it simply returns nil. * The ```GCDWebServerMatchBlock``` is called on every handler added to the ```GCDWebServer``` instance whenever a web request has started (i.e. HTTP headers have been received). It is passed the basic info for the web request (HTTP method, URL, headers...) and must decide if it wants to handle it or not. If yes, it must return a new ```GCDWebServerRequest``` instance (see above) created with this info. Otherwise, it simply returns nil.
* The 'GCDWebServerProcessBlock' is called after the web request has been fully received and is passed the 'GCDWebServerRequest' instance created at the previous step. It must return a 'GCDWebServerResponse' instance (see above) or nil on error. * The ```GCDWebServerProcessBlock``` is called after the web request has been fully received and is passed the ```GCDWebServerRequest``` instance created at the previous step. It must return a ```GCDWebServerResponse``` instance (see above) or nil on error, which will result in a 500 HTTP status code returned to the client. It's however recommended to return an instance of [GCDWebServerErrorResponse](GCDWebServer/Responses/GCDWebServerErrorResponse.h) on error so more useful information can be returned to the client.
Note that most methods on 'GCDWebServer' to add handlers only require the 'GCDWebServerProcessBlock' as they already provide a built-in 'GCDWebServerMatchBlock' e.g. to match a URL path with a Regex. Note that most methods on ```GCDWebServer``` to add handlers only require the ```GCDWebServerProcessBlock``` as they already provide a built-in ```GCDWebServerMatchBlock``` e.g. to match a URL path with a Regex.
GCDWebServer & Background Mode for iOS Apps
===========================================
When doing networking operations in iOS apps, you must handle carefully [what happens when iOS puts the app in the background](https://developer.apple.com/library/ios/technotes/tn2277/_index.html). Typically you must stop any server while the app is in the background and restart them when it comes back to the foreground. This can become quite complex considering the server might have ongoing connections when it needs to be stopped.
Fortunately, GCDWebServer does all of this automatically for you:
- GCDWebServer begins a [background task](https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html) whenever the first HTTP connection is opened and ends it only when the last one is closed. This prevents iOS from suspending the app after it goes in the background, which would immediately kill HTTP connections to the client.
- While the app is in the background, as long as new HTTP connections keep being initiated, the background task will continue to exist and iOS will not suspend the app (unless under sudden and unexpected memory pressure).
- If the app is still in the background when the last HTTP connection is closed, GCDWebServer will suspend itself and stop accepting new connections as if you had called ```-stop``` (this behavior can be disabled with the ```GCDWebServerOption_AutomaticallySuspendInBackground``` option).
- If the app goes in the background while no HTTP connections are opened, GCDWebServer will immediately suspend itself and stop accepting new connections as if you had called ```-stop``` (this behavior can be disabled with the ```GCDWebServerOption_AutomaticallySuspendInBackground``` option).
- If the app comes back to the foreground and GCDWebServer had been suspended, it will automatically resume itself and start accepting again new HTTP connections as if you had called ```-start```.
HTTP connections are often initiated in batches (or bursts), for instance when loading a web page with multiple resources. This makes it difficult to accurately detect when the *very last* HTTP connection has been closed: it's possible 2 consecutive HTTP connections part of the same batch would be separated by a small delay instead of overlapping. It would be bad for the client if GCDWebServer suspended itself right in between. The ```GCDWebServerOption_ConnectedStateCoalescingInterval``` option solves this problem elegantly by forcing GCDWebServer to wait some extra delay before performing any action after the last HTTP connection has been closed, just in case a new HTTP connection is initiated within this delay.
Advanced Example 1: Implementing HTTP Redirects Advanced Example 1: Implementing HTTP Redirects
=============================================== ===============================================
Here's an example handler that redirects "/" to "/index.html" using the convenience method on 'GCDWebServerResponse' (it sets the HTTP status code and 'Location' header automatically): Here's an example handler that redirects "/" to "/index.html" using the convenience method on ```GCDWebServerResponse``` (it sets the HTTP status code and "Location" header automatically):
```objectivec ```objectivec
[self addHandlerForMethod:@"GET" [self addHandlerForMethod:@"GET"
@@ -186,8 +243,8 @@ Advanced Example 2: Implementing Forms
====================================== ======================================
To implement an HTTP form, you need a pair of handlers: To implement an HTTP form, you need a pair of handlers:
* The GET handler does not expect any body in the HTTP request and therefore uses the 'GCDWebServerRequest' class. The handler generates a response containing a simple HTML form. * The GET handler does not expect any body in the HTTP request and therefore uses the ```GCDWebServerRequest``` class. The handler generates a response containing a simple HTML form.
* The POST handler expects the form values to be in the body of the HTTP request and percent-encoded. Fortunately, GCDWebServer provides the request class 'GCDWebServerURLEncodedFormRequest' which can automatically parse such bodies. The handler simply echoes back the value from the user submitted form. * The POST handler expects the form values to be in the body of the HTTP request and percent-encoded. Fortunately, GCDWebServer provides the request class ```GCDWebServerURLEncodedFormRequest``` which can automatically parse such bodies. The handler simply echoes back the value from the user submitted form.
```objectivec ```objectivec
[webServer addHandlerForMethod:@"GET" [webServer addHandlerForMethod:@"GET"
@@ -222,7 +279,7 @@ To implement an HTTP form, you need a pair of handlers:
Advanced Example 3: Serving a Dynamic Website Advanced Example 3: Serving a Dynamic Website
============================================= =============================================
GCDWebServer provides an extension to the 'GCDWebServerDataResponse' class that can return HTML content generated from a template and a set of variables (using the format '%variable%'). It is a very basic template system and is really intended as a starting point to building more advanced template systems by subclassing 'GCDWebServerResponse'. GCDWebServer provides an extension to the ```GCDWebServerDataResponse``` class that can return HTML content generated from a template and a set of variables (using the format ```%variable%```). It is a very basic template system and is really intended as a starting point to building more advanced template systems by subclassing ```GCDWebServerResponse```.
Assuming you have a website directory in your app containing HTML template files along with the corresponding CSS, scripts and images, it's pretty easy to turn it into a dynamic website: Assuming you have a website directory in your app containing HTML template files along with the corresponding CSS, scripts and images, it's pretty easy to turn it into a dynamic website:

58
Run-Tests.sh Executable file
View File

@@ -0,0 +1,58 @@
#!/bin/bash -ex
OSX_SDK="macosx"
if [ -z "$TRAVIS" ]; then
IOS_SDK="iphoneos"
else
IOS_SDK="iphonesimulator"
fi
OSX_TARGET="GCDWebServer (Mac)"
IOS_TARGET="GCDWebServer (iOS)"
CONFIGURATION="Release"
MRC_BUILD_DIR="/tmp/GCDWebServer-MRC"
MRC_PRODUCT="$MRC_BUILD_DIR/$CONFIGURATION/GCDWebServer"
ARC_BUILD_DIR="/tmp/GCDWebServer-ARC"
ARC_PRODUCT="$ARC_BUILD_DIR/$CONFIGURATION/GCDWebServer"
PAYLOAD_ZIP="Tests/Payload.zip"
PAYLOAD_DIR="/tmp/GCDWebServer"
function runTests {
rm -rf "$PAYLOAD_DIR"
ditto -x -k "$PAYLOAD_ZIP" "$PAYLOAD_DIR"
TZ=GMT find "$PAYLOAD_DIR" -type d -exec SetFile -d "1/1/2014 00:00:00" -m "1/1/2014 00:00:00" '{}' \; # ZIP archives do not preserve directories dates
logLevel=2 $1 -mode "$2" -root "$PAYLOAD_DIR/Payload" -tests "$3"
}
# Build for iOS in manual memory management mode (TODO: run tests on iOS)
rm -rf "$MRC_BUILD_DIR"
xcodebuild -sdk "$IOS_SDK" -target "$IOS_TARGET" -configuration "$CONFIGURATION" build "SYMROOT=$MRC_BUILD_DIR" "CLANG_ENABLE_OBJC_ARC=NO" > /dev/null
# Build for iOS in ARC mode (TODO: run tests on iOS)
rm -rf "$ARC_BUILD_DIR"
xcodebuild -sdk "$IOS_SDK" -target "$IOS_TARGET" -configuration "$CONFIGURATION" build "SYMROOT=$ARC_BUILD_DIR" "CLANG_ENABLE_OBJC_ARC=YES" > /dev/null
# Build for OS X in manual memory management mode
rm -rf "$MRC_BUILD_DIR"
xcodebuild -sdk "$OSX_SDK" -target "$OSX_TARGET" -configuration "$CONFIGURATION" build "SYMROOT=$MRC_BUILD_DIR" "CLANG_ENABLE_OBJC_ARC=NO" > /dev/null
# Build for OS X in ARC mode
rm -rf "$ARC_BUILD_DIR"
xcodebuild -sdk "$OSX_SDK" -target "$OSX_TARGET" -configuration "$CONFIGURATION" build "SYMROOT=$ARC_BUILD_DIR" "CLANG_ENABLE_OBJC_ARC=YES" > /dev/null
# Run tests
runTests $MRC_PRODUCT "webServer" "Tests/WebServer"
runTests $ARC_PRODUCT "webServer" "Tests/WebServer"
runTests $MRC_PRODUCT "webDAV" "Tests/WebDAV-Transmit"
runTests $ARC_PRODUCT "webDAV" "Tests/WebDAV-Transmit"
runTests $MRC_PRODUCT "webDAV" "Tests/WebDAV-Cyberduck"
runTests $ARC_PRODUCT "webDAV" "Tests/WebDAV-Cyberduck"
runTests $MRC_PRODUCT "webDAV" "Tests/WebDAV-Finder"
runTests $ARC_PRODUCT "webDAV" "Tests/WebDAV-Finder"
runTests $MRC_PRODUCT "webUploader" "Tests/WebUploader"
runTests $ARC_PRODUCT "webUploader" "Tests/WebUploader"
# Done
echo "\nAll tests completed successfully!"

BIN
Tests/Payload.zip Normal file

Binary file not shown.

View File

@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:52:42 GMT

View File

@@ -0,0 +1,6 @@
HEAD / HTTP/1.1
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,14 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 1106
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:52:42 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Copy.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/images</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/PDF%20Reports</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND / HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,12 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 700
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:52:47 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/PDF%20Reports/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/PDF%20Reports/Apple%20Economic%20Impact%20on%20Cupertino.pdf</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2013-05-01T12:01:13+00:00</D:creationdate><D:getlastmodified>Wed, 01 May 2013 12:01:13 GMT</D:getlastmodified><D:getcontentlength>181952</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND /PDF%20Reports/ HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,13 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 998
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:52:47 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/images/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/images/capable_green_ipad_l.png</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T21:46:56+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 21:46:56 GMT</D:getlastmodified><D:getcontentlength>116066</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/images/hero_mba_11.jpg</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T21:51:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 21:51:14 GMT</D:getlastmodified><D:getcontentlength>106799</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND /images/ HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:52:51 GMT

View File

@@ -0,0 +1,6 @@
HEAD / HTTP/1.1
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,7 @@
HTTP/1.1 404 Not Found
Content-Length: 204
Content-Type: text/html; charset=utf-8
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:52:51 GMT

View File

@@ -0,0 +1,6 @@
HEAD /Copy%20%284%3A11%3A14%2C%209%3A52%20PM%29.txt HTTP/1.1
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,6 @@
HTTP/1.1 201 Created
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:52:51 GMT

View File

@@ -0,0 +1,8 @@
COPY /Copy.txt HTTP/1.1
Destination: http://localhost:8080/Copy%20%284%3A11%3A14%2C%209%3A52%20PM%29.txt
Overwrite: T
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,15 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 1448
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:52:51 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Copy%20(4:11:14,%209:52%20PM).txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Copy.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/images</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/PDF%20Reports</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND / HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:52:59 GMT

View File

@@ -0,0 +1,6 @@
HEAD / HTTP/1.1
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

Binary file not shown.

View File

@@ -0,0 +1,6 @@
GET /images/capable_green_ipad_l.png HTTP/1.1
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,13 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 998
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:07 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/images/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/images/capable_green_ipad_l.png</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T21:46:56+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 21:46:56 GMT</D:getlastmodified><D:getcontentlength>116066</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/images/hero_mba_11.jpg</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T21:51:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 21:51:14 GMT</D:getlastmodified><D:getcontentlength>106799</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND /images/ HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,6 @@
HTTP/1.1 204 No Content
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:07 GMT

View File

@@ -0,0 +1,6 @@
DELETE /images/capable_green_ipad_l.png HTTP/1.1
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,6 @@
HTTP/1.1 204 No Content
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:07 GMT

View File

@@ -0,0 +1,6 @@
DELETE /images/hero_mba_11.jpg HTTP/1.1
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,6 @@
HTTP/1.1 204 No Content
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:07 GMT

View File

@@ -0,0 +1,6 @@
DELETE /images/ HTTP/1.1
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,14 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 1214
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:07 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Copy%20(4:11:14,%209:52%20PM).txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Copy.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/PDF%20Reports</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND / HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,6 @@
HTTP/1.1 201 Created
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:13 GMT

View File

@@ -0,0 +1,8 @@
MOVE /Copy%20%284%3A11%3A14%2C%209%3A52%20PM%29.txt HTTP/1.1
Destination: http://localhost:8080/Test.txt
Overwrite: T
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,14 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 1189
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:13 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Copy.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/PDF%20Reports</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Test.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND / HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,6 @@
HTTP/1.1 201 Created
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:14 GMT

View File

@@ -0,0 +1,8 @@
MOVE /Test.txt HTTP/1.1
Destination: http://localhost:8080/PDF%20Reports/Test.txt
Overwrite: T
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,13 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 872
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:14 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Copy.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/PDF%20Reports</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND / HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,13 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 1031
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:14 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/PDF%20Reports/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/PDF%20Reports/Apple%20Economic%20Impact%20on%20Cupertino.pdf</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2013-05-01T12:01:13+00:00</D:creationdate><D:getlastmodified>Wed, 01 May 2013 12:01:13 GMT</D:getlastmodified><D:getcontentlength>181952</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/PDF%20Reports/Test.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND /PDF%20Reports/ HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,6 @@
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:22 GMT

View File

@@ -0,0 +1,6 @@
HEAD / HTTP/1.1
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,7 @@
HTTP/1.1 404 Not Found
Content-Length: 190
Content-Type: text/html; charset=utf-8
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:22 GMT

View File

@@ -0,0 +1,6 @@
HEAD /Test%20File.txt HTTP/1.1
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,6 @@
HTTP/1.1 201 Created
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:22 GMT

View File

@@ -0,0 +1,11 @@
PUT /Test%20File.txt HTTP/1.1
Content-Length: 21
Content-Type: text/plain
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
X-GCDWebServer-CreationDate: 2014-04-12T04:53:22+00:00
X-GCDWebServer-ModifiedDate: Sat, 12 Apr 2014 04:53:22 GMT
Nothing to see here!

View File

@@ -0,0 +1,14 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 1195
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:22 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Copy.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/PDF%20Reports</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Test%20File.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-12T04:53:22+00:00</D:creationdate><D:getlastmodified>Sat, 12 Apr 2014 04:53:22 GMT</D:getlastmodified><D:getcontentlength>21</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND / HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,6 @@
HTTP/1.1 201 Created
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:35 GMT

View File

@@ -0,0 +1,8 @@
MKCOL /Text%20Files/ HTTP/1.1
Content-Length: 0
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
X-GCDWebServer-CreationDate: 2014-04-12T04:53:35+00:00

View File

@@ -0,0 +1,15 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 1435
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:35 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Copy.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-10T11:10:14+00:00</D:creationdate><D:getlastmodified>Thu, 10 Apr 2014 11:10:14 GMT</D:getlastmodified><D:getcontentlength>271</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/PDF%20Reports</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-01-01T00:00:00+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Test%20File.txt</D:href><D:propstat><D:prop><D:resourcetype/><D:creationdate>2014-04-12T04:53:22+00:00</D:creationdate><D:getlastmodified>Sat, 12 Apr 2014 04:53:22 GMT</D:getlastmodified><D:getcontentlength>21</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
<D:response><D:href>/Text%20Files</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-04-12T04:53:35+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND / HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,11 @@
HTTP/1.1 207 Multi-Status
Cache-Control: no-cache
Content-Length: 327
Content-Type: application/xml; charset="utf-8"
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:36 GMT
<?xml version="1.0" encoding="utf-8" ?><D:multistatus xmlns:D="DAV:">
<D:response><D:href>/Text%20Files/</D:href><D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype><D:creationdate>2014-04-12T04:53:35+00:00</D:creationdate></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>

View File

@@ -0,0 +1,10 @@
PROPFIND /Text%20Files/ HTTP/1.1
Depth: 1
Content-Type: text/xml; charset=utf-8
Content-Length: 99
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><propfind xmlns="DAV:"><allprop/></propfind>

View File

@@ -0,0 +1,6 @@
HTTP/1.1 201 Created
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:39 GMT

View File

@@ -0,0 +1,8 @@
MOVE /Test%20File.txt HTTP/1.1
Destination: http://localhost:8080/Text%20Files/Test%20File.txt
Overwrite: T
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

View File

@@ -0,0 +1,6 @@
HTTP/1.1 201 Created
Cache-Control: no-cache
Connection: Close
Server: GCDWebDAVServer
Date: Sat, 12 Apr 2014 04:53:39 GMT

View File

@@ -0,0 +1,8 @@
MOVE /Copy.txt HTTP/1.1
Destination: http://localhost:8080/Text%20Files/Copy.txt
Overwrite: T
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Cyberduck/4.4.3 (Mac OS X/10.9.2) (x86_64)
Accept-Encoding: gzip,deflate

Some files were not shown because too many files have changed in this diff Show More