-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added in FlameType to allow for choice between single threaded and mu…
…ltiple
- Loading branch information
Elliott Minns
committed
Jan 20, 2017
1 parent
cae47f7
commit f38b214
Showing
8 changed files
with
197 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Request.swift | ||
// Blackfire | ||
// | ||
// Created by Elliott Minns on 20/01/2017. | ||
// | ||
// | ||
|
||
import Foundation | ||
|
||
public class Request: HTTPRequest { | ||
public let params: [String: String] | ||
|
||
init(params: [String: String], raw: HTTPRequest) { | ||
self.params = params | ||
super.init(headers: raw.headers, method: raw.method, | ||
body: raw.body, path: raw.path, httpProtocol: raw.httpProtocol) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// RequestHandler.swift | ||
// Blackfire | ||
// | ||
// Created by Elliott Minns on 20/01/2017. | ||
// | ||
// | ||
|
||
import Foundation | ||
|
||
struct RequestHandler { | ||
let nodes: [Node] | ||
|
||
init(nodes: [Node]) { | ||
self.nodes = nodes | ||
} | ||
|
||
func handle(request: HTTPRequest, response: HTTPResponse) { | ||
let handlers = nodes.last?.handlers[request.method] ?? [] | ||
|
||
guard handlers.count > 0 else { | ||
response.send(status: 404) | ||
return | ||
} | ||
/* | ||
let comps = request.path.components(separatedBy: "/") | ||
let params = self.nodes.reduce((0, [:])) { (result, node) -> (Int, [String: String]) in | ||
if !node.path.isEmpty && node.path[node.path.startIndex] == ":" { | ||
let key = node.path.substring(from: node.path.index(after: node.path.startIndex)) | ||
let value = comps[result.0] | ||
return (result.0 + 1, [key: value]) | ||
} else { | ||
return (result.0 + 1, result.1) | ||
} | ||
}.1 | ||
*/ | ||
let params: [String: String] = [:] | ||
let request = Request(params: params, raw: request) | ||
handlers.forEach { handler in | ||
handler(request, response) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters