|
MantisBase v0.3.4
|
A wrapper class around httplib::Request offering a consistent API and allowing for easy wrapper methods compatible with Duktape API requirements for scripting.
More...
#include <http.h>
Public Member Functions | |
| MantisRequest (const httplib::Request &_req) | |
| Wrapper class around the httplib Request object and our context library. | |
| std::string | getMethod () const |
| Get HTTP request method (GET, POST, etc.). | |
| std::string | getPath () const |
| Get request path. | |
| std::string | getBody () const |
| Get raw request body. | |
| std::string | getRemoteAddr () const |
| Get client remote address. | |
| int | getRemotePort () const |
| Get client remote port. | |
| std::string | getLocalAddr () const |
| Get server local address. | |
| int | getLocalPort () const |
| Get server local port. | |
| bool | hasHeader (const std::string &key) const |
| Check if header exists. | |
| std::string | getHeaderValue (const std::string &key, const char *def, size_t id) const |
| Get header value with default and index. | |
| size_t | getHeaderValueU64 (const std::string &key, size_t def, size_t id) const |
| Get header value as unsigned 64-bit integer. | |
| size_t | getHeaderValueCount (const std::string &key) const |
| Get count of header values. | |
| bool | hasTrailer (const std::string &key) const |
| Check if trailer exists. | |
| std::string | getTrailerValue (const std::string &key, size_t id) const |
| Get trailer value. | |
| size_t | getTrailerValueCount (const std::string &key) const |
| Get count of trailer values. | |
| httplib::Match | matches () const |
| Get route match information. | |
| bool | hasQueryParam (const std::string &key) const |
| Check if query parameter exists. | |
| std::string | getQueryParamValue (const std::string &key) const |
| Get query parameter value (first occurrence). | |
| std::string | getQueryParamValue (const std::string &key, size_t id) const |
| Get query parameter value by index. | |
| size_t | getQueryParamValueCount (const std::string &key) const |
| Get count of query parameter values. | |
| bool | hasPathParams () const |
| Check if request has path parameters. | |
| bool | hasPathParam (const std::string &key) const |
| Check if path parameter exists. | |
| std::string | getPathParamValue (const std::string &key) const |
| Get path parameter value. | |
| size_t | getPathParamValueCount (const std::string &key) const |
| Get count of path parameter values. | |
| bool | isMultipartFormData () const |
| Check if request is multipart/form-data. | |
| bool | hasKey (const std::string &key) const |
| Check if context store has key. | |
| std::string | getBearerTokenAuth () const |
| Extract Bearer token from Authorization header. | |
| std::pair< nlohmann::json, std::string > | getBodyAsJson () const |
| Parse request body as JSON. | |
| template<typename T > | |
| void | set (const std::string &key, T value) |
| Store value in request context (for middleware communication). | |
| template<typename T > | |
| T & | getOr (const std::string &key, T default_value) |
| Get value from context store or return default. | |
Static Public Member Functions | |
| static void | registerDuktapeMethods () |
| Register MantisRequest methods for JavaScript/Duktape. | |
A wrapper class around httplib::Request offering a consistent API and allowing for easy wrapper methods compatible with Duktape API requirements for scripting.
Additionally, MantisRequest adds a context object for storing some key-value data for sharing across middlewares and request handlers.
|
explicit |
Wrapper class around the httplib Request object and our context library.
| _req | httplib::Request& object |
Construct request wrapper.
| _req | Reference to httplib::Request object |
| std::string mb::MantisRequest::getBearerTokenAuth | ( | ) | const |
Extract Bearer token from Authorization header.
| std::string mb::MantisRequest::getBody | ( | ) | const |
Get raw request body.
| std::pair< nlohmann::json, std::string > mb::MantisRequest::getBodyAsJson | ( | ) | const |
Parse request body as JSON.
| std::string mb::MantisRequest::getHeaderValue | ( | const std::string & | key, |
| const char * | def, | ||
| size_t | id | ||
| ) | const |
Get header value with default and index.
| key | Header name |
| def | Default value if not found |
| id | Index if multiple values (0-based) |
Get count of header values.
| key | Header name |
| size_t mb::MantisRequest::getHeaderValueU64 | ( | const std::string & | key, |
| size_t | def, | ||
| size_t | id | ||
| ) | const |
Get header value as unsigned 64-bit integer.
| key | Header name |
| def | Default value |
| id | Index if multiple values |
| std::string mb::MantisRequest::getLocalAddr | ( | ) | const |
Get server local address.
| int mb::MantisRequest::getLocalPort | ( | ) | const |
Get server local port.
| std::string mb::MantisRequest::getMethod | ( | ) | const |
Get HTTP request method (GET, POST, etc.).
Get value from context store or return default.
| T | Value type |
| key | Context key |
| default_value | Default value if key not found |
| std::string mb::MantisRequest::getPath | ( | ) | const |
Get request path.
| std::string mb::MantisRequest::getPathParamValue | ( | const std::string & | key | ) | const |
Get path parameter value.
| key | Parameter name |
Get count of path parameter values.
| key | Parameter name |
| std::string mb::MantisRequest::getQueryParamValue | ( | const std::string & | key | ) | const |
Get query parameter value (first occurrence).
| key | Parameter name |
Get query parameter value by index.
| key | Parameter name |
| id | Index if multiple values (0-based) |
Get count of query parameter values.
| key | Parameter name |
| std::string mb::MantisRequest::getRemoteAddr | ( | ) | const |
Get client remote address.
| int mb::MantisRequest::getRemotePort | ( | ) | const |
Get client remote port.
Get trailer value.
| key | Trailer name |
| id | Index if multiple values |
Get count of trailer values.
| key | Trailer name |
Check if header exists.
| key | Header name |
Check if context store has key.
| key | Key to check |
Check if path parameter exists.
| key | Parameter name (from route pattern like /:id) |
| bool mb::MantisRequest::hasPathParams | ( | ) | const |
Check if request has path parameters.
Check if query parameter exists.
| key | Parameter name |
Check if trailer exists.
| key | Trailer name |
| bool mb::MantisRequest::isMultipartFormData | ( | ) | const |
Check if request is multipart/form-data.
| httplib::Match mb::MantisRequest::matches | ( | ) | const |
Get route match information.
Register MantisRequest methods for JavaScript/Duktape.
|
inline |