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 162
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 164
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 166
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 168
error()
static ServerResponse error(int status)
status-only (page via the error handler)
Declared in ClikaRT/http/server.h, line 170
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 174
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 177
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).
Declared in ClikaRT/http/server.h, line 184
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.
Declared in ClikaRT/http/server.h, line 188
Member functions
ServerResponse()
ServerResponse(ServerResponse&&) noexcept
Move-only: transfers the response.
Declared in ClikaRT/http/server.h, line 154
operator=()
ServerResponse& operator=(ServerResponse&&) noexcept
Move-assign: transfers the response.
Declared in ClikaRT/http/server.h, line 156
~ServerResponse()
~ServerResponse()
Releases the response.
Declared in ClikaRT/http/server.h, line 158
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 191
with_cookie()
ServerResponse& with_cookie(Cookie cookie) &
Set a cookie (chainable); formats a Set-Cookie header.
Declared in ClikaRT/http/server.h, line 193