#include <Pt/Http/Responder.h>
Handles one HTTP request and writes the reply. More...
Inherited by WebSocketResponder.
Public Member Functions | |
| Responder (Service &s) | |
| Construct with service. | |
| virtual | ~Responder () |
| Destructor. | |
| Service & | service () |
| Returns the service for which to respond. | |
| const Service & | service () const |
| Returns the service for which to respond. | |
| void | beginRequest (Request &request, Reply &reply, System::EventLoop &loop) |
| Called when the request header was received. | |
| void | readRequest (Request &request, Reply &reply, System::EventLoop &loop) |
| Called when request body data was received. | |
| void | beginReply (const Request &request, Reply &reply, System::EventLoop &loop) |
| Called when request is complete. | |
| void | writeReply (const Request &request, Reply &reply, System::EventLoop &loop) |
| Write responding reply. | |
Protected Member Functions | |
| virtual void | onBeginRequest (Request &request, Reply &reply, System::EventLoop &loop)=0 |
| Called when the request header was received. | |
| virtual void | onReadRequest (Request &request, Reply &reply, System::EventLoop &loop)=0 |
| Called for each chunk of the request body. | |
| virtual void | onBeginReply (const Request &request, Reply &reply, System::EventLoop &loop)=0 |
| Called when request is complete. | |
| virtual void | onWriteReply (const Request &request, Reply &reply, System::EventLoop &loop)=0 |
| Write responding reply. | |
| void | setReady (bool isFinished) |
| Sets whether the current step is complete. | |
| void | setFinished (bool isFinished) |
| Sets whether the exchange is finished. | |
Responder is the per-exchange handler in the server model. A Service creates it for a mapped request and releases it when the reply has been sent. Derive from it and implement the four callbacks, which the server calls in order.
onBeginRequest() runs when the request header is available, so the responder can inspect fields and prepare the reply. onReadRequest() runs for each chunk of the request body, and may be called more than once. onBeginReply() runs when the request is complete and the reply should start. onWriteReply() runs when a previous Reply::beginSend(false) needs another chunk of the reply body, which is how a large reply is written in chunked encoding.
Finish the reply with Reply::beginSend() and the completion flag set to true. That call may be made from an earlier callback, in which case the remaining callbacks are skipped and the rest of the request is ignored. service() is the service that created this responder.
The example is a responder that ignores the request body and writes a fixed reply. beginSend(true) completes the reply in onBeginReply(), so onWriteReply() stays empty.