A blocking HTTP/1.1 client over TLS that keeps one connection to one host.
More...
#include <algotradelib/src/network/http_client.hpp>
|
| | 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.
|
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.
◆ 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
-
| ioc | The I/O context. |
| context | The 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. |
| host | The host name (also used for SNI and certificate verification). |
| port | The port. |
| options | The options; rate_limit_ and queue_limit_ are not used. |
Definition at line 184 of file http_client.hpp.
◆ 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
-
| target | The path and query. |
| headers | Additional headers. |
- Returns
- The response, whatever its status.
- Exceptions
-
| boost::system::system_error | on 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
-
| target | The path and query. |
| body | The body. |
| headers | Additional headers. |
- Returns
- The response, whatever its status.
- Exceptions
-
| boost::system::system_error | on 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
-
| method | The HTTP method. |
| target | The path and query. |
| body | The body. |
| headers | Additional headers. |
- Returns
- The response, whatever its status.
- Exceptions
-
| boost::system::system_error | on a transport failure. |
Definition at line 233 of file http_client.hpp.
The documentation for this class was generated from the following file: