|
Safeheron-SGX-Native-Development-Framework v1.2.0
|
HTTP request class to represent an incoming HTTP request. More...
#include <ssgx_http_t_structs.h>
Public Member Functions | |
| void | SetMethod (const char *buf, size_t buf_len) |
| Set the HTTP method (GET, POST, etc.) from a char buffer. | |
| void | SetMethod (const std::string &method) |
| Set the HTTP method (GET, POST, etc.) from a string. | |
| std::string | Method () const |
| Get the HTTP method. | |
| void | SetPath (const char *buf, size_t buf_len) |
| Set the path of the request (e.g., "/api/v1/xxx"). | |
| void | SetPath (const std::string &path) |
| Set the path of the request (e.g., "/api/v1/xxx"). | |
| std::string | Path () const |
| Get the path of the request. | |
| void | SetHeaders (const TypeHeaders &headers) |
| Set the headers for the request. | |
| const TypeHeaders & | Headers () const |
| Get the headers for the request. | |
| void | SetHeader (const std::string &key, const std::string &val) |
| Set a specific header for the request. | |
| void | SetHeader (const std::string &key, int64_t val) |
| Set a specific header for the request with an integer value. | |
| bool | HasHeader (const std::string &key) const |
| Check if the request has a specific header. | |
| std::string | GetHeaderValue (const std::string &key, const char *def="") const |
| Get the value of a specific header (with a default value). | |
| uint64_t | GetHeaderValueUint64 (const std::string &key, uint64_t def=0) const |
| Get the value of a specific header as uint64 (with a default value). | |
| void | SetParams (const TypeParams ¶ms) |
| Set the parameters for the request. | |
| const TypeParams & | Params () const |
| Get the parameters for the request. | |
| void | SetParam (const std::string &key, const std::string &val) |
| Set a specific parameter for the request. | |
| void | SetParam (const std::string &key, int64_t val) |
| Set a specific parameter for the request with an integer value. | |
| bool | HasParam (const std::string &key) const |
| Check if the request has a specific parameter. | |
| std::string | GetParamValue (const std::string &key, const char *def="") const |
| Get the value of a specific parameter (with a default value). | |
| void | SetBody (const char *buf, size_t buf_len) |
| Set the body of the request from a character buffer. | |
| void | SetBody (const std::string &body) |
| Set the body of the request from a string. | |
| const std::string & | Body () const |
| Get the body of the request. | |
| bool | FromJsonStr (const std::string &json_str) |
| Parse the request from a JSON string. | |
| bool | FromJsonStr (const char *json_str) |
| Parse the request from a JSON character buffer. | |
| bool | ToJsonStr (std::string &json_str) const |
| Convert the request to a JSON string. | |
| template<typename T > | |
| void | SetAttribute (const std::string &key, T &&value) |
| Get the attribute value associated with the given key. | |
| template<typename T > | |
| T & | GetAttribute (const std::string &key) |
| Get the attribute value associated with the given key. | |
| template<typename T > | |
| bool | HasAttribute (const std::string &key) const |
| Check if an attribute exists. | |
HTTP request class to represent an incoming HTTP request.
| const std::string & ssgx::http_t::Request::Body | ( | ) | const |
Get the body of the request.
This method returns the body of the HTTP request.
| bool ssgx::http_t::Request::FromJsonStr | ( | const char * | json_str | ) |
Parse the request from a JSON character buffer.
This method parses the HTTP request from a JSON character buffer.
| json_str | The character buffer containing the JSON string. |
| bool ssgx::http_t::Request::FromJsonStr | ( | const std::string & | json_str | ) |
Parse the request from a JSON string.
This method parses the HTTP request from a JSON string representation.
| json_str | The JSON string containing the request. |
|
inline |
Get the attribute value associated with the given key.
This method retrieves the value of the specified attribute. The caller must ensure the requested type matches the stored type.
| T | The expected type of the attribute value. |
| key | The attribute key. |
| std::string ssgx::http_t::Request::GetHeaderValue | ( | const std::string & | key, |
| const char * | def = "" ) const |
Get the value of a specific header (with a default value).
This method retrieves the value of a specific header, and returns a default value if the header is not found.
| key | The key (header name) to retrieve. |
| def | The default value to return if the header is not found. |
| uint64_t ssgx::http_t::Request::GetHeaderValueUint64 | ( | const std::string & | key, |
| uint64_t | def = 0 ) const |
Get the value of a specific header as uint64 (with a default value).
This method retrieves the value of a header as an unsigned 64-bit integer, and returns a default value if the header is not found.
| key | The key (header name) to retrieve. |
| def | The default value to return if the header is not found. |
| std::string ssgx::http_t::Request::GetParamValue | ( | const std::string & | key, |
| const char * | def = "" ) const |
Get the value of a specific parameter (with a default value).
This method retrieves the value of a specific parameter, and returns a default value if the parameter is not found.
| key | The key (parameter name) to retrieve. |
| def | The default value to return if the parameter is not found. |
|
inlinenodiscard |
Check if an attribute exists.
This method checks whether a given key exists in the attribute storage.
| key | The attribute key to check. |
| bool ssgx::http_t::Request::HasHeader | ( | const std::string & | key | ) | const |
Check if the request has a specific header.
This method checks whether a specific header exists in the request.
| key | The key (header name) to check for. |
| bool ssgx::http_t::Request::HasParam | ( | const std::string & | key | ) | const |
Check if the request has a specific parameter.
This method checks whether a specific query parameter exists in the request.
| key | The key (parameter name) to check for. |
| const TypeHeaders & ssgx::http_t::Request::Headers | ( | ) | const |
Get the headers for the request.
This method returns the headers of the HTTP request.
| std::string ssgx::http_t::Request::Method | ( | ) | const |
Get the HTTP method.
This method returns the HTTP method of the request.
| const TypeParams & ssgx::http_t::Request::Params | ( | ) | const |
Get the parameters for the request.
This method returns the query parameters of the HTTP request.
| std::string ssgx::http_t::Request::Path | ( | ) | const |
Get the path of the request.
This method returns the path of the HTTP request.
|
inline |
Get the attribute value associated with the given key.
This method retrieves the value of the specified attribute. The caller must ensure the requested type matches the stored type.
| T | The expected type of the attribute value. |
| key | The attribute key. |
| void ssgx::http_t::Request::SetBody | ( | const char * | buf, |
| size_t | buf_len ) |
Set the body of the request from a character buffer.
This method sets the body of the request using a character buffer and its length.
| buf | The character buffer containing the body. |
| buf_len | The length of the buffer. |
| void ssgx::http_t::Request::SetBody | ( | const std::string & | body | ) |
Set the body of the request from a string.
This method sets the body of the request using a string.
| body | The body of the request as a string. |
| void ssgx::http_t::Request::SetHeader | ( | const std::string & | key, |
| const std::string & | val ) |
Set a specific header for the request.
This method sets a specific header for the HTTP request.
| key | The key (header name) to set. |
| val | The value for the header. |
| void ssgx::http_t::Request::SetHeader | ( | const std::string & | key, |
| int64_t | val ) |
Set a specific header for the request with an integer value.
This method sets a specific header for the HTTP request with an integer value.
| key | The key (header name) to set. |
| val | The integer value for the header. |
| void ssgx::http_t::Request::SetHeaders | ( | const TypeHeaders & | headers | ) |
Set the headers for the request.
This method sets the headers for the HTTP request.
| headers | The headers to set as a map. |
| void ssgx::http_t::Request::SetMethod | ( | const char * | buf, |
| size_t | buf_len ) |
Set the HTTP method (GET, POST, etc.) from a char buffer.
This method takes a character buffer and sets the HTTP method. The buffer length is also provided to ensure proper parsing.
| buf | The character buffer containing the HTTP method. |
| buf_len | The length of the buffer. |
| void ssgx::http_t::Request::SetMethod | ( | const std::string & | method | ) |
Set the HTTP method (GET, POST, etc.) from a string.
This method takes a string and sets the HTTP method.
| method | The HTTP method as a string (e.g., "GET", "POST"). |
| void ssgx::http_t::Request::SetParam | ( | const std::string & | key, |
| const std::string & | val ) |
Set a specific parameter for the request.
This method sets a specific query parameter for the HTTP request.
| key | The key (parameter name) to set. |
| val | The value for the parameter. |
| void ssgx::http_t::Request::SetParam | ( | const std::string & | key, |
| int64_t | val ) |
Set a specific parameter for the request with an integer value.
This method sets a specific query parameter for the HTTP request with an integer value.
| key | The key (parameter name) to set. |
| val | The integer value for the parameter. |
| void ssgx::http_t::Request::SetParams | ( | const TypeParams & | params | ) |
Set the parameters for the request.
This method sets the query parameters for the HTTP request.
| params | The parameters to set as a map. |
| void ssgx::http_t::Request::SetPath | ( | const char * | buf, |
| size_t | buf_len ) |
Set the path of the request (e.g., "/api/v1/xxx").
This method sets the path for the request, which is the part of the URL following the domain (e.g., "/api/v1/xxx").
| buf | The character buffer containing the path. |
| buf_len | The length of the buffer. |
| void ssgx::http_t::Request::SetPath | ( | const std::string & | path | ) |
Set the path of the request (e.g., "/api/v1/xxx").
This method sets the path for the request as a string.
| path | The path as a string (e.g., "/api/v1/xxx"). |
| bool ssgx::http_t::Request::ToJsonStr | ( | std::string & | json_str | ) | const |
Convert the request to a JSON string.
This method converts the HTTP request to its JSON string representation.
| json_str | The resulting JSON string. |