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

HTTP response class to represent an outgoing HTTP response. More...

#include <ssgx_http_t_structs.h>

Public Member Functions

void SetStatusCode (HttpStatusCode status)
 Set the HTTP status code for the response.
 
HttpStatusCode StatusCode () const
 Get the HTTP status code of the response.
 
void SetHeaders (const TypeHeaders &headers)
 Set the headers for the response.
 
const TypeHeadersHeaders () const
 Get the headers of the response.
 
void SetHeader (const std::string &key, const std::string &val)
 Set a specific header for the response.
 
void SetHeader (const std::string &key, int64_t val)
 Set a specific header for the response with an integer value.
 
bool HasHeader (const std::string &key) const
 Check if the response has a specific header.
 
std::string GetHeaderValue (const std::string &key, const char *def="") const
 Get the value of a specific header in the response (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 SetBody (const char *buf, size_t buf_len)
 Set the body of the response from a character buffer.
 
void SetBody (const std::string &body)
 Set the body of the response from a string.
 
const std::string & Body () const
 Get the body of the response.
 
bool FromJsonStrWithoutBody (const std::string &json_str)
 Parse the response from a JSON string, without including the body.
 
bool ToJsonStrWithoutBody (std::string &json_str) const
 Convert the response to a JSON string, without including the body.
 
void SetResp (const char *s, size_t n, const std::string &content_type, HttpStatusCode status)
 Set the full response with a string body, content type, and status.
 
void SetResp (const std::string &s, const std::string &content_type, HttpStatusCode status)
 Set the full response with a string body, content type, and status.
 
void SetRespRedirect (const std::string &url, HttpStatusCode status_code=HttpStatusCode::Found302)
 Set a redirection response with the specified URL and status.
 
void SetResp404NotFound ()
 Set a "404 Not Found" response.
 
void SetResp500InternalServerError ()
 Set a "500 Internal Server Error" response.
 
void SetResp403Forbidden ()
 Set a "403 Forbidden" response.
 
void SetResp204NoContent ()
 Set a "204 No Content" response.
 

Detailed Description

HTTP response class to represent an outgoing HTTP response.

Member Function Documentation

◆ Body()

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

Get the body of the response.

This method returns the body of the HTTP response.

Returns
The body of the response as a string.

◆ FromJsonStrWithoutBody()

bool ssgx::http_t::Response::FromJsonStrWithoutBody ( const std::string & json_str)

Parse the response from a JSON string, without including the body.

This method parses the response from a JSON string representation, ignoring the body.

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

◆ GetHeaderValue()

std::string ssgx::http_t::Response::GetHeaderValue ( const std::string & key,
const char * def = "" ) const

Get the value of a specific header in the response (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::Response::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 specific 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.

◆ HasHeader()

bool ssgx::http_t::Response::HasHeader ( const std::string & key) const

Check if the response has a specific header.

This method checks whether a specific header exists in the response.

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

◆ Headers()

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

Get the headers of the response.

This method returns the headers of the HTTP response.

Returns
A const reference to the headers of the response.

◆ SetBody() [1/2]

void ssgx::http_t::Response::SetBody ( const char * buf,
size_t buf_len )

Set the body of the response from a character buffer.

This method sets the body of the response 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::Response::SetBody ( const std::string & body)

Set the body of the response from a string.

This method sets the body of the response using a string.

Parameters
bodyThe body of the response as a string.

◆ SetHeader() [1/2]

void ssgx::http_t::Response::SetHeader ( const std::string & key,
const std::string & val )

Set a specific header for the response.

This method sets a specific header for the HTTP response.

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

◆ SetHeader() [2/2]

void ssgx::http_t::Response::SetHeader ( const std::string & key,
int64_t val )

Set a specific header for the response with an integer value.

This method sets a specific header for the HTTP response with an integer value.

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

◆ SetHeaders()

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

Set the headers for the response.

This method sets the headers for the HTTP response.

Parameters
headersThe headers to set as a map.

◆ SetResp() [1/2]

void ssgx::http_t::Response::SetResp ( const char * s,
size_t n,
const std::string & content_type,
HttpStatusCode status )

Set the full response with a string body, content type, and status.

This method sets the full response, including the body, content type, and status.

Parameters
sThe response body as a string.
nThe length of the body string.
content_typeThe content type (e.g., "application/json").
statusThe HTTP status code for the response.

◆ SetResp() [2/2]

void ssgx::http_t::Response::SetResp ( const std::string & s,
const std::string & content_type,
HttpStatusCode status )

Set the full response with a string body, content type, and status.

This method sets the full response, including the body, content type, and status.

Parameters
sThe response body as a string.
content_typeThe content type (e.g., "application/json").
statusThe HTTP status code for the response.

◆ SetResp204NoContent()

void ssgx::http_t::Response::SetResp204NoContent ( )

Set a "204 No Content" response.

This method sets a 204 No Content response, indicating a successful request with no body.

◆ SetResp403Forbidden()

void ssgx::http_t::Response::SetResp403Forbidden ( )

Set a "403 Forbidden" response.

This method sets a 403 Forbidden response with a default body.

◆ SetResp404NotFound()

void ssgx::http_t::Response::SetResp404NotFound ( )

Set a "404 Not Found" response.

This method sets a 404 Not Found response with a default body.

◆ SetResp500InternalServerError()

void ssgx::http_t::Response::SetResp500InternalServerError ( )

Set a "500 Internal Server Error" response.

This method sets a 500 Internal Server Error response with a default body.

◆ SetRespRedirect()

void ssgx::http_t::Response::SetRespRedirect ( const std::string & url,
HttpStatusCode status_code = HttpStatusCode::Found302 )

Set a redirection response with the specified URL and status.

This method sets a redirection response, including the URL and the status code.

Parameters
urlThe URL to redirect to.
status_codeThe HTTP status code for the redirection (default is 302 Found).

◆ SetStatusCode()

void ssgx::http_t::Response::SetStatusCode ( HttpStatusCode status)

Set the HTTP status code for the response.

This method sets the HTTP status code (e.g., 200 OK, 404 Not Found) for the response.

Parameters
statusThe HTTP status code to set.

◆ StatusCode()

HttpStatusCode ssgx::http_t::Response::StatusCode ( ) const

Get the HTTP status code of the response.

This method returns the HTTP status code of the response (e.g., 200 OK, 404 Not Found).

Returns
The HTTP status code.

◆ ToJsonStrWithoutBody()

bool ssgx::http_t::Response::ToJsonStrWithoutBody ( std::string & json_str) const

Convert the response to a JSON string, without including the body.

This method converts the response to its JSON string representation, excluding the body.

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: