Safeheron-SGX-Native-Development-Framework v1.2.0
Loading...
Searching...
No Matches
ssgx::http_t::Request Class Reference

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 TypeHeadersHeaders () 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 &params)
 Set the parameters for the request.
 
const TypeParamsParams () 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.
 

Detailed Description

HTTP request class to represent an incoming HTTP request.

Member Function Documentation

◆ Body()

const std::string & ssgx::http_t::Request::Body ( ) const

Get the body of the request.

This method returns the body of the HTTP request.

Returns
The body of the request as a string.

◆ FromJsonStr() [1/2]

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.

Parameters
json_strThe character buffer containing the JSON string.
Returns
True if parsing is successful, otherwise false.

◆ FromJsonStr() [2/2]

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.

Parameters
json_strThe JSON string containing the request.
Returns
True if parsing is successful, otherwise false.

◆ GetAttribute()

template<typename T >
T & ssgx::http_t::Request::GetAttribute ( const std::string & key)
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.

Template Parameters
TThe expected type of the attribute value.
Parameters
keyThe attribute key.
Returns
Reference to the attribute value of type T.

◆ GetHeaderValue()

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.

Parameters
keyThe key (header name) to retrieve.
defThe default value to return if the header is not found.
Returns
The value of the header, or the default value if not found.

◆ GetHeaderValueUint64()

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.

Parameters
keyThe key (header name) to retrieve.
defThe default value to return if the header is not found.
Returns
The value of the header as uint64, or the default value.

◆ GetParamValue()

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.

Parameters
keyThe key (parameter name) to retrieve.
defThe default value to return if the parameter is not found.
Returns
The value of the parameter, or the default value if not found.

◆ HasAttribute()

template<typename T >
bool ssgx::http_t::Request::HasAttribute ( const std::string & key) const
inlinenodiscard

Check if an attribute exists.

This method checks whether a given key exists in the attribute storage.

Parameters
keyThe attribute key to check.
Returns
True if the key exists, otherwise false.

◆ HasHeader()

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.

Parameters
keyThe key (header name) to check for.
Returns
True if the header exists, otherwise false.

◆ HasParam()

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.

Parameters
keyThe key (parameter name) to check for.
Returns
True if the parameter exists, otherwise false.

◆ Headers()

const TypeHeaders & ssgx::http_t::Request::Headers ( ) const

Get the headers for the request.

This method returns the headers of the HTTP request.

Returns
A const reference to the headers of the request.

◆ Method()

std::string ssgx::http_t::Request::Method ( ) const

Get the HTTP method.

This method returns the HTTP method of the request.

Returns
The HTTP method as a string.

◆ Params()

const TypeParams & ssgx::http_t::Request::Params ( ) const

Get the parameters for the request.

This method returns the query parameters of the HTTP request.

Returns
A const reference to the parameters of the request.

◆ Path()

std::string ssgx::http_t::Request::Path ( ) const

Get the path of the request.

This method returns the path of the HTTP request.

Returns
The path of the request as a string.

◆ SetAttribute()

template<typename T >
void ssgx::http_t::Request::SetAttribute ( const std::string & key,
T && value )
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.

Template Parameters
TThe expected type of the attribute value.
Parameters
keyThe attribute key.
Returns
Reference to the attribute value of type T.

◆ SetBody() [1/2]

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.

Parameters
bufThe character buffer containing the body.
buf_lenThe length of the buffer.

◆ SetBody() [2/2]

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.

Parameters
bodyThe body of the request as a string.

◆ SetHeader() [1/2]

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.

Parameters
keyThe key (header name) to set.
valThe value for the header.

◆ SetHeader() [2/2]

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.

Parameters
keyThe key (header name) to set.
valThe integer value for the header.

◆ SetHeaders()

void ssgx::http_t::Request::SetHeaders ( const TypeHeaders & headers)

Set the headers for the request.

This method sets the headers for the HTTP request.

Parameters
headersThe headers to set as a map.

◆ SetMethod() [1/2]

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.

Parameters
bufThe character buffer containing the HTTP method.
buf_lenThe length of the buffer.

◆ SetMethod() [2/2]

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.

Parameters
methodThe HTTP method as a string (e.g., "GET", "POST").

◆ SetParam() [1/2]

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.

Parameters
keyThe key (parameter name) to set.
valThe value for the parameter.

◆ SetParam() [2/2]

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.

Parameters
keyThe key (parameter name) to set.
valThe integer value for the parameter.

◆ SetParams()

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.

Parameters
paramsThe parameters to set as a map.

◆ SetPath() [1/2]

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").

Parameters
bufThe character buffer containing the path.
buf_lenThe length of the buffer.

◆ SetPath() [2/2]

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.

Parameters
pathThe path as a string (e.g., "/api/v1/xxx").

◆ ToJsonStr()

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.

Parameters
json_strThe resulting JSON string.
Returns
True if conversion is successful, otherwise false.

The documentation for this class was generated from the following file: