HTTP response wrapper bound to a MantisBase instance.
More...
#include <http.h>
|
| | MbResponse (const MantisBase &app) |
| | ~MbResponse ()=default |
| const drogon::HttpResponsePtr & | drogonResponse () const |
| int | getStatus () const |
| void | setStatus (int s) const |
| std::string | version () const |
| std::string | body () const |
| void | setBody (const std::string &b) |
| std::string | location () const |
| void | setLocation (const std::string &b) const |
| bool | hasHeader (const std::string &key) const |
| std::string | headerValue (const std::string &key, const std::string &def="") const |
| void | setHeader (const std::string &key, const std::string &val) const |
| void | setAuthTokenCookie (const std::string &token, int max_age_seconds) const |
| void | clearAuthTokenCookie () const |
| void | setRedirect (const std::string &url, int status=302) const |
| void | setContent (const char *s, size_t n, const std::string &content_type) const |
| void | setContent (const std::string &s, const std::string &content_type) const |
| void | setContent (std::string &&s, const std::string &content_type) const |
| void | setFileContent (const std::string &path, const std::string &content_type) const |
| void | setFileContent (const std::string &path) const |
| void | send (int statusCode, const std::string &data="", const std::string &content_type="text/plain") const |
| void | sendJSON (int statusCode=200, const json &data=json::object()) const |
| void | sendText (int statusCode=200, const std::string &data="") const |
| void | sendHtml (int statusCode=200, const std::string &data="") const |
| void | sendEmpty (int statusCode=204) const |
| | MbAppMixin (const MantisBase &app) |
| | Constrictor for instantiating this interface.
|
| | MbAppMixin (MbAppMixin &&)=default |
| MbAppMixin & | operator= (MbAppMixin &&)=delete |
| | MbAppMixin (const MbAppMixin &)=default |
| MbAppMixin & | operator= (const MbAppMixin &)=delete |
| const MantisBase & | mbApp () const |
| | Application that owns this service or request context.
|
| const MbLogger & | logger () const |
HTTP response wrapper bound to a MantisBase instance.
Constructed by the router for each request; use sendJSON(), send(), or header helpers to build the outgoing response.
◆ MbResponse()
| mb::MbResponse::MbResponse |
( |
const MantisBase & | app | ) |
|
|
explicit |
◆ ~MbResponse()
| mb::MbResponse::~MbResponse |
( |
| ) |
|
|
default |
◆ body()
| std::string mb::MbResponse::body |
( |
| ) |
const |
|
nodiscard |
◆ clearAuthTokenCookie()
| void mb::MbResponse::clearAuthTokenCookie |
( |
| ) |
const |
Clear the HttpOnly auth cookie.
◆ drogonResponse()
| const drogon::HttpResponsePtr & mb::MbResponse::drogonResponse |
( |
| ) |
const |
|
nodiscard |
- Returns
- Underlying Drogon response pointer.
◆ getStatus()
| int mb::MbResponse::getStatus |
( |
| ) |
const |
|
nodiscard |
◆ hasHeader()
| bool mb::MbResponse::hasHeader |
( |
const std::string & | key | ) |
const |
|
nodiscard |
◆ headerValue()
| std::string mb::MbResponse::headerValue |
( |
const std::string & | key, |
|
|
const std::string & | def = "" ) const |
|
nodiscard |
◆ location()
| std::string mb::MbResponse::location |
( |
| ) |
const |
|
nodiscard |
NOTE: dukglue expects non-const function
◆ registerDuktapeMethods()
| void mb::MbResponse::registerDuktapeMethods |
( |
| ) |
|
|
static |
Register response helper methods on the Duktape res object.
◆ send()
| void mb::MbResponse::send |
( |
int | statusCode, |
|
|
const std::string & | data = "", |
|
|
const std::string & | content_type = "text/plain" ) const |
Send response with status, body, and content type.
◆ sendEmpty()
| void mb::MbResponse::sendEmpty |
( |
int | statusCode = 204 | ) |
const |
Send empty body (default 204 No Content).
◆ sendHtml()
| void mb::MbResponse::sendHtml |
( |
int | statusCode = 200, |
|
|
const std::string & | data = "" ) const |
◆ sendJSON()
| void mb::MbResponse::sendJSON |
( |
int | statusCode = 200, |
|
|
const json & | data = json::object() ) const |
Send the standard MantisBase JSON envelope { status, error, data }.
◆ sendText()
| void mb::MbResponse::sendText |
( |
int | statusCode = 200, |
|
|
const std::string & | data = "" ) const |
◆ setAuthTokenCookie()
| void mb::MbResponse::setAuthTokenCookie |
( |
const std::string & | token, |
|
|
int | max_age_seconds ) const |
Set the HttpOnly auth cookie used by login/refresh handlers.
◆ setBody()
| void mb::MbResponse::setBody |
( |
const std::string & | b | ) |
|
◆ setContent() [1/3]
| void mb::MbResponse::setContent |
( |
const char * | s, |
|
|
size_t | n, |
|
|
const std::string & | content_type ) const |
Set response body with explicit content type.
◆ setContent() [2/3]
| void mb::MbResponse::setContent |
( |
const std::string & | s, |
|
|
const std::string & | content_type ) const |
◆ setContent() [3/3]
| void mb::MbResponse::setContent |
( |
std::string && | s, |
|
|
const std::string & | content_type ) const |
◆ setFileContent() [1/2]
| void mb::MbResponse::setFileContent |
( |
const std::string & | path | ) |
const |
◆ setFileContent() [2/2]
| void mb::MbResponse::setFileContent |
( |
const std::string & | path, |
|
|
const std::string & | content_type ) const |
Stream a file from disk as the response body.
◆ setHeader()
| void mb::MbResponse::setHeader |
( |
const std::string & | key, |
|
|
const std::string & | val ) const |
◆ setLocation()
| void mb::MbResponse::setLocation |
( |
const std::string & | b | ) |
const |
◆ setRedirect()
| void mb::MbResponse::setRedirect |
( |
const std::string & | url, |
|
|
int | status = 302 ) const |
Set Location header and status for redirects.
◆ setStatus()
| void mb::MbResponse::setStatus |
( |
int | s | ) |
const |
◆ version()
| std::string mb::MbResponse::version |
( |
| ) |
const |
|
nodiscard |
The documentation for this class was generated from the following files:
- /home/runner/work/mantisbase/mantisbase/include/mantisbase/core/http.h
- /home/runner/work/mantisbase/mantisbase/src/core/http_response.cpp