Manual
Request handlers
What the application returns, and how a request meets it.
Introduction#
The application returns a RequestHandler wrapping a closure; swerve calls it once per HTTP exchange with a ClientRequest to read the request and write the response on. The closure may keep the request open for as long as it likes — an event stream, a slow download — simply by not returning. See Run your application.
Guides#
- After the response – Keep working after the response is sent: send 10,000 e-mails without the client waiting.
Examples#
- All examples of this topic – 21 with their output.
Reference#
ClientRequest– One HTTP exchange with a client: the request to read, and the response to write. The application's RequestHandler is called once for each, and may keep it for as long as it likes (an event stream, a long download) by simply not returning.HeadersSentException– The final response head was already committed: its status and headers can't change.FormBody– The form data of a request, parsed when first asked for: what PHP puts in $_POST and $_FILES.RequestBody– A request's body as a PSR-7 stream, read from the ClientRequest as the application reads it.RequestHandler– What an application's swerve.php returns: the callable that serves each HTTP exchange.ServerInterface– A protocol server, such as HTTP/1.1 (--http).StaticFiles– Serves the files of a directory, and passes every other request on to the application's handler.Swerve– What swerve gives the application: its log, the cache and the messages shared by every worker, and the state of the worker.