|
MantisBase v0.3.4
|
Wrapper around httplib::Response for consistent API. More...
#include <http.h>
Public Member Functions | |
| MantisResponse (httplib::Response &_resp) | |
| Construct response wrapper. | |
| ~MantisResponse ()=default | |
| Destructor. | |
| httplib::Response & | getResponse () const |
| int | getStatus () const |
| Get HTTP status code. | |
| void | setStatus (int s) |
| Set HTTP status code. | |
| std::string | getVersion () const |
| Get HTTP version. | |
| void | setVersion (const std::string &b) |
| Set HTTP version. | |
| std::string | getBody () const |
| Get response body. | |
| void | setBody (const std::string &b) |
| Set response body. | |
| std::string | getLocation () const |
| Get redirect location. | |
| void | setLocation (const std::string &b) |
| Set redirect location. | |
| std::string | getReason () const |
| Get status reason phrase. | |
| void | setReason (const std::string &b) |
| Set status reason phrase. | |
| bool | hasHeader (const std::string &key) const |
| Check if header exists. | |
| std::string | getHeaderValue (const std::string &key, const char *def="", size_t id=0) const |
| Get header value. | |
| size_t | getHeaderValueU64 (const std::string &key, size_t def=0, size_t id=0) const |
| Get header value as unsigned 64-bit integer. | |
| size_t | getHeaderValueCount (const std::string &key) const |
| Get count of header values. | |
| void | setHeader (const std::string &key, const std::string &val) const |
| Set response header. | |
| bool | hasTrailer (const std::string &key) const |
| Check if trailer exists. | |
| std::string | getTrailerValue (const std::string &key, size_t id=0) const |
| Get trailer value. | |
| size_t | getTrailerValueCount (const std::string &key) const |
| Get count of trailer values. | |
| void | setRedirect (const std::string &url, int status=httplib::StatusCode::Found_302) const |
| Set redirect response. | |
| void | setContent (const char *s, size_t n, const std::string &content_type) const |
| Set response content from buffer. | |
| void | setContent (const std::string &s, const std::string &content_type) const |
| Set response content from string. | |
| void | setContent (std::string &&s, const std::string &content_type) const |
| Set response content from moved string. | |
| void | setFileContent (const std::string &path, const std::string &content_type) const |
| Set response content from file with MIME type. | |
| void | setFileContent (const std::string &path) const |
| Set response content from file (auto-detect MIME type). | |
| void | send (int statusCode, const std::string &data="", const std::string &content_type="text/plain") const |
| Send response with status, data, and content type. | |
| void | sendJSON (int statusCode=200, const json &data=json::object()) const |
| Send JSON response. | |
| void | sendText (int statusCode=200, const std::string &data="") const |
| Send text response. | |
| void | sendHtml (int statusCode=200, const std::string &data="") const |
| Send HTML response. | |
| void | sendEmpty (int statusCode=204) const |
| Send empty response (no body). | |
Static Public Member Functions | |
| static void | registerDuktapeMethods () |
| Register MantisResponse methods for JavaScript/Duktape. | |
Wrapper around httplib::Response for consistent API.
Provides convenient methods for setting response status, headers, and body with support for JSON, text, HTML, and file responses.
|
explicit |
Construct response wrapper.
| _resp | Reference to httplib::Response object |
|
default |
Destructor.
| std::string mb::MantisResponse::getBody | ( | ) | const |
Get response body.
| std::string mb::MantisResponse::getHeaderValue | ( | const std::string & | key, |
| const char * | def = "", |
||
| size_t | id = 0 |
||
| ) | const |
Get header value.
| key | Header name |
| def | Default value if not found |
| id | Index if multiple values (0-based) |
| size_t mb::MantisResponse::getHeaderValueCount | ( | const std::string & | key | ) | const |
Get count of header values.
| key | Header name |
| size_t mb::MantisResponse::getHeaderValueU64 | ( | const std::string & | key, |
| size_t | def = 0, |
||
| size_t | id = 0 |
||
| ) | const |
Get header value as unsigned 64-bit integer.
| key | Header name |
| def | Default value |
| id | Index if multiple values |
| std::string mb::MantisResponse::getLocation | ( | ) | const |
Get redirect location.
| std::string mb::MantisResponse::getReason | ( | ) | const |
Get status reason phrase.
| httplib::Response & mb::MantisResponse::getResponse | ( | ) | const |
| int mb::MantisResponse::getStatus | ( | ) | const |
Get HTTP status code.
| std::string mb::MantisResponse::getTrailerValue | ( | const std::string & | key, |
| size_t | id = 0 |
||
| ) | const |
Get trailer value.
| key | Trailer name |
| id | Index if multiple values |
| size_t mb::MantisResponse::getTrailerValueCount | ( | const std::string & | key | ) | const |
Get count of trailer values.
| key | Trailer name |
| std::string mb::MantisResponse::getVersion | ( | ) | const |
Get HTTP version.
| bool mb::MantisResponse::hasHeader | ( | const std::string & | key | ) | const |
Check if header exists.
| key | Header name |
| bool mb::MantisResponse::hasTrailer | ( | const std::string & | key | ) | const |
Check if trailer exists.
| key | Trailer name |
|
static |
Register MantisResponse methods for JavaScript/Duktape.
| void mb::MantisResponse::send | ( | int | statusCode = 200, |
| const std::string & | data = "", |
||
| const std::string & | content_type = "text/plain" |
||
| ) | const |
Send response with status, data, and content type.
| statusCode | HTTP status code |
| data | Response data |
| content_type | MIME type (default: "text/plain") |
| void mb::MantisResponse::sendEmpty | ( | int | statusCode = 204 | ) | const |
Send empty response (no body).
| statusCode | HTTP status code (default: 204 No Content) |
| void mb::MantisResponse::sendHtml | ( | int | statusCode = 200, |
| const std::string & | data = "" |
||
| ) | const |
Send HTML response.
| statusCode | HTTP status code (default: 200) |
| data | HTML content |
| void mb::MantisResponse::sendJSON | ( | int | statusCode = 200, |
| const json & | data = json::object() |
||
| ) | const |
Send JSON response.
| statusCode | HTTP status code (default: 200) |
| data | JSON object to send res.sendJSON(200, {{"success", true}, {"data", result}});
|
| void mb::MantisResponse::sendText | ( | int | statusCode = 200, |
| const std::string & | data = "" |
||
| ) | const |
Send text response.
| statusCode | HTTP status code (default: 200) |
| data | Text content |
| void mb::MantisResponse::setBody | ( | const std::string & | b | ) |
Set response body.
| b | Body string |
| void mb::MantisResponse::setContent | ( | const char * | s, |
| size_t | n, | ||
| const std::string & | content_type | ||
| ) | const |
Set response content from buffer.
| s | Content buffer |
| n | Content length |
| content_type | MIME type |
| void mb::MantisResponse::setContent | ( | const std::string & | s, |
| const std::string & | content_type | ||
| ) | const |
Set response content from string.
| s | Content string |
| content_type | MIME type |
| void mb::MantisResponse::setContent | ( | std::string && | s, |
| const std::string & | content_type | ||
| ) | const |
Set response content from moved string.
| s | Content string (moved) |
| content_type | MIME type |
| void mb::MantisResponse::setFileContent | ( | const std::string & | path | ) | const |
Set response content from file (auto-detect MIME type).
| path | File path |
| void mb::MantisResponse::setFileContent | ( | const std::string & | path, |
| const std::string & | content_type | ||
| ) | const |
Set response content from file with MIME type.
| path | File path |
| content_type | MIME type |
| void mb::MantisResponse::setHeader | ( | const std::string & | key, |
| const std::string & | val | ||
| ) | const |
Set response header.
| key | Header name |
| val | Header value |
| void mb::MantisResponse::setLocation | ( | const std::string & | b | ) |
Set redirect location.
| b | Location URL |
| void mb::MantisResponse::setReason | ( | const std::string & | b | ) |
Set status reason phrase.
| b | Reason string |
| void mb::MantisResponse::setRedirect | ( | const std::string & | url, |
| int | status = httplib::StatusCode::Found_302 |
||
| ) | const |
Set redirect response.
| url | Redirect URL |
| status | HTTP status code (default: 302 Found) |
| void mb::MantisResponse::setStatus | ( | int | s | ) |
Set HTTP status code.
| s | Status code |
| void mb::MantisResponse::setVersion | ( | const std::string & | b | ) |
Set HTTP version.
| b | Version string |