RequestHandler¶
The handler's interface to the connection.
Embedded in a user's handler actor (or used inline). Hides the connection protocol and tracks response state to prevent double-response.
For inline handlers, create a RequestHandler, call respond(), and let
it go out of scope:
For async handlers, embed it in an actor:
actor MyHandler is hobby.HandlerReceiver
embed _handler: hobby.RequestHandler
new create(ctx: hobby.HandlerContext iso) =>
_handler = hobby.RequestHandler(consume ctx)
// ... start async work ...
be result(value: String) =>
_handler.respond(stallion.StatusOK, value)
be dispose() => None
be throttled() => None
be unthrottled() => None
Constructors¶
create¶
Create a handler from a consumed handler context.
Extracts all request data and protocol references from the context.
Parameters¶
- ctx: HandlerContext iso
Returns¶
- RequestHandler ref^
Public Functions¶
respond¶
Send a complete response with the given status and body.
Idempotent — the first call sends the response, subsequent calls are
silently ignored. Content-Length is set automatically by the connection.
For HEAD requests, the body is suppressed but Content-Length is preserved.
Parameters¶
Returns¶
- None val
respond_with_headers¶
Send a complete response with explicit headers and body.
The caller is responsible for including Content-Length or any other
required headers. For HEAD requests, the body is suppressed but all
headers are preserved.
fun ref respond_with_headers(
status: Status val,
headers: Headers val,
body': (String val | Array[U8 val] val))
: None val
Parameters¶
Returns¶
- None val
start_streaming¶
Begin a streaming response using chunked transfer encoding.
Returns StreamingStarted on success, ChunkedNotSupported for
HTTP/1.0 clients, or BodyNotNeeded for HEAD requests (the framework
sends a headers-only response automatically).
After StreamingStarted, call send_chunk() to send data and finish()
to complete the stream. If already responded, returns BodyNotNeeded.
For ChunkedNotSupported, respond() can still be called as a fallback.
fun ref start_streaming(
status: Status val,
headers: (Headers val | None val) = reference)
: (StreamingStarted val | ChunkedNotSupported val | BodyNotNeeded val)
Parameters¶
Returns¶
- (StreamingStarted val | ChunkedNotSupported val | BodyNotNeeded val)
send_chunk¶
Send a streaming chunk.
Only effective after start_streaming() returned StreamingStarted.
Silently ignored otherwise.
Parameters¶
Returns¶
- None val
finish¶
End the streaming response.
Sends the terminal chunk and signals completion. Only effective after
start_streaming() returned StreamingStarted.
Returns¶
- None val
param¶
Get a route parameter by name.
Errors if the parameter does not exist. Parameter names come from route
definitions — :id in /users/:id is accessed as param("id").
Parameters¶
- key: String val
Returns¶
- String val ?
body¶
Return the accumulated request body bytes.
Returns¶
request¶
Return the HTTP request.
Returns¶
- Request val
is_head¶
Return true if this is a HEAD request.
Returns¶
- Bool val