public interface HttpHandler
See HttpServer.
A filter is an HttpHandler that may forward the request to another handler, possibly transforming the request beforehand, and/or the response afterwards.
We recommend that a filter is created by either a constructor or a factory method that accepts the target handler. For example:
HttpHandler handler;
handler = new MyAppHandler();
handler = new FooFilter(handler);
handler = BarFilter.create(handler, params);
...
HttpServer server = new HttpServer(handler);
| Abstract Method | |
|---|---|
Async<HttpResponse> |
handle(HttpRequest request)
Generate a response for the request.
|
Async<HttpResponse> handle(HttpRequest request)
This is an Async action. The action must eventually complete with a
non-null HttpResponse, or an exception.
Note that HttpResponseImpl is a subtype of Async<HttpResponse>,
therefore it can be returned from this method.
The response status code must not be 1xx(e.g. "100 Continue"); 1xx responses are handled automatically by lower layers.
For HttpServer handler:
handle(request) is invoked for every incoming request.
It's always invoked on a fiber,
with the request as the fiber-local request.
If this action fails with an exception, HttpServer will generate
a simple internal error response.
request entity is not sharable; its body can be read only once.
after handle(request) completes,
the request body must not be read any more.
HEAD requests can be treated the same as GET requests; the server will not read the response entity body.
conditional GET requests can be treated the same as normal GET requests;
they are handled
automatically by default.
Range requests can be treated the same as normal GET requests;
they are handled
automatically by default.