Created
December 6, 2018 15:12
-
-
Save kjessup/d50986396f85fb5911018d1d884b0a85 to your computer and use it in GitHub Desktop.
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
import PerfectHTTP | |
import PerfectHTTPServer | |
import Dispatch | |
let serial = DispatchQueue(label: "serial") | |
var mul = 1 | |
struct NotEmpty: Codable { | |
let str: String | |
init() { | |
str = serial.sync { | |
let mulVal = String(repeating: "\(mul)", count: mul) | |
mul += 1 | |
return mulVal | |
} | |
} | |
} | |
func handler(request: HTTPRequest, response: HTTPResponse) { | |
try! response.setBody(json: NotEmpty()) | |
response.addHeader(.eTag, value: "\"thisisntreal\"") | |
response.completed(status: .ok) | |
} | |
var routes = Routes() | |
routes.add(method: .get, uri: "/", handler: handler) | |
try HTTPServer.launch(name: "localhost", | |
port: 8181, | |
routes: routes, | |
responseFilters: [ | |
(PerfectHTTPServer.HTTPFilter.contentCompression(data: [:]), .high)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment