Просмотр исходного кода

Merge branch 'master' of https://github.com/glock45/swifter

Conflicts:
	Common/HttpParser.swift
	Common/HttpServer.swift
Christopher Luu 11 лет назад
Родитель
Сommit
14d3cdb938

+ 4 - 4
Swifter/HttpParser.swift → Common/HttpParser.swift

@@ -12,8 +12,8 @@ class HttpParser {
     class func err(reason:String) -> NSError {
         return NSError.errorWithDomain("HTTP_PARSER", code: 0, userInfo:[NSLocalizedFailureReasonErrorKey : reason])
     }
-    
-    func nextHttpRequest(socket: CInt, error:NSErrorPointer = nil) -> (String, String, Dictionary<String, String>, NSData?)? {
+
+    func nextHttpRequest(socket: CInt, error:NSErrorPointer = nil) -> HttpRequest? { //(String, String, Dictionary<String, String>)? {
         if let statusLine = nextLine(socket, error: error) {
             let statusTokens = split(statusLine, { $0 == " " })
             println(statusTokens)
@@ -34,7 +34,7 @@ class HttpParser {
                 }
                 println(responseString)
                 let responseData = responseString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)
-                return (path, method, headers, responseData)
+                return HttpRequest(url: path, method: method, headers: headers, responseData: responseData)
             }
         }
         return nil
@@ -61,7 +61,7 @@ class HttpParser {
         return nil
     }
 
-    var recvBuffer: [UInt8] = [UInt8](count: 1024, repeatedValue: 0)
+    var recvBuffer = [UInt8](count: 1024, repeatedValue: 0)
     var recvBufferSize: Int = 0
     var recvBufferOffset: Int = 0
     

+ 16 - 0
Common/HttpRequest.swift

@@ -0,0 +1,16 @@
+//
+//  HttpRequest.swift
+//  Swifter
+//
+//  Created by Damian Kolakowski on 19/08/14.
+//  Copyright (c) 2014 Damian Kołakowski. All rights reserved.
+//
+
+import Foundation
+
+struct HttpRequest {
+    let url: String
+    let method: String
+    let headers: Dictionary<String, String>
+	let responseData: NSData?
+}

+ 0 - 0
Swifter/HttpResponse.swift → Common/HttpResponse.swift


+ 10 - 9
Swifter/HttpServer.swift → Common/HttpServer.swift

@@ -9,7 +9,7 @@ import Foundation
 
 class HttpServer
 {
-    typealias Handler = (String, String, Dictionary<String,String>, NSData?) -> HttpResponse
+    typealias Handler = HttpRequest -> HttpResponse
     
     var handlers: [(expression: NSRegularExpression, handler: Handler)] = []
     var acceptSocket: CInt = -1
@@ -42,10 +42,11 @@ class HttpServer
         }
         set ( directoryPath ) {
             if let regex = NSRegularExpression.regularExpressionWithPattern(path, options: expressionOptions, error: nil) {
-                handlers.append(expression: regex, handler: { (method, path, headers, responseData) in
-                    let result = regex.firstMatchInString(path, options: self.matchingOptions, range: NSMakeRange(0, path.lengthOfBytesUsingEncoding(NSASCIIStringEncoding)))
-                    let myPath: NSString = path
-                    let filesPath = directoryPath.stringByAppendingPathComponent(myPath.substringWithRange(result.rangeAtIndex(1)))
+                handlers.append(expression: regex, handler: { request in
+                    let result = regex.firstMatchInString(request.url, options: self.matchingOptions, range: NSMakeRange(0, request.url.lengthOfBytesUsingEncoding(NSASCIIStringEncoding)))
+                    let nsPath: NSString = request.url
+                    let filesPath = directoryPath.stringByExpandingTildeInPath
+                        .stringByAppendingPathComponent(nsPath.substringWithRange(result.rangeAtIndex(1)))
                     if let fileBody = String.stringWithContentsOfFile(filesPath, encoding: NSASCIIStringEncoding, error: nil) {
                         return HttpResponse.OK(.RAW(fileBody))
                     }
@@ -69,10 +70,10 @@ class HttpServer
                 while let socket = Socket.acceptClientSocket(self.acceptSocket) {
                     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {
                         let parser = HttpParser()
-                        while let (path, method, headers, responseData) = parser.nextHttpRequest(socket) {
-                            let keepAlive = parser.supportsKeepAlive(headers)
-                            if let handler: Handler = self[path] {
-                                HttpServer.writeResponse(socket, response: handler(method, path, headers, responseData), keepAlive: keepAlive)
+                        while let request = parser.nextHttpRequest(socket) {
+                            let keepAlive = parser.supportsKeepAlive(request.headers)
+                            if let handler: Handler = self[request.url] {
+                                HttpServer.writeResponse(socket, response: handler(request), keepAlive: keepAlive)
                             } else {
                                 HttpServer.writeResponse(socket, response: HttpResponse.NotFound, keepAlive: keepAlive)
                             }

+ 0 - 0
Swifter/Socket.swift → Common/Socket.swift


+ 3 - 0
Resources/test.json

@@ -0,0 +1,3 @@
+{
+    "test" : "test"
+}

+ 92 - 95
Swifter.xcodeproj/project.pbxproj

@@ -11,23 +11,33 @@
 		7C839B7619422CFF003A6950 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C839B7519422CFF003A6950 /* ViewController.swift */; };
 		7C839B7919422CFF003A6950 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7C839B7719422CFF003A6950 /* Main.storyboard */; };
 		7C839B7B19422CFF003A6950 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7C839B7A19422CFF003A6950 /* Images.xcassets */; };
-		7C839B8719422CFF003A6950 /* SwifterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C839B8619422CFF003A6950 /* SwifterTests.swift */; };
-		7C839B9319422D50003A6950 /* HttpParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C839B9019422D50003A6950 /* HttpParser.swift */; };
-		7C839B9419422D50003A6950 /* HttpServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C839B9119422D50003A6950 /* HttpServer.swift */; };
-		7C839B9519422D50003A6950 /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C839B9219422D50003A6950 /* Socket.swift */; };
-		7C9D35DA1989ADA4008AC163 /* test.json in Resources */ = {isa = PBXBuildFile; fileRef = 7C9D35D91989ADA4008AC163 /* test.json */; };
-		7CF6E638195203E5003635F0 /* HttpResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CF6E637195203E5003635F0 /* HttpResponse.swift */; };
+		7CA4813E19A2EA8D0030B30D /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4813D19A2EA8D0030B30D /* main.swift */; };
+		7CA4814E19A2EED00030B30D /* HttpParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4814A19A2EED00030B30D /* HttpParser.swift */; };
+		7CA4814F19A2EED00030B30D /* HttpParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4814A19A2EED00030B30D /* HttpParser.swift */; };
+		7CA4815019A2EED00030B30D /* HttpResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4814B19A2EED00030B30D /* HttpResponse.swift */; };
+		7CA4815119A2EED00030B30D /* HttpResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4814B19A2EED00030B30D /* HttpResponse.swift */; };
+		7CA4815219A2EED00030B30D /* HttpServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4814C19A2EED00030B30D /* HttpServer.swift */; };
+		7CA4815319A2EED00030B30D /* HttpServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4814C19A2EED00030B30D /* HttpServer.swift */; };
+		7CA4815419A2EED00030B30D /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4814D19A2EED00030B30D /* Socket.swift */; };
+		7CA4815519A2EED00030B30D /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4814D19A2EED00030B30D /* Socket.swift */; };
+		7CA4815819A2EF2B0030B30D /* test.json in Resources */ = {isa = PBXBuildFile; fileRef = 7CA4815719A2EF2B0030B30D /* test.json */; };
+		7CA4815919A2EF560030B30D /* test.json in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7CA4815719A2EF2B0030B30D /* test.json */; };
+		7CA4815B19A2F6A60030B30D /* HttpRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4815A19A2F6A60030B30D /* HttpRequest.swift */; };
+		7CA4815C19A2F6A60030B30D /* HttpRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CA4815A19A2F6A60030B30D /* HttpRequest.swift */; };
 /* End PBXBuildFile section */
 
-/* Begin PBXContainerItemProxy section */
-		7C839B8119422CFF003A6950 /* PBXContainerItemProxy */ = {
-			isa = PBXContainerItemProxy;
-			containerPortal = 7C839B6619422CFF003A6950 /* Project object */;
-			proxyType = 1;
-			remoteGlobalIDString = 7C839B6D19422CFF003A6950;
-			remoteInfo = Swifter;
+/* Begin PBXCopyFilesBuildPhase section */
+		7CA4813919A2EA8D0030B30D /* CopyFiles */ = {
+			isa = PBXCopyFilesBuildPhase;
+			buildActionMask = 8;
+			dstPath = "";
+			dstSubfolderSpec = 7;
+			files = (
+				7CA4815919A2EF560030B30D /* test.json in CopyFiles */,
+			);
+			runOnlyForDeploymentPostprocessing = 1;
 		};
-/* End PBXContainerItemProxy section */
+/* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
 		7C839B6E19422CFF003A6950 /* Swifter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Swifter.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -36,14 +46,14 @@
 		7C839B7519422CFF003A6950 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
 		7C839B7819422CFF003A6950 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
 		7C839B7A19422CFF003A6950 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
-		7C839B8019422CFF003A6950 /* SwifterTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwifterTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
-		7C839B8519422CFF003A6950 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
-		7C839B8619422CFF003A6950 /* SwifterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwifterTests.swift; sourceTree = "<group>"; };
-		7C839B9019422D50003A6950 /* HttpParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HttpParser.swift; sourceTree = "<group>"; };
-		7C839B9119422D50003A6950 /* HttpServer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HttpServer.swift; sourceTree = "<group>"; };
-		7C839B9219422D50003A6950 /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Socket.swift; sourceTree = "<group>"; };
-		7C9D35D91989ADA4008AC163 /* test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = test.json; sourceTree = "<group>"; };
-		7CF6E637195203E5003635F0 /* HttpResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HttpResponse.swift; sourceTree = "<group>"; };
+		7CA4813B19A2EA8D0030B30D /* SwifterOSX */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SwifterOSX; sourceTree = BUILT_PRODUCTS_DIR; };
+		7CA4813D19A2EA8D0030B30D /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
+		7CA4814A19A2EED00030B30D /* HttpParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HttpParser.swift; sourceTree = "<group>"; };
+		7CA4814B19A2EED00030B30D /* HttpResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HttpResponse.swift; sourceTree = "<group>"; };
+		7CA4814C19A2EED00030B30D /* HttpServer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HttpServer.swift; sourceTree = "<group>"; };
+		7CA4814D19A2EED00030B30D /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Socket.swift; sourceTree = "<group>"; };
+		7CA4815719A2EF2B0030B30D /* test.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = test.json; sourceTree = "<group>"; };
+		7CA4815A19A2F6A60030B30D /* HttpRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HttpRequest.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -54,7 +64,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
-		7C839B7D19422CFF003A6950 /* Frameworks */ = {
+		7CA4813819A2EA8D0030B30D /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
@@ -67,8 +77,10 @@
 		7C839B6519422CFF003A6950 = {
 			isa = PBXGroup;
 			children = (
+				7CA4815619A2EF2B0030B30D /* Resources */,
+				7CA4814919A2EED00030B30D /* Common */,
 				7C839B7019422CFF003A6950 /* Swifter */,
-				7C839B8319422CFF003A6950 /* SwifterTests */,
+				7CA4813C19A2EA8D0030B30D /* SwifterOSX */,
 				7C839B6F19422CFF003A6950 /* Products */,
 			);
 			sourceTree = "<group>";
@@ -77,7 +89,7 @@
 			isa = PBXGroup;
 			children = (
 				7C839B6E19422CFF003A6950 /* Swifter.app */,
-				7C839B8019422CFF003A6950 /* SwifterTests.xctest */,
+				7CA4813B19A2EA8D0030B30D /* SwifterOSX */,
 			);
 			name = Products;
 			sourceTree = "<group>";
@@ -85,11 +97,6 @@
 		7C839B7019422CFF003A6950 /* Swifter */ = {
 			isa = PBXGroup;
 			children = (
-				7C9D35D91989ADA4008AC163 /* test.json */,
-				7CF6E637195203E5003635F0 /* HttpResponse.swift */,
-				7C839B9019422D50003A6950 /* HttpParser.swift */,
-				7C839B9119422D50003A6950 /* HttpServer.swift */,
-				7C839B9219422D50003A6950 /* Socket.swift */,
 				7C839B7319422CFF003A6950 /* AppDelegate.swift */,
 				7C839B7519422CFF003A6950 /* ViewController.swift */,
 				7C839B7719422CFF003A6950 /* Main.storyboard */,
@@ -107,21 +114,32 @@
 			name = "Supporting Files";
 			sourceTree = "<group>";
 		};
-		7C839B8319422CFF003A6950 /* SwifterTests */ = {
+		7CA4813C19A2EA8D0030B30D /* SwifterOSX */ = {
 			isa = PBXGroup;
 			children = (
-				7C839B8619422CFF003A6950 /* SwifterTests.swift */,
-				7C839B8419422CFF003A6950 /* Supporting Files */,
+				7CA4813D19A2EA8D0030B30D /* main.swift */,
 			);
-			path = SwifterTests;
+			path = SwifterOSX;
 			sourceTree = "<group>";
 		};
-		7C839B8419422CFF003A6950 /* Supporting Files */ = {
+		7CA4814919A2EED00030B30D /* Common */ = {
 			isa = PBXGroup;
 			children = (
-				7C839B8519422CFF003A6950 /* Info.plist */,
+				7CA4815A19A2F6A60030B30D /* HttpRequest.swift */,
+				7CA4814A19A2EED00030B30D /* HttpParser.swift */,
+				7CA4814B19A2EED00030B30D /* HttpResponse.swift */,
+				7CA4814C19A2EED00030B30D /* HttpServer.swift */,
+				7CA4814D19A2EED00030B30D /* Socket.swift */,
 			);
-			name = "Supporting Files";
+			path = Common;
+			sourceTree = "<group>";
+		};
+		7CA4815619A2EF2B0030B30D /* Resources */ = {
+			isa = PBXGroup;
+			children = (
+				7CA4815719A2EF2B0030B30D /* test.json */,
+			);
+			path = Resources;
 			sourceTree = "<group>";
 		};
 /* End PBXGroup section */
@@ -144,23 +162,22 @@
 			productReference = 7C839B6E19422CFF003A6950 /* Swifter.app */;
 			productType = "com.apple.product-type.application";
 		};
-		7C839B7F19422CFF003A6950 /* SwifterTests */ = {
+		7CA4813A19A2EA8D0030B30D /* SwifterOSX */ = {
 			isa = PBXNativeTarget;
-			buildConfigurationList = 7C839B8D19422D00003A6950 /* Build configuration list for PBXNativeTarget "SwifterTests" */;
+			buildConfigurationList = 7CA4814119A2EA8D0030B30D /* Build configuration list for PBXNativeTarget "SwifterOSX" */;
 			buildPhases = (
-				7C839B7C19422CFF003A6950 /* Sources */,
-				7C839B7D19422CFF003A6950 /* Frameworks */,
-				7C839B7E19422CFF003A6950 /* Resources */,
+				7CA4813719A2EA8D0030B30D /* Sources */,
+				7CA4813819A2EA8D0030B30D /* Frameworks */,
+				7CA4813919A2EA8D0030B30D /* CopyFiles */,
 			);
 			buildRules = (
 			);
 			dependencies = (
-				7C839B8219422CFF003A6950 /* PBXTargetDependency */,
 			);
-			name = SwifterTests;
-			productName = SwifterTests;
-			productReference = 7C839B8019422CFF003A6950 /* SwifterTests.xctest */;
-			productType = "com.apple.product-type.bundle.unit-test";
+			name = SwifterOSX;
+			productName = SwifterOSX;
+			productReference = 7CA4813B19A2EA8D0030B30D /* SwifterOSX */;
+			productType = "com.apple.product-type.tool";
 		};
 /* End PBXNativeTarget section */
 
@@ -174,9 +191,8 @@
 					7C839B6D19422CFF003A6950 = {
 						CreatedOnToolsVersion = 6.0;
 					};
-					7C839B7F19422CFF003A6950 = {
+					7CA4813A19A2EA8D0030B30D = {
 						CreatedOnToolsVersion = 6.0;
-						TestTargetID = 7C839B6D19422CFF003A6950;
 					};
 				};
 			};
@@ -194,7 +210,7 @@
 			projectRoot = "";
 			targets = (
 				7C839B6D19422CFF003A6950 /* Swifter */,
-				7C839B7F19422CFF003A6950 /* SwifterTests */,
+				7CA4813A19A2EA8D0030B30D /* SwifterOSX */,
 			);
 		};
 /* End PBXProject section */
@@ -206,14 +222,7 @@
 			files = (
 				7C839B7919422CFF003A6950 /* Main.storyboard in Resources */,
 				7C839B7B19422CFF003A6950 /* Images.xcassets in Resources */,
-				7C9D35DA1989ADA4008AC163 /* test.json in Resources */,
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-		7C839B7E19422CFF003A6950 /* Resources */ = {
-			isa = PBXResourcesBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
+				7CA4815819A2EF2B0030B30D /* test.json in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -224,33 +233,31 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				7CF6E638195203E5003635F0 /* HttpResponse.swift in Sources */,
+				7CA4815019A2EED00030B30D /* HttpResponse.swift in Sources */,
 				7C839B7619422CFF003A6950 /* ViewController.swift in Sources */,
-				7C839B9319422D50003A6950 /* HttpParser.swift in Sources */,
-				7C839B9519422D50003A6950 /* Socket.swift in Sources */,
-				7C839B9419422D50003A6950 /* HttpServer.swift in Sources */,
+				7CA4815419A2EED00030B30D /* Socket.swift in Sources */,
+				7CA4815219A2EED00030B30D /* HttpServer.swift in Sources */,
+				7CA4814E19A2EED00030B30D /* HttpParser.swift in Sources */,
+				7CA4815B19A2F6A60030B30D /* HttpRequest.swift in Sources */,
 				7C839B7419422CFF003A6950 /* AppDelegate.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
-		7C839B7C19422CFF003A6950 /* Sources */ = {
+		7CA4813719A2EA8D0030B30D /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				7C839B8719422CFF003A6950 /* SwifterTests.swift in Sources */,
+				7CA4815119A2EED00030B30D /* HttpResponse.swift in Sources */,
+				7CA4814F19A2EED00030B30D /* HttpParser.swift in Sources */,
+				7CA4815519A2EED00030B30D /* Socket.swift in Sources */,
+				7CA4815319A2EED00030B30D /* HttpServer.swift in Sources */,
+				7CA4813E19A2EA8D0030B30D /* main.swift in Sources */,
+				7CA4815C19A2F6A60030B30D /* HttpRequest.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 /* End PBXSourcesBuildPhase section */
 
-/* Begin PBXTargetDependency section */
-		7C839B8219422CFF003A6950 /* PBXTargetDependency */ = {
-			isa = PBXTargetDependency;
-			target = 7C839B6D19422CFF003A6950 /* Swifter */;
-			targetProxy = 7C839B8119422CFF003A6950 /* PBXContainerItemProxy */;
-		};
-/* End PBXTargetDependency section */
-
 /* Begin PBXVariantGroup section */
 		7C839B7719422CFF003A6950 /* Main.storyboard */ = {
 			isa = PBXVariantGroup;
@@ -365,39 +372,29 @@
 			};
 			name = Release;
 		};
-		7C839B8E19422D00003A6950 /* Debug */ = {
+		7CA4813F19A2EA8D0030B30D /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/Swifter.app/Swifter";
-				FRAMEWORK_SEARCH_PATHS = (
-					"$(SDKROOT)/Developer/Library/Frameworks",
-					"$(inherited)",
-				);
 				GCC_PREPROCESSOR_DEFINITIONS = (
 					"DEBUG=1",
 					"$(inherited)",
 				);
-				INFOPLIST_FILE = SwifterTests/Info.plist;
-				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
-				METAL_ENABLE_DEBUG_INFO = YES;
+				MACOSX_DEPLOYMENT_TARGET = 10.9;
+				MTL_ENABLE_DEBUG_INFO = YES;
+				ONLY_ACTIVE_ARCH = YES;
 				PRODUCT_NAME = "$(TARGET_NAME)";
-				TEST_HOST = "$(BUNDLE_LOADER)";
+				SDKROOT = macosx;
 			};
 			name = Debug;
 		};
-		7C839B8F19422D00003A6950 /* Release */ = {
+		7CA4814019A2EA8D0030B30D /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/Swifter.app/Swifter";
-				FRAMEWORK_SEARCH_PATHS = (
-					"$(SDKROOT)/Developer/Library/Frameworks",
-					"$(inherited)",
-				);
-				INFOPLIST_FILE = SwifterTests/Info.plist;
-				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
-				METAL_ENABLE_DEBUG_INFO = NO;
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+				MACOSX_DEPLOYMENT_TARGET = 10.9;
+				MTL_ENABLE_DEBUG_INFO = NO;
 				PRODUCT_NAME = "$(TARGET_NAME)";
-				TEST_HOST = "$(BUNDLE_LOADER)";
+				SDKROOT = macosx;
 			};
 			name = Release;
 		};
@@ -422,11 +419,11 @@
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
-		7C839B8D19422D00003A6950 /* Build configuration list for PBXNativeTarget "SwifterTests" */ = {
+		7CA4814119A2EA8D0030B30D /* Build configuration list for PBXNativeTarget "SwifterOSX" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (
-				7C839B8E19422D00003A6950 /* Debug */,
-				7C839B8F19422D00003A6950 /* Release */,
+				7CA4813F19A2EA8D0030B30D /* Debug */,
+				7CA4814019A2EA8D0030B30D /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;

BIN
Swifter.xcodeproj/project.xcworkspace/xcuserdata/damiankolakowski.xcuserdatad/UserInterfaceState.xcuserstate


+ 108 - 0
Swifter.xcodeproj/xcuserdata/damiankolakowski.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -193,5 +193,113 @@
             landmarkType = "3">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "Common/HttpServer.swift"
+            timestampString = "430108876.844745"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "44"
+            endingLineNumber = "44"
+            landmarkName = "HttpServer"
+            landmarkType = "3">
+            <Locations>
+               <Location
+                  shouldBeEnabled = "No"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "SwifterOSX.HttpServer.subscript.setter (Swift.String) -&gt; Swift.String"
+                  moduleName = "SwifterOSX"
+                  urlString = "file:///Users/damiankolakowski/Desktop/Swifter/Common/HttpServer.swift"
+                  timestampString = "430108980.866628"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "44"
+                  endingLineNumber = "44"
+                  offsetFromSymbolStart = "43">
+               </Location>
+               <Location
+                  shouldBeEnabled = "No"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "SwifterOSX.HttpServer.subscript.setter (Swift.String) -&gt; Swift.String"
+                  moduleName = "SwifterOSX"
+                  urlString = "file:///Users/damiankolakowski/Desktop/Swifter/Common/HttpServer.swift"
+                  timestampString = "430108980.866808"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "44"
+                  endingLineNumber = "44"
+                  offsetFromSymbolStart = "850">
+               </Location>
+            </Locations>
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "Common/HttpServer.swift"
+            timestampString = "430111339.558837"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "46"
+            endingLineNumber = "46"
+            landmarkName = "HttpServer"
+            landmarkType = "3">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            shouldBeEnabled = "No"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "Common/HttpResponse.swift"
+            timestampString = "430110038.828632"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "35"
+            endingLineNumber = "35"
+            landmarkName = "data()"
+            landmarkType = "5">
+            <Locations>
+               <Location
+                  shouldBeEnabled = "No"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "SwifterOSX.HttpResponseBody.data (SwifterOSX.HttpResponseBody)() -&gt; Swift.Optional&lt;Swift.String&gt;"
+                  moduleName = "SwifterOSX"
+                  urlString = "file:///Users/damiankolakowski/Desktop/Swifter/Common/HttpResponse.swift"
+                  timestampString = "430110038.833456"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "35"
+                  endingLineNumber = "35"
+                  offsetFromSymbolStart = "3084">
+               </Location>
+               <Location
+                  shouldBeEnabled = "No"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "SwifterOSX.HttpResponseBody.data (SwifterOSX.HttpResponseBody)() -&gt; Swift.Optional&lt;Swift.String&gt;"
+                  moduleName = "SwifterOSX"
+                  urlString = "file:///Users/damiankolakowski/Desktop/Swifter/Common/HttpResponse.swift"
+                  timestampString = "430110038.833645"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "35"
+                  endingLineNumber = "35"
+                  offsetFromSymbolStart = "3643">
+               </Location>
+            </Locations>
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

+ 86 - 0
Swifter.xcodeproj/xcuserdata/damiankolakowski.xcuserdatad/xcschemes/SwifterOSX.xcscheme

@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "0600"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "7CA4813A19A2EA8D0030B30D"
+               BuildableName = "SwifterOSX"
+               BlueprintName = "SwifterOSX"
+               ReferencedContainer = "container:Swifter.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      buildConfiguration = "Debug">
+      <Testables>
+      </Testables>
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "7CA4813A19A2EA8D0030B30D"
+            BuildableName = "SwifterOSX"
+            BlueprintName = "SwifterOSX"
+            ReferencedContainer = "container:Swifter.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+   </TestAction>
+   <LaunchAction
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      buildConfiguration = "Debug"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      allowLocationSimulation = "YES">
+      <BuildableProductRunnable>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "7CA4813A19A2EA8D0030B30D"
+            BuildableName = "SwifterOSX"
+            BlueprintName = "SwifterOSX"
+            ReferencedContainer = "container:Swifter.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      buildConfiguration = "Release"
+      debugDocumentVersioning = "YES">
+      <BuildableProductRunnable>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "7CA4813A19A2EA8D0030B30D"
+            BuildableName = "SwifterOSX"
+            BlueprintName = "SwifterOSX"
+            ReferencedContainer = "container:Swifter.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 10 - 0
Swifter.xcodeproj/xcuserdata/damiankolakowski.xcuserdatad/xcschemes/xcschememanagement.plist

@@ -9,6 +9,11 @@
 			<key>orderHint</key>
 			<integer>0</integer>
 		</dict>
+		<key>SwifterOSX.xcscheme</key>
+		<dict>
+			<key>orderHint</key>
+			<integer>1</integer>
+		</dict>
 	</dict>
 	<key>SuppressBuildableAutocreation</key>
 	<dict>
@@ -22,6 +27,11 @@
 			<key>primary</key>
 			<true/>
 		</dict>
+		<key>7CA4813A19A2EA8D0030B30D</key>
+		<dict>
+			<key>primary</key>
+			<true/>
+		</dict>
 	</dict>
 </dict>
 </plist>

+ 11 - 9
Swifter/AppDelegate.swift

@@ -16,32 +16,34 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
     let server: HttpServer = HttpServer()
     
     func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
-        server["/resources/(.+)"] = NSBundle.mainBundle().resourcePath
-        server["/test"] = { (method, url, headers) in
+        if let resDir = NSBundle.mainBundle().resourcePath {
+            server["/resources/(.+)"] = resDir
+        }
+        server["/test"] = { request in
             var headersInfo = ""
-            for (name, value) in headers {
+            for (name, value) in request.headers {
                 headersInfo += "\(name) : \(value)<br>"
             }
-            let response = "<html><body>Url: \(url)<br>Method: \(method)<br>\(headersInfo)</body></html>"
+            let response = "<html><body>Url: \(request.url)<br>Method: \(request.method)<br>\(headersInfo)</body></html>"
             return .OK(.RAW(response))
         }
-        server["/json"] = { (method, url, headers) in
+        server["/json"] = { request in
             return .OK(.JSON(["posts" : [[ "id" : 1, "message" : "hello world"],[ "id" : 2, "message" : "sample message"]], "new_updates" : false]))
         }
-        server["/redirect"] = { (method, url, headers) in
+        server["/redirect"] = { request in
             return .MovedPermanently("http://www.google.com")
         }
-        server["/long"] = { (method, url, headers) in
+        server["/long"] = { request in
             var longResponse = ""
             for k in 0..<1000 { longResponse += "(\(k)),->" }
             return .OK(.RAW(longResponse))
         }
-        server["/demo"] = { (method, url, headers) in
+        server["/demo"] = { request in
             return .OK(.RAW("<html><body><center><h2>Hello Swift</h2>" +
                 "<img src=\"https://devimages.apple.com.edgekey.net/swift/images/swift-hero_2x.png\"/><br>" +
                 "<h4>\(UIDevice().name), \(UIDevice().systemVersion)</h4></center></body></html>"))
         }
-        server["/"] = { (method, url, headers) in
+        server["/"] = { request in
             var listPage = "<html><body>Available services:<br><ul>"
             for item in self.server.routes() {
                 listPage += "<li><a href=\"\(item)\">\(item)</a></li>"

+ 3 - 4
Swifter/Base.lproj/Main.storyboard

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6154.17" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6206.8" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
     <dependencies>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.11"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7026.1"/>
     </dependencies>
     <scenes>
         <!--View Controller-->
@@ -13,10 +13,9 @@
                         <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
                     </layoutGuides>
                     <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
-                        <rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
+                        <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
-                        <simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
                     </view>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>

+ 0 - 3
Swifter/test.json

@@ -1,3 +0,0 @@
-{
-	"test" : "test"
-}

+ 58 - 0
SwifterOSX/main.swift

@@ -0,0 +1,58 @@
+//
+//  main.swift
+//  SwifterOSX
+//
+//  Created by Damian Kolakowski on 19/08/14.
+//  Copyright (c) 2014 Damian Kołakowski. All rights reserved.
+//
+
+import Foundation
+
+let server: HttpServer = HttpServer()
+
+server["/resources/(.+)"] = "~/"
+
+server["/test"] = { request in
+    var headersInfo = ""
+    for (name, value) in request.headers {
+        headersInfo += "\(name) : \(value)<br>"
+    }
+    let response = "<html><body>Url: \(request.url)<br>Method: \(request.method)<br>\(headersInfo)</body></html>"
+    return .OK(.RAW(response))
+}
+server["/json"] = { request in
+    return .OK(.JSON(["posts" : [[ "id" : 1, "message" : "hello world"],[ "id" : 2, "message" : "sample message"]], "new_updates" : false]))
+}
+server["/redirect"] = { request in
+    return .MovedPermanently("http://www.google.com")
+}
+server["/long"] = { request in
+    var longResponse = ""
+    for k in 0..<1000 { longResponse += "(\(k)),->" }
+    return .OK(.RAW(longResponse))
+}
+server["/demo"] = { request in
+    return .OK(.RAW("<html><body><center><h2>Hello Swift</h2>" +
+        "<img src=\"https://devimages.apple.com.edgekey.net/swift/images/swift-hero_2x.png\"/><br>" +
+        "<h4>\(NSHost.currentHost().localizedName)</h4></center></body></html>"))
+}
+server["/"] = { request in
+    var listPage = "<html><body>Available services:<br><ul>"
+    for item in server.routes() {
+        listPage += "<li><a href=\"\(item)\">\(item)</a></li>"
+    }
+    listPage += "</ul></body></html>"
+    return .OK(.RAW(listPage))
+}
+
+var error: NSError?
+
+if !server.start(error: &error) {
+    println("Server start error: \(error)")
+} else {
+    println("Server started !")
+    while ( true ) { };
+}
+
+
+

+ 0 - 24
SwifterTests/Info.plist

@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
-	<key>CFBundleDevelopmentRegion</key>
-	<string>en</string>
-	<key>CFBundleExecutable</key>
-	<string>${EXECUTABLE_NAME}</string>
-	<key>CFBundleIdentifier</key>
-	<string>pl.kolakowski..${PRODUCT_NAME:rfc1034identifier}</string>
-	<key>CFBundleInfoDictionaryVersion</key>
-	<string>6.0</string>
-	<key>CFBundleName</key>
-	<string>${PRODUCT_NAME}</string>
-	<key>CFBundlePackageType</key>
-	<string>BNDL</string>
-	<key>CFBundleShortVersionString</key>
-	<string>1.0</string>
-	<key>CFBundleSignature</key>
-	<string>????</string>
-	<key>CFBundleVersion</key>
-	<string>1</string>
-</dict>
-</plist>

+ 0 - 35
SwifterTests/SwifterTests.swift

@@ -1,35 +0,0 @@
-//
-//  SwifterTests.swift
-//  SwifterTests
-//
-//  Created by Damian Kolakowski on 06/06/14.
-//  Copyright (c) 2014 Damian Kołakowski. All rights reserved.
-//
-
-import XCTest
-
-class SwifterTests: XCTestCase {
-    
-    override func setUp() {
-        super.setUp()
-        // Put setup code here. This method is called before the invocation of each test method in the class.
-    }
-    
-    override func tearDown() {
-        // Put teardown code here. This method is called after the invocation of each test method in the class.
-        super.tearDown()
-    }
-    
-    func testExample() {
-        // This is an example of a functional test case.
-        XCTAssert(true, "Pass")
-    }
-    
-    func testPerformanceExample() {
-        // This is an example of a performance test case.
-        self.measureBlock() {
-            // Put the code you want to measure the time of here.
-        }
-    }
-    
-}