#include <Pt/Http/Servlet.h>
Maps requests to a service. More...
Inherits NonCopyable.
Inherited by MapAny, and MapUrl.
Public Member Functions | |
| Servlet (Service &s) | |
| Construct with service. | |
| Servlet (Service &s, Authorizer &a) | |
| Construct with service and authorizer. | |
| virtual | ~Servlet () |
| Destructor. | |
| void | setShutdown (bool shutdown=true) |
| Set shutdown flag. | |
| bool | isIdle () |
| Returns true if not in use. | |
| void | detach () |
| Detach from server. | |
| bool | isMapped (const Request &request) const |
| Returns true if request is mapped to the service. | |
| Service * | service () |
| Returns the service to map requests to. | |
| Authorizer * | authorizer () |
| Returns the authorizer. | |
Protected Member Functions | |
| virtual bool | onRequest (const Request &request) const =0 |
| Returns true if the servlet should process the request. | |
Servlet is the mapping rule in the server model. It combines a Service with an optional Authorizer and decides whether an incoming request belongs to that service. The server calls isMapped(), which forwards to onRequest(), and the first servlet that returns true handles the request.
Construct it with a service, or with a service and an authorizer. Several servlets may share one service, so the same resource can appear under more than one name, and they may share one authorizer. service() and authorizer() return those pointers.
MapUrl maps one exact URL. MapAny maps every request. A custom servlet implements onRequest() and returns true when its service should run. Do not reimplement MapUrl unless the mapping rule is actually different.
setShutdown() marks the servlet so it stops taking new work, and isIdle() is true when no exchange is using it. detach() unregisters it from the server that holds it.
The example is the usual mapping: one URL, one service. The optional authorizer is passed as a third argument.