Skip to content

Commit 4a54b82

Browse files
committed
it starts
1 parent 7ba7f28 commit 4a54b82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+7038
-61
lines changed

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Created by https://www.gitignore.io/api/xcode
2+
3+
### Xcode ###
4+
# Xcode
5+
#
6+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
7+
8+
## Build generated
9+
build/
10+
DerivedData
11+
Carthage/
12+
13+
## Various settings
14+
*.pbxuser
15+
!default.pbxuser
16+
*.mode1v3
17+
!default.mode1v3
18+
*.mode2v3
19+
!default.mode2v3
20+
*.perspectivev3
21+
!default.perspectivev3
22+
xcuserdata
23+
24+
## Other
25+
*.xccheckout
26+
*.moved-aside
27+
*.xcuserstate
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// main.swift
2+
//
3+
// The MIT License (MIT)
4+
//
5+
// Copyright (c) 2015 Zewo
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all
15+
// copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
// SOFTWARE.
24+
25+
func respond(request: HTTPRequest, completion: HTTPResponse -> Void) {
26+
completion(
27+
HTTPResponse(
28+
statusCode: 200,
29+
reasonPhrase: "OK",
30+
majorVersion: 1,
31+
minorVersion: 1,
32+
headers: [:],
33+
body: []
34+
)
35+
)
36+
}
37+
38+
let server = HTTPServer(port: 8080, respond: respond)
39+
server.start()

Aeon.xcodeproj/project.pbxproj

+487-6
Large diffs are not rendered by default.

Aeon.xcodeproj/xcuserdata/paulofaria.xcuserdatad/xcschemes/Aeon.xcscheme

+53
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,49 @@
55
<BuildAction
66
parallelizeBuildables = "YES"
77
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "B0D5216F1BE4F753002063D5"
18+
BuildableName = "Aeon.framework"
19+
BlueprintName = "Aeon"
20+
ReferencedContainer = "container:Aeon.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
824
</BuildAction>
925
<TestAction
1026
buildConfiguration = "Debug"
1127
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
1228
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
1329
shouldUseLaunchSchemeArgsEnv = "YES">
1430
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "B0D521791BE4F753002063D5"
36+
BuildableName = "AeonTests.xctest"
37+
BlueprintName = "AeonTests"
38+
ReferencedContainer = "container:Aeon.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
1541
</Testables>
42+
<MacroExpansion>
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "B0D5216F1BE4F753002063D5"
46+
BuildableName = "Aeon.framework"
47+
BlueprintName = "Aeon"
48+
ReferencedContainer = "container:Aeon.xcodeproj">
49+
</BuildableReference>
50+
</MacroExpansion>
1651
<AdditionalOptions>
1752
</AdditionalOptions>
1853
</TestAction>
@@ -26,6 +61,15 @@
2661
debugDocumentVersioning = "YES"
2762
debugServiceExtension = "internal"
2863
allowLocationSimulation = "YES">
64+
<MacroExpansion>
65+
<BuildableReference
66+
BuildableIdentifier = "primary"
67+
BlueprintIdentifier = "B0D5216F1BE4F753002063D5"
68+
BuildableName = "Aeon.framework"
69+
BlueprintName = "Aeon"
70+
ReferencedContainer = "container:Aeon.xcodeproj">
71+
</BuildableReference>
72+
</MacroExpansion>
2973
<AdditionalOptions>
3074
</AdditionalOptions>
3175
</LaunchAction>
@@ -35,6 +79,15 @@
3579
savedToolIdentifier = ""
3680
useCustomWorkingDirectory = "NO"
3781
debugDocumentVersioning = "YES">
82+
<MacroExpansion>
83+
<BuildableReference
84+
BuildableIdentifier = "primary"
85+
BlueprintIdentifier = "B0D5216F1BE4F753002063D5"
86+
BuildableName = "Aeon.framework"
87+
BlueprintName = "Aeon"
88+
ReferencedContainer = "container:Aeon.xcodeproj">
89+
</BuildableReference>
90+
</MacroExpansion>
3891
</ProfileAction>
3992
<AnalyzeAction
4093
buildConfiguration = "Debug">

Aeon.xcodeproj/xcuserdata/paulofaria.xcuserdatad/xcschemes/xcschememanagement.plist

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<dict>
55
<key>SchemeUserState</key>
66
<dict>
7+
<key>Aeon Command Line Application.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>1</integer>
11+
</dict>
712
<key>Aeon.xcscheme</key>
813
<dict>
914
<key>orderHint</key>
@@ -22,6 +27,11 @@
2227
<key>primary</key>
2328
<true/>
2429
</dict>
30+
<key>B0D521BE1BE53AD7002063D5</key>
31+
<dict>
32+
<key>primary</key>
33+
<true/>
34+
</dict>
2535
</dict>
2636
</dict>
2737
</plist>

Aeon/Aeon.h

-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +0,0 @@
1-
//
2-
// Aeon.h
3-
// Aeon
4-
//
5-
// Created by Paulo Faria on 10/31/15.
6-
// Copyright © 2015 Zewo. All rights reserved.
7-
//
8-
9-
#import <Cocoa/Cocoa.h>
10-
11-
//! Project version number for Aeon.
12-
FOUNDATION_EXPORT double AeonVersionNumber;
13-
14-
//! Project version string for Aeon.
15-
FOUNDATION_EXPORT const unsigned char AeonVersionString[];
16-
17-
// In this header, you should import all the public headers of your framework using statements like #import <Aeon/PublicHeader.h>
18-
19-

Aeon/HTTPParser.swift

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// HTTPParser.swift
2+
//
3+
// The MIT License (MIT)
4+
//
5+
// Copyright (c) 2015 Zewo
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all
15+
// copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
// SOFTWARE.
24+
25+
struct HTTPParser : RequestParserType {
26+
func parseRequest(client: StreamType, completion: Result<HTTPRequest> -> Void) {
27+
let parser = HTTPRequestParser { request in
28+
completion(Result(request))
29+
}
30+
31+
client.receive { result in
32+
result.success { data in
33+
do {
34+
try parser.parse(data)
35+
} catch {
36+
completion(Result(error))
37+
}
38+
}
39+
result.failure { error in
40+
completion(Result(error))
41+
}
42+
}
43+
}
44+
}

Aeon/HTTPRequest+KeepAliveType.swift

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// HTTPRequest+KeepAliveType.swift
2+
//
3+
// The MIT License (MIT)
4+
//
5+
// Copyright (c) 2015 Zewo
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all
15+
// copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
// SOFTWARE.
24+
25+
extension HTTPRequest : KeepAliveType {
26+
var shouldKeepAlive: Bool {
27+
return keepAlive
28+
}
29+
}

Aeon/HTTPSerializer.swift

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// HTTPSerializer.swift
2+
//
3+
// The MIT License (MIT)
4+
//
5+
// Copyright (c) 2015 Zewo
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all
15+
// copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
// SOFTWARE.
24+
25+
struct HTTPSerializer : ResponseSerializerType {
26+
func serializeResponse(client: StreamType, response: HTTPResponse, completion: Result<Void> -> Void) {
27+
var string = "HTTP/\(response.majorVersion).\(response.minorVersion) \(response.statusCode) \(response.reasonPhrase)\r\n"
28+
29+
for (name, value) in response.headers {
30+
string += "\(name): \(value)\r\n"
31+
}
32+
33+
string += "\r\n"
34+
35+
var data = string.utf8.map { Int8($0) }
36+
data += response.body
37+
38+
client.send(data, completion: completion)
39+
}
40+
}

Aeon/HTTPServer.swift

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// HTTPServer.swift
2+
//
3+
// The MIT License (MIT)
4+
//
5+
// Copyright (c) 2015 Zewo
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all
15+
// copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
// SOFTWARE.
24+
25+
struct HTTPServer : RequestResponseServer {
26+
var server: ServerType
27+
var parser = HTTPParser()
28+
var serializer = HTTPSerializer()
29+
30+
private let respondRequest: (request: HTTPRequest, completion: HTTPResponse -> Void) -> Void
31+
32+
init(port: Int, respond: (request: HTTPRequest, completion: HTTPResponse -> Void) -> Void) {
33+
self.server = TCPServer(port: port)
34+
self.respondRequest = respond
35+
}
36+
37+
func respond(request: HTTPRequest, completion: HTTPResponse -> Void) {
38+
respondRequest(request: request, completion: completion)
39+
}
40+
}

0 commit comments

Comments
 (0)