Builds and sends an HTTP/1.1 response. More...
#include <httpd.hpp>
Public Member Functions | |
| TResponse (std::function< TFuture< ssize_t >(const void *, size_t)> writer) | |
| void | SetStatus (int statusCode) |
Sets the HTTP status code (default is 200). Must be called before SendHeaders. | |
| void | SetHeader (const std::string &name, const std::string &value) |
Adds or replaces a response header. Must be called before SendHeaders. | |
| TFuture< void > | SendHeaders () |
| Sends the status line and all accumulated headers to the client. | |
| TFuture< void > | WriteBodyChunk (const char *data, size_t size) |
Writes data as one chunk using Transfer-Encoding: chunked. | |
| TFuture< void > | WriteBodyFull (const std::string &data) |
Sends headers (with Content-Length) and the full body in one call. | |
| bool | IsClosed () const |
Returns true if the connection has been closed or an error occurred. | |
| int | StatusCode () const |
Returns the status code set via SetStatus (default 200). | |
Builds and sends an HTTP/1.1 response.
Typical usage in a router handler:
SetStatus and SetHeader must be called before SendHeaders. After SendHeaders, only body-write methods may be called.
| TFuture< void > NNet::TResponse::SendHeaders | ( | ) |
Sends the status line and all accumulated headers to the client.
Must be called exactly once, after SetStatus/SetHeader and before any body write. If WriteBodyFull is used instead, SendHeaders is called implicitly.
| TFuture< void > NNet::TResponse::WriteBodyChunk | ( | const char * | data, |
| size_t | size | ||
| ) |
Writes data as one chunk using Transfer-Encoding: chunked.
Call SendHeaders() first (without a Content-Length header). Repeat for each chunk; the final zero-length chunk is sent automatically when the connection closes.
| TFuture< void > NNet::TResponse::WriteBodyFull | ( | const std::string & | data | ) |
Sends headers (with Content-Length) and the full body in one call.
Implies SendHeaders() — do not call it separately when using this method.