#include <Pt/Http/Service.h>
Factory for request responders. More...
Inherits NonCopyable.
Inherited by BasicService< R, Alloc >, WebSocketService, HttpService, HttpService, and .
Public Member Functions | |
| Service () | |
| Default Constructor. | |
| virtual | ~Service () |
| Destructor. | |
| Responder * | getResponder (const Request &) |
| Creates a responder to handle request received by a server. | |
| void | releaseResponder (Responder *) |
| Destroys a responder created by a server. | |
| Signal< IOStream *, const std::string & > & | upgradeRequested () |
| Returns the signal emitted when a request upgrades to this service. | |
Protected Member Functions | |
| virtual Responder * | onGetResponder (const Request &)=0 |
| Creates a responder to handle request received by a server. | |
| virtual void | onReleaseResponder (Responder *)=0 |
| Destroys a responder created by a server. | |
Service is the responder factory in the server model. The server does not construct responders itself: when a servlet maps a request, the service's getResponder() calls onGetResponder(), and when the reply has been sent or the exchange has failed, releaseResponder() calls onReleaseResponder(). The service must remain alive while any responder it created is still in use.
BasicService is that factory for a single responder type, using an allocator that defaults to new and delete. Use a custom Service when the responder type depends on the request headers, or when responders are pooled.
upgradeRequested() is emitted when a request asks to upgrade the connection. The signal provides the accepted IOStream and the value of the Upgrade header. That stream is the upgraded connection, not the HTTP message body.
The example is the usual factory: a BasicService for a responder type. The equivalent hand-written service implements onGetResponder() and onReleaseResponder() in the same way.