32 lines
1.1 KiB
Plaintext
32 lines
1.1 KiB
Plaintext
route(request: dever.http.Request) (response: dever.http.Response) {
|
|
response = selected(request.target, request.body)
|
|
}
|
|
|
|
selected(path: "/json", body: Bytes) (response: dever.http.Response) {
|
|
response = dever.http.Response { status = 200, headers = [dever.http.header("content-type", "application/json")], body = dever.bytes.fromText("{\"ok\":true}") }
|
|
}
|
|
selected(path: "/echo", body: Bytes) (response: dever.http.Response) {
|
|
response = dever.http.Response { status = 200, headers = [dever.http.header("content-type", "application/octet-stream")], body = body }
|
|
}
|
|
selected(path: other, body: Bytes) (response: dever.http.Response) {
|
|
response = dever.http.Response { status = 404, headers = [], body = dever.bytes.fromText("") }
|
|
}
|
|
|
|
serve(connections: Int) () {
|
|
listener = dever.net.listen("127.0.0.1", 0)
|
|
port = dever.net.port(listener)
|
|
limits = dever.http.defaultLimits()
|
|
limits.connections = connections
|
|
limits.body_bytes = 65536
|
|
blocking(dever.io.println("READY|" + int.toText(port)))
|
|
dever.http.serve(route, listener, limits)
|
|
}
|
|
|
|
main() () {
|
|
serve(2048)
|
|
}
|
|
|
|
overload() () {
|
|
serve(8192)
|
|
}
|