ClikaRT::http::ServerResponse
class
Header: ClikaRT/http/server.h
A response a handler returns. Build with a factory and chain with_header / with_cookie. Move-only.
Static member functions
text()
static ServerResponse text(std::string_view body, int status = 200)
A text/plain response carrying body at status.
Declared in ClikaRT/http/server.h, line 171
json()
static ServerResponse json(std::string_view body, int status = 200)
An application/json response carrying body at status.
Declared in ClikaRT/http/server.h, line 173
html()
static ServerResponse html(std::string_view body, int status = 200)
A text/html response carrying body at status.
Declared in ClikaRT/http/server.h, line 175
bytes()
static ServerResponse bytes(
std::string_view body,
std::string_view content_type,
int status = 200
)
Raw bytes with an explicit content_type at status.
Declared in ClikaRT/http/server.h, line 177
error()
static ServerResponse error(int status)
status-only (page via the error handler)
Declared in ClikaRT/http/server.h, line 179
redirect()
static ServerResponse redirect(std::string_view location, int status = 302)
location is emitted verbatim; validate it (same-origin) before building it from request input, or it becomes an open redirect. Redirect to location at status (default 302 Found).
Declared in ClikaRT/http/server.h, line 183
file()
static ServerResponse file(std::string_view path)
Serve a file (MIME inferred from the extension). path is caller-owned; contain it before deriving it from untrusted input (path traversal).
Declared in ClikaRT/http/server.h, line 186
stream()
static ServerResponse stream(
std::string_view content_type,
std::function<Result<std::optional<std::string>>()> next
)
A chunked streaming body: next is pulled until it returns nullopt (done). It runs on a pool worker; don't block forever, and don't capture the ServerRequest. A throw / failure Result aborts the stream (logged at Warn on ClikaRT::logging::logger(); headers are already out, so the log line is the only failure signal). An empty next answers with the server's 500 page, and one Error line on that logger names the cause.
Declared in ClikaRT/http/server.h, line 194
sse()
static ServerResponse sse(std::function<Result<std::optional<ServerSentEvent>>()> next)
A Server-Sent-Events body: next yields one event per call, nullopt ⇒ done. Same worker / non-blocking rules as stream, and the same answer to an empty next.
Declared in ClikaRT/http/server.h, line 199
Member functions
ServerResponse()
ServerResponse(ServerResponse&&) noexcept
Move-only: transfers the response.
Declared in ClikaRT/http/server.h, line 163
operator=()
ServerResponse& operator=(ServerResponse&&) noexcept
Move-assign: transfers the response.
Declared in ClikaRT/http/server.h, line 165
~ServerResponse()
~ServerResponse()
Releases the response.
Declared in ClikaRT/http/server.h, line 167
with_header()
ServerResponse& with_header(std::string_view name, std::string_view value) &
Append a header (chainable). Multiple values for one name are allowed.
Declared in ClikaRT/http/server.h, line 202
with_cookie()
ServerResponse& with_cookie(Cookie cookie) &
Set a cookie (chainable); formats a Set-Cookie header.
Declared in ClikaRT/http/server.h, line 204