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

Client class for making HTTP and HTTPS requests. More...

#include <ssgx_http_t_client.h>

Public Member Functions

 Client (const std::string &host)
 Constructor to initialize the client with a hostname.
 
 Client (const std::string &host, int port)
 Constructor to initialize the client with a hostname and port.
 
 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.
 
virtual ~Client ()=default
 Destructor to clean up resources.
 
Result Get (const std::string &path, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
 Sends a GET request.
 
Result Get (const std::string &path, const TypeHeaders &headers, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
 Sends a GET request with HTTP headers.
 
Result Get (const std::string &path, const TypeParams &params, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
 Sends a GET request with URL parameters.
 
Result Get (const std::string &path, const TypeHeaders &headers, const TypeParams &params, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
 Sends a GET request with HTTP headers and URL parameters.
 
Result Post (const std::string &path, int time_out_sec=SSGX_HTTP_CLIENT_TIMEOUT)
 Sends a POST request.
 
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 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 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 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 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.
 

Detailed Description

Client class for making HTTP and HTTPS requests.

This class encapsulates the functionality required to connect to an HTTP/HTTPS server and send requests using common methods like GET and POST. It supports setting custom headers, URL parameters, request bodies, and timeouts. For HTTPS connections, it handles server certificate verification against either the system's default CA certificate store or a user-provided CA certificate.

Constructor & Destructor Documentation

◆ Client() [1/3]

ssgx::http_t::Client::Client ( const std::string & host)
explicit

Constructor to initialize the client with a hostname.

  1. The default port will be used for connection.
  2. For HTTPS, will use the default ca root certificate store to verify server's certificate.
Parameters
hostServer hostname.

◆ Client() [2/3]

ssgx::http_t::Client::Client ( const std::string & host,
int port )
explicit

Constructor to initialize the client with a hostname and port.

For HTTPS, will use the default ca root certificate store to verify server's certificate.

Parameters
hostServer hostname.
portServer port number.

◆ Client() [3/3]

ssgx::http_t::Client::Client ( const std::string & host,
int port,
const std::string & server_ca )
explicit

Constructor to initialize the client with a hostname, port, and server CA certificate.

For HTTPS, will use server_ca to verify server's certificate.

Parameters
hostServer hostname.
portServer port number.
server_caServer CA certificate chain, in PEM format.

◆ ~Client()

virtual ssgx::http_t::Client::~Client ( )
virtualdefault

Destructor to clean up resources.

Member Function Documentation

◆ Get() [1/4]

Result ssgx::http_t::Client::Get ( const std::string & path,
const TypeHeaders & headers,
const TypeParams & params,
int time_out_sec = SSGX_HTTP_CLIENT_TIMEOUT )

Sends a GET request with HTTP headers and URL parameters.

Parameters
pathRequest path.
headersHTTP headers.
paramsURL parameters.
time_out_secTimeout duration (in seconds), default is SSGX_HTTP_CLIENT_TIMEOUT.
Returns
Request result.

◆ Get() [2/4]

Result ssgx::http_t::Client::Get ( const std::string & path,
const TypeHeaders & headers,
int time_out_sec = SSGX_HTTP_CLIENT_TIMEOUT )

Sends a GET request with HTTP headers.

Parameters
pathRequest path.
headersHTTP headers.
time_out_secTimeout duration (in seconds), default is SSGX_HTTP_CLIENT_TIMEOUT.
Returns
Request result.

◆ Get() [3/4]

Result ssgx::http_t::Client::Get ( const std::string & path,
const TypeParams & params,
int time_out_sec = SSGX_HTTP_CLIENT_TIMEOUT )

Sends a GET request with URL parameters.

Parameters
pathRequest path.
paramsURL parameters.
time_out_secTimeout duration (in seconds), default is SSGX_HTTP_CLIENT_TIMEOUT.
Returns
Request result.

◆ Get() [4/4]

Result ssgx::http_t::Client::Get ( const std::string & path,
int time_out_sec = SSGX_HTTP_CLIENT_TIMEOUT )

Sends a GET request.

Parameters
pathRequest path.
time_out_secTimeout duration (in seconds), default is SSGX_HTTP_CLIENT_TIMEOUT.
Returns
Request result.

◆ Post() [1/6]

Result ssgx::http_t::Client::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.

Parameters
pathRequest path.
bodyRequest body data (C-style string).
content_lengthBody length.
content_typeBody MIME type.
time_out_secTimeout duration (in seconds), default is SSGX_HTTP_CLIENT_TIMEOUT.
Returns
Request result.

◆ Post() [2/6]

Result ssgx::http_t::Client::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.

Parameters
pathRequest path.
bodyRequest body data (C++ string).
content_typeBody MIME type.
time_out_secTimeout duration (in seconds), default is SSGX_HTTP_CLIENT_TIMEOUT.
Returns
Request result.

◆ Post() [3/6]

Result ssgx::http_t::Client::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.

Parameters
pathRequest path.
headersHTTP headers.
bodyRequest body data (C-style string).
content_lengthBody length.
content_typeBody MIME type.
time_out_secTimeout duration (in seconds), default is SSGX_HTTP_CLIENT_TIMEOUT.
Returns
Request result.

◆ Post() [4/6]

Result ssgx::http_t::Client::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.

Parameters
pathRequest path.
headersHTTP headers.
bodyRequest body data (C++ string).
content_typeBody MIME type.
time_out_secTimeout duration (in seconds), default is SSGX_HTTP_CLIENT_TIMEOUT.
Returns
Request result.

◆ Post() [5/6]

Result ssgx::http_t::Client::Post ( const std::string & path,
const TypeHeaders & headers,
int time_out_sec = SSGX_HTTP_CLIENT_TIMEOUT )

Sends a POST request with HTTP headers.

Parameters
pathRequest path.
headersHTTP headers.
time_out_secTimeout duration (in seconds), default is SSGX_HTTP_CLIENT_TIMEOUT.
Returns
Request result.

◆ Post() [6/6]

Result ssgx::http_t::Client::Post ( const std::string & path,
int time_out_sec = SSGX_HTTP_CLIENT_TIMEOUT )

Sends a POST request.

Parameters
pathRequest path.
time_out_secTimeout duration (in seconds), default is SSGX_HTTP_CLIENT_TIMEOUT.
Returns
Request result.

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