algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::network::HttpClient Class Reference

A blocking HTTP/1.1 client over TLS that keeps one connection to one host. More...

#include <algotradelib/src/network/http_client.hpp>

Public Member Functions

 HttpClient (net::io_context &ioc, ssl::context &context, std::string host, std::string port, HttpClientOptions options={})
 Constructs a client; it connects on the first request.
HttpResponse get (const std::string &target, const std::map< std::string, std::string > &headers={})
 Sends a GET request and waits for the response.
HttpResponse post (const std::string &target, const std::string &body, const std::map< std::string, std::string > &headers={})
 Sends a POST request and waits for the response; never retried.
HttpResponse request (http::verb method, const std::string &target, const std::string &body={}, const std::map< std::string, std::string > &headers={})
 Sends a request and waits for the response; a GET that fails is sent once more.
void close ()
 Closes the connection; the next request opens a new one.

Detailed Description

A blocking HTTP/1.1 client over TLS that keeps one connection to one host.

Not paced, not thread-safe, and with no enforced deadlines: a blocking DNS lookup, connect, TLS handshake, write, read, or the TLS shutdown when closing can wait indefinitely. Broker clients use AsyncHttpClient.

Definition at line 172 of file http_client.hpp.

Constructor & Destructor Documentation

◆ HttpClient()

algotradelib::network::HttpClient::HttpClient ( net::io_context & ioc,
ssl::context & context,
std::string host,
std::string port,
HttpClientOptions options = {} )
inline

Constructs a client; it connects on the first request.

Parameters
iocThe I/O context.
contextThe TLS context; borrowed, and must outlive the client. The client installs SNI and a host-name check; for the peer to be verified, the context must enable ssl::verify_peer and hold trusted roots.
hostThe host name (also used for SNI and certificate verification).
portThe port.
optionsThe options; rate_limit_ and queue_limit_ are not used.

Definition at line 184 of file http_client.hpp.

Member Function Documentation

◆ close()

void algotradelib::network::HttpClient::close ( )
inline

Closes the connection; the next request opens a new one.

Definition at line 294 of file http_client.hpp.

◆ get()

HttpResponse algotradelib::network::HttpClient::get ( const std::string & target,
const std::map< std::string, std::string > & headers = {} )
inline

Sends a GET request and waits for the response.

Parameters
targetThe path and query.
headersAdditional headers.
Returns
The response, whatever its status.
Exceptions
boost::system::system_erroron a transport failure (after one retry).

Definition at line 201 of file http_client.hpp.

◆ post()

HttpResponse algotradelib::network::HttpClient::post ( const std::string & target,
const std::string & body,
const std::map< std::string, std::string > & headers = {} )
inline

Sends a POST request and waits for the response; never retried.

Parameters
targetThe path and query.
bodyThe body.
headersAdditional headers.
Returns
The response, whatever its status.
Exceptions
boost::system::system_erroron a transport failure.

Definition at line 216 of file http_client.hpp.

◆ request()

HttpResponse algotradelib::network::HttpClient::request ( http::verb method,
const std::string & target,
const std::string & body = {},
const std::map< std::string, std::string > & headers = {} )
inline

Sends a request and waits for the response; a GET that fails is sent once more.

Parameters
methodThe HTTP method.
targetThe path and query.
bodyThe body.
headersAdditional headers.
Returns
The response, whatever its status.
Exceptions
boost::system::system_erroron a transport failure.

Definition at line 233 of file http_client.hpp.


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