Import std.net.http.work
std.net.http.work
Blocking route handlers, run on a server's worker threads.
Work routes' threads: a blocking handler, which computes or waits, runs on one of a server's Workers threads, given a Sendable copy of its request, while the main thread goes on answering the others; what it gives goes back to the main thread as a Sendable copy too, which the connection's response is made from.
std/net/http/work.fb
Types
WorkHandler
alias
Public Alias WorkHandler = Sendable Func(WorkRequest): HttpResponse
What a work route runs, on a Workers thread: a blocking function of a copy of the request, which gives the response.
WorkRequest
struct
Public Struct WorkRequest
A copy of a request that a work route's handler gets on another thread: what HttpRequest has but the connection, as Sendable values.
Examples
Function Report(request: WorkRequest): HttpResponse
// Blocking work, on a Workers thread, while the main thread answers other requests.
Local size = request.Param("size") ?? "small"
Return HttpResponse.Of(Body.Text("a {size} report"))
End Function
Local server = HttpServer()
server.Workers = 4
server.Work("/reports/:size", Report)
Try server.Listen("127.0.0.1", 8080)
// Serve answers requests, GET /reports/big with "a big report", until Stop.
server.Serve()-
Its method, as the client wrote it, like "GET".
-
Its target, as the client wrote it.
-
Its target's path, percent-encoded, without dot segments.
-
"HTTP/1.1" or "HTTP/1.0".
-
The client's address.
-
Its body's bytes.
-
Its headers, new Headers each time, made on the thread that asks.
-
Its query's names and values, a new QueryParams each time.
-
The body as text, its UTF-8, with U+FFFD for each byte that doesn't start well-formed UTF-8.
-
A path parameter its route bound, percent-decoded, or Null when it has none of that
name. -
Each path parameter its route bound, by name, a new Map each time.
-
A form's fields, when the body is application/x-www-form-urlencoded, or none.
Report an issue with this page or with FutureBlitz on GitHub.