Native HTTP client implementation using cpp-httplib. More...
#include <httplib_client.h>


Public Member Functions | |
| HttpLibClient () | |
| ~HttpLibClient () override | |
| absl::StatusOr< HttpResponse > | Get (const std::string &url, const Headers &headers={}) override |
| Perform an HTTP GET request. | |
| absl::StatusOr< HttpResponse > | Post (const std::string &url, const std::string &body, const Headers &headers={}) override |
| Perform an HTTP POST request. | |
| absl::StatusOr< HttpResponse > | Put (const std::string &url, const std::string &body, const Headers &headers={}) override |
| Perform an HTTP PUT request. | |
| absl::StatusOr< HttpResponse > | Delete (const std::string &url, const Headers &headers={}) override |
| Perform an HTTP DELETE request. | |
| void | SetTimeout (int timeout_seconds) override |
| Set a timeout for HTTP requests. | |
Public Member Functions inherited from yaze::net::IHttpClient | |
| virtual | ~IHttpClient ()=default |
| int | GetTimeout () const |
| Get the current timeout setting. | |
Private Member Functions | |
| absl::Status | ParseUrl (const std::string &url, std::string &scheme, std::string &host, int &port, std::string &path) const |
| Parse URL into components. | |
| absl::StatusOr< std::shared_ptr< httplib::Client > > | GetOrCreateClient (const std::string &scheme, const std::string &host, int port) |
| Create or get cached httplib client for a host. | |
| Headers | ConvertHeaders (const void *httplib_headers) const |
| Convert httplib headers to our Headers type. | |
Private Attributes | |
| std::map< std::string, std::shared_ptr< httplib::Client > > | client_cache_ |
Additional Inherited Members | |
Protected Attributes inherited from yaze::net::IHttpClient | |
| int | timeout_seconds_ = 30 |
Native HTTP client implementation using cpp-httplib.
This implementation wraps the cpp-httplib library for native builds, providing HTTP/HTTPS support with optional SSL/TLS via OpenSSL.
Definition at line 24 of file httplib_client.h.
| yaze::net::HttpLibClient::HttpLibClient | ( | ) |
Definition at line 16 of file httplib_client.cc.
|
override |
Definition at line 20 of file httplib_client.cc.
References client_cache_.
|
overridevirtual |
Perform an HTTP GET request.
| url | The URL to request |
| headers | Optional HTTP headers |
Implements yaze::net::IHttpClient.
Definition at line 113 of file httplib_client.cc.
References ASSIGN_OR_RETURN, yaze::net::HttpResponse::body, ConvertHeaders(), GetOrCreateClient(), yaze::net::HttpResponse::headers, ParseUrl(), RETURN_IF_ERROR, and yaze::net::HttpResponse::status_code.

|
overridevirtual |
Perform an HTTP POST request.
| url | The URL to post to |
| body | The request body |
| headers | Optional HTTP headers |
Implements yaze::net::IHttpClient.
Definition at line 146 of file httplib_client.cc.
References ASSIGN_OR_RETURN, yaze::net::HttpResponse::body, ConvertHeaders(), GetOrCreateClient(), yaze::net::HttpResponse::headers, ParseUrl(), RETURN_IF_ERROR, and yaze::net::HttpResponse::status_code.

|
overridevirtual |
Perform an HTTP PUT request.
| url | The URL to put to |
| body | The request body |
| headers | Optional HTTP headers |
Reimplemented from yaze::net::IHttpClient.
Definition at line 186 of file httplib_client.cc.
References ASSIGN_OR_RETURN, yaze::net::HttpResponse::body, ConvertHeaders(), GetOrCreateClient(), yaze::net::HttpResponse::headers, ParseUrl(), RETURN_IF_ERROR, and yaze::net::HttpResponse::status_code.

|
overridevirtual |
Perform an HTTP DELETE request.
| url | The URL to delete |
| headers | Optional HTTP headers |
Reimplemented from yaze::net::IHttpClient.
Definition at line 226 of file httplib_client.cc.
References ASSIGN_OR_RETURN, yaze::net::HttpResponse::body, ConvertHeaders(), GetOrCreateClient(), yaze::net::HttpResponse::headers, ParseUrl(), RETURN_IF_ERROR, and yaze::net::HttpResponse::status_code.

|
overridevirtual |
Set a timeout for HTTP requests.
| timeout_seconds | Timeout in seconds |
Reimplemented from yaze::net::IHttpClient.
Definition at line 259 of file httplib_client.cc.
References client_cache_, and yaze::net::IHttpClient::SetTimeout().

|
private |
Parse URL into components.
| url | The URL to parse |
| scheme | Output: URL scheme (http/https) |
| host | Output: Host name |
| port | Output: Port number |
| path | Output: Path component |
Definition at line 25 of file httplib_client.cc.
|
private |
Create or get cached httplib client for a host.
| scheme | URL scheme (http/https) |
| host | Host name |
| port | Port number |
Definition at line 54 of file httplib_client.cc.
References client_cache_, and yaze::net::IHttpClient::timeout_seconds_.
|
private |
|
private |
Definition at line 115 of file httplib_client.h.
Referenced by GetOrCreateClient(), SetTimeout(), and ~HttpLibClient().