HTTP request wrapper bound to a MantisBase instance.
More...
#include <http.h>
HTTP request wrapper bound to a MantisBase instance.
Per-request attributes (auth, verification, etc.) are stored on the underlying Drogon request via set() / get(), not a global context. Use mbApp() (from MbAppMixin) to reach application services.
◆ MbRequest()
| mb::MbRequest::MbRequest |
( |
const MantisBase & | app, |
|
|
drogon::HttpRequestPtr | _req ) |
|
explicit |
◆ bearerTokenAuth()
| std::string mb::MbRequest::bearerTokenAuth |
( |
| ) |
const |
|
nodiscard |
- Returns
- Bearer token from the Authorization header, or empty.
◆ body()
| std::string mb::MbRequest::body |
( |
| ) |
const |
|
nodiscard |
◆ bodyAsJson()
| std::pair< nlohmann::json, std::string > mb::MbRequest::bodyAsJson |
( |
| ) |
const |
|
nodiscard |
Parse and cache the JSON request body.
- Returns
- {body, error} — error non-empty on parse failure.
◆ cookieValue()
| std::string mb::MbRequest::cookieValue |
( |
const std::string & | key | ) |
const |
|
nodiscard |
◆ drogonRequest()
| const drogon::HttpRequestPtr & mb::MbRequest::drogonRequest |
( |
| ) |
const |
|
nodiscard |
- Returns
- Underlying Drogon request pointer.
◆ filesMetadata()
| const json & mb::MbRequest::filesMetadata |
( |
| ) |
const |
|
nodiscard |
File field metadata keyed by form field name (after parseFormDataToEntity).
◆ formData()
| const std::vector< MbFormDataItem > & mb::MbRequest::formData |
( |
| ) |
const |
|
nodiscard |
Multipart parts (text + file fields). Empty for non-multipart bodies.
◆ get()
template<typename T>
| const T & mb::MbRequest::get |
( |
const std::string & | key, |
|
|
T | default_value ) |
|
inline |
Get a per-request attribute, inserting default_value if missing.
◆ hasHeader()
| bool mb::MbRequest::hasHeader |
( |
const std::string & | key | ) |
const |
|
nodiscard |
◆ hashMultipartMetadata()
| std::string mb::MbRequest::hashMultipartMetadata |
( |
const MbFormDataItem & | data | ) |
|
|
static |
Stable hash of multipart metadata for deduplication checks.
◆ hasKey()
| bool mb::MbRequest::hasKey |
( |
const std::string & | key | ) |
const |
|
nodiscard |
- Returns
- true if a per-request attribute exists on the Drogon request.
◆ hasPathParam()
| bool mb::MbRequest::hasPathParam |
( |
const std::string & | key | ) |
const |
|
nodiscard |
◆ hasPathParams()
| bool mb::MbRequest::hasPathParams |
( |
| ) |
const |
|
nodiscard |
◆ hasQueryParam()
| bool mb::MbRequest::hasQueryParam |
( |
const std::string & | key | ) |
const |
|
nodiscard |
◆ headerValue()
| std::string mb::MbRequest::headerValue |
( |
const std::string & | key, |
|
|
const std::string & | def = "" ) const |
|
nodiscard |
◆ isAdminAuth()
| bool mb::MbRequest::isAdminAuth |
( |
| ) |
|
|
nodiscard |
- Returns
- true when the request auth block is an admin session.
◆ isGuestAuth()
| bool mb::MbRequest::isGuestAuth |
( |
| ) |
|
|
nodiscard |
- Returns
- true when the request auth block is guest/unauthenticated.
◆ isMultipartFormData()
| bool mb::MbRequest::isMultipartFormData |
( |
| ) |
const |
|
nodiscard |
- Returns
- true when Content-Type is multipart/form-data.
◆ isUserAuth()
| bool mb::MbRequest::isUserAuth |
( |
| ) |
|
|
nodiscard |
- Returns
- true when the request auth block is a regular user session.
◆ jsonBody()
| const json & mb::MbRequest::jsonBody |
( |
| ) |
const |
|
nodiscard |
Unified parsed request body (lazy, parsed once per request).
This is the single body entry point for (req, res) handlers on PUT/PATCH/POST, covering both JSON and multipart/file-upload bodies.
JSON requests: the parsed body; throws MbException(400) on malformed JSON. Multipart requests: empty until parseFormDataToEntity() maps the form fields onto an entity.
For a non-throwing parse use bodyAsJson().
◆ localAddr()
| std::string mb::MbRequest::localAddr |
( |
| ) |
const |
|
nodiscard |
◆ localPort()
| int mb::MbRequest::localPort |
( |
| ) |
const |
|
nodiscard |
◆ method()
| std::string mb::MbRequest::method |
( |
| ) |
const |
|
nodiscard |
◆ parseFormDataToEntity()
| void mb::MbRequest::parseFormDataToEntity |
( |
const MbEntity & | entity | ) |
const |
Map parsed multipart form fields onto an entity for create/update (no-op for JSON).
◆ path()
| std::string mb::MbRequest::path |
( |
| ) |
const |
|
nodiscard |
◆ pathParamValue()
| std::string mb::MbRequest::pathParamValue |
( |
const std::string & | key | ) |
const |
|
nodiscard |
◆ queryParamValue()
| std::string mb::MbRequest::queryParamValue |
( |
const std::string & | key | ) |
const |
|
nodiscard |
◆ registerDuktapeMethods()
| void mb::MbRequest::registerDuktapeMethods |
( |
| ) |
|
|
static |
Register request accessor methods on the Duktape req object.
◆ remoteAddr()
| std::string mb::MbRequest::remoteAddr |
( |
| ) |
const |
|
nodiscard |
◆ remotePort()
| int mb::MbRequest::remotePort |
( |
| ) |
const |
|
nodiscard |
◆ resolveAuthToken()
| std::string mb::MbRequest::resolveAuthToken |
( |
| ) |
const |
|
nodiscard |
Bearer token if present, otherwise the auth cookie value.
◆ set()
template<typename T>
| void mb::MbRequest::set |
( |
const std::string & | key, |
|
|
T | value ) |
|
inline |
Store a per-request attribute on the underlying Drogon request.
◆ setPathParam()
| void mb::MbRequest::setPathParam |
( |
const std::string & | key, |
|
|
const std::string & | value ) |
Set a single route path parameter (e.g. :id).
◆ setPathParams()
| void mb::MbRequest::setPathParams |
( |
const std::unordered_map< std::string, std::string > & | params | ) |
|
Replace all route path parameters.
◆ undoWrittenFiles()
| void mb::MbRequest::undoWrittenFiles |
( |
const std::string & | entity_name | ) |
const |
Remove files written by writeFiles on validation failure.
◆ writeFiles()
| void mb::MbRequest::writeFiles |
( |
const std::string & | entity_name | ) |
const |
Persist uploaded files for entity_name using stored metadata (no-op for JSON).
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_request.cpp