Server¶
HTTP/HTTPS server that accepts connections and dispatches requests through a compiled routing tree.
Created with a BuiltApplication (from Application.build()) and a
ServerNotify for lifecycle events. Two constructors prevent
accidentally serving HTTP when HTTPS is intended.
actor Main is hobby.ServerNotify
let _env: Env
new create(env: Env) =>
_env = env
let auth = lori.TCPListenAuth(env.root)
let app = hobby.Application
.> get("/", {(ctx) =>
hobby.RequestHandler(consume ctx)
.respond(stallion.StatusOK, "Hello!")
} val)
match app.build()
| let built: hobby.BuiltApplication =>
hobby.Server(auth, built, this
where host = "0.0.0.0", port = "8080")
| let err: hobby.ConfigError =>
env.err.print(err.message)
end
be listening(server: hobby.Server,
host: String, service: String)
=>
_env.out.print(
"Listening on " + host + ":" + service)
Call dispose() to shut down. In-flight connections drain naturally.
Implements¶
- TCPListenerActor[RuntimeBackend ref] tag
Constructors¶
create¶
Start an HTTP server.
host and port control the listener bind address. config is
passed through to Stallion for parser limits (max body size, idle
timeout, etc.) — the host/port in config are not used for
binding.
new tag create(
auth: TCPListenAuth val,
app: BuiltApplication val,
notify: ServerNotify tag,
host: String val = "localhost",
port: String val = "0",
handler_timeout: (HandlerTimeout | None val) = DefaultHandlerTimeout(),
config: ServerConfig val = stallion.ServerConfig("localhost", "0"))
: Server tag^
Parameters¶
- auth: TCPListenAuth val
- app: BuiltApplication val
- notify: ServerNotify tag
- host: String val = "localhost"
- port: String val = "0"
- handler_timeout: (HandlerTimeout | None val) = DefaultHandlerTimeout()
- config: ServerConfig val = stallion.ServerConfig("localhost", "0")
Returns¶
- Server tag^
ssl¶
Start an HTTPS server.
Identical to create except connections use TLS via the provided
SSLContext. The context must be configured with a certificate and
private key.
new tag ssl(
auth: TCPListenAuth val,
app: BuiltApplication val,
notify: ServerNotify tag,
ssl_ctx: SSLContext val,
host: String val = "localhost",
port: String val = "0",
handler_timeout: (HandlerTimeout | None val) = DefaultHandlerTimeout(),
config: ServerConfig val = stallion.ServerConfig("localhost", "0"))
: Server tag^
Parameters¶
- auth: TCPListenAuth val
- app: BuiltApplication val
- notify: ServerNotify tag
- ssl_ctx: SSLContext val
- host: String val = "localhost"
- port: String val = "0"
- handler_timeout: (HandlerTimeout | None val) = DefaultHandlerTimeout()
- config: ServerConfig val = stallion.ServerConfig("localhost", "0")
Returns¶
- Server tag^
Public Behaviours¶
dispose¶
Shut down the server. Closes the listener and disposes the shared timer actor. In-flight connections drain naturally. Idempotent.