|
Safeheron-SGX-Native-Development-Framework v1.2.0
|
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 TypeHeaders & | Headers () 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. | |
HTTP response class to represent an outgoing HTTP response.
| const std::string & ssgx::http_t::Response::Body | ( | ) | const |
Get the body of the response.
This method returns the body of the HTTP response.
| 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.
| json_str | The JSON string containing the response. |
| 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.
| key | The key (header name) to retrieve. |
| def | The default value to return if the header is not found. |
| 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.
| key | The key (header name) to retrieve. |
| def | The default value to return if the header is not found. |
| 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.
| key | The key (header name) to check for. |
| const TypeHeaders & ssgx::http_t::Response::Headers | ( | ) | const |
Get the headers of the response.
This method returns the headers of the HTTP response.
| 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.
| buf | The character buffer containing the body. |
| buf_len | The length of the buffer. |
| 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.
| body | The body of the response as a string. |
| 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.
| key | The key (header name) to set. |
| val | The value for the header. |
| 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.
| key | The key (header name) to set. |
| val | The integer value for the header. |
| void ssgx::http_t::Response::SetHeaders | ( | const TypeHeaders & | headers | ) |
Set the headers for the response.
This method sets the headers for the HTTP response.
| headers | The headers to set as a map. |
| 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.
| s | The response body as a string. |
| n | The length of the body string. |
| content_type | The content type (e.g., "application/json"). |
| status | The HTTP status code for the response. |
| 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.
| s | The response body as a string. |
| content_type | The content type (e.g., "application/json"). |
| status | The HTTP status code for the response. |
| 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.
| void ssgx::http_t::Response::SetResp403Forbidden | ( | ) |
Set a "403 Forbidden" response.
This method sets a 403 Forbidden response with a default body.
| void ssgx::http_t::Response::SetResp404NotFound | ( | ) |
Set a "404 Not Found" response.
This method sets a 404 Not Found response with a default body.
| void ssgx::http_t::Response::SetResp500InternalServerError | ( | ) |
| 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.
| url | The URL to redirect to. |
| status_code | The HTTP status code for the redirection (default is 302 Found). |
| 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.
| status | The HTTP status code to set. |
| 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).
| 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.
| json_str | The resulting JSON string. |