1#ifndef SAFEHERON_SGX_TRUSTED_HTTP_CLIENT_H
2#define SAFEHERON_SGX_TRUSTED_HTTP_CLIENT_H
46 : error_code_(error_code), error_msg_(std::move(error_msg)), internal_err_(std::move(internal_err)) {
52 [[nodiscard]]
const std::string&
message()
const {
61 std::string error_msg_;
62 std::string internal_err_;
71 Result(std::unique_ptr<Response>&& res,
const Error& err) : res_(std::move(res)), err_(err) {
74 explicit operator bool()
const {
75 return res_ !=
nullptr;
78 return res_ ==
nullptr;
81 return res_ !=
nullptr;
108 std::unique_ptr<Response> res_;
133 explicit Client(
const std::string& host);
144 explicit Client(
const std::string& host,
int port);
156 explicit Client(
const std::string& host,
int port,
const std::string& server_ca);
233 Result Post(
const std::string& path,
const char* body,
size_t content_length,
const std::string& content_type,
259 Result Post(
const std::string& path,
const std::string& body,
const std::string& content_type,
276 [[nodiscard]]
Result SendRequest(
const std::string& method,
const std::string& path,
const TypeHeaders& headers,
277 const TypeParams& params,
const std::string& body,
const std::string& content_type,
278 int time_out_sec)
const;
282 std::string server_ca_;
Client class for making HTTP and HTTPS requests.
Definition ssgx_http_t_client.h:122
Client(const std::string &host, int port, const std::string &server_ca)
Constructor to initialize the client with a hostname, port, and server CA certificate.
Result Post(const std::string &path, const std::string &body, const std::string &content_type, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
Sends a POST request with a body.
Result Post(const std::string &path, const char *body, size_t content_length, const std::string &content_type, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
Sends a POST request with a body.
Result Get(const std::string &path, const TypeHeaders &headers, const TypeParams ¶ms, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
Sends a GET request with HTTP headers and URL parameters.
Result Get(const std::string &path, const TypeParams ¶ms, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
Sends a GET request with URL parameters.
Result Get(const std::string &path, const TypeHeaders &headers, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
Sends a GET request with HTTP headers.
virtual ~Client()=default
Destructor to clean up resources.
Result Post(const std::string &path, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
Sends a POST request.
Client(const std::string &host, int port)
Constructor to initialize the client with a hostname and port.
Client(const std::string &host)
Constructor to initialize the client with a hostname.
Result Post(const std::string &path, const TypeHeaders &headers, const char *body, size_t content_length, const std::string &content_type, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
Sends a POST request with HTTP headers and a body.
Result Post(const std::string &path, const TypeHeaders &headers, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
Sends a POST request with HTTP headers.
Result Get(const std::string &path, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
Sends a GET request.
Result Post(const std::string &path, const TypeHeaders &headers, const std::string &body, const std::string &content_type, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
Sends a POST request with HTTP headers and a body.
Represents detailed error information, typically from client operations.
Definition ssgx_http_t_client.h:41
const std::string & internal_error() const
Definition ssgx_http_t_client.h:55
Error(const Error &other)=default
ErrorCode code() const
Definition ssgx_http_t_client.h:49
const std::string & message() const
Definition ssgx_http_t_client.h:52
Error(ErrorCode error_code, std::string error_msg, std::string internal_err)
Definition ssgx_http_t_client.h:45
HTTP response class to represent an outgoing HTTP response.
Definition ssgx_http_t_structs.h:424
The result class of the client operation stores the response data of the request or the error informa...
Definition ssgx_http_t_client.h:68
Error error() const
Definition ssgx_http_t_client.h:103
Response & value()
Definition ssgx_http_t_client.h:86
bool operator==(std::nullptr_t) const
Definition ssgx_http_t_client.h:77
bool operator!=(std::nullptr_t) const
Definition ssgx_http_t_client.h:80
Result(std::unique_ptr< Response > &&res, const Error &err)
Definition ssgx_http_t_client.h:71
Response & operator*()
Definition ssgx_http_t_client.h:92
Response * operator->()
Definition ssgx_http_t_client.h:98
const Response * operator->() const
Definition ssgx_http_t_client.h:95
const Response & value() const
Definition ssgx_http_t_client.h:83
const Response & operator*() const
Definition ssgx_http_t_client.h:89
std::map< std::string, std::string, ci > TypeHeaders
Definition ssgx_http_t_structs.h:103
ErrorCode
Error code of the client operation.
Definition ssgx_http_t_client.h:18
std::map< std::string, std::string > TypeParams
Definition ssgx_http_t_structs.h:104
constexpr int SSGX_HTTP_CLIENT_TIMEOUT
Definition ssgx_http_t_client.h:13
Definition ssgx_attestation_t.h:6