yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::net::HttpLibClient Class Reference

Native HTTP client implementation using cpp-httplib. More...

#include <httplib_client.h>

Inheritance diagram for yaze::net::HttpLibClient:
Collaboration diagram for yaze::net::HttpLibClient:

Public Member Functions

 HttpLibClient ()
 
 ~HttpLibClient () override
 
absl::StatusOr< HttpResponseGet (const std::string &url, const Headers &headers={}) override
 Perform an HTTP GET request.
 
absl::StatusOr< HttpResponsePost (const std::string &url, const std::string &body, const Headers &headers={}) override
 Perform an HTTP POST request.
 
absl::StatusOr< HttpResponsePut (const std::string &url, const std::string &body, const Headers &headers={}) override
 Perform an HTTP PUT request.
 
absl::StatusOr< HttpResponseDelete (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ HttpLibClient()

yaze::net::HttpLibClient::HttpLibClient ( )

Definition at line 16 of file httplib_client.cc.

◆ ~HttpLibClient()

yaze::net::HttpLibClient::~HttpLibClient ( )
override

Definition at line 20 of file httplib_client.cc.

References client_cache_.

Member Function Documentation

◆ Get()

absl::StatusOr< HttpResponse > yaze::net::HttpLibClient::Get ( const std::string & url,
const Headers & headers = {} )
overridevirtual

Perform an HTTP GET request.

Parameters
urlThe URL to request
headersOptional HTTP headers
Returns
HttpResponse or error status

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.

Here is the call graph for this function:

◆ Post()

absl::StatusOr< HttpResponse > yaze::net::HttpLibClient::Post ( const std::string & url,
const std::string & body,
const Headers & headers = {} )
overridevirtual

Perform an HTTP POST request.

Parameters
urlThe URL to post to
bodyThe request body
headersOptional HTTP headers
Returns
HttpResponse or error status

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.

Here is the call graph for this function:

◆ Put()

absl::StatusOr< HttpResponse > yaze::net::HttpLibClient::Put ( const std::string & url,
const std::string & body,
const Headers & headers = {} )
overridevirtual

Perform an HTTP PUT request.

Parameters
urlThe URL to put to
bodyThe request body
headersOptional HTTP headers
Returns
HttpResponse or error status

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.

Here is the call graph for this function:

◆ Delete()

absl::StatusOr< HttpResponse > yaze::net::HttpLibClient::Delete ( const std::string & url,
const Headers & headers = {} )
overridevirtual

Perform an HTTP DELETE request.

Parameters
urlThe URL to delete
headersOptional HTTP headers
Returns
HttpResponse or error status

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.

Here is the call graph for this function:

◆ SetTimeout()

void yaze::net::HttpLibClient::SetTimeout ( int timeout_seconds)
overridevirtual

Set a timeout for HTTP requests.

Parameters
timeout_secondsTimeout in seconds

Reimplemented from yaze::net::IHttpClient.

Definition at line 259 of file httplib_client.cc.

References client_cache_, and yaze::net::IHttpClient::SetTimeout().

Here is the call graph for this function:

◆ ParseUrl()

absl::Status yaze::net::HttpLibClient::ParseUrl ( const std::string & url,
std::string & scheme,
std::string & host,
int & port,
std::string & path ) const
private

Parse URL into components.

Parameters
urlThe URL to parse
schemeOutput: URL scheme (http/https)
hostOutput: Host name
portOutput: Port number
pathOutput: Path component
Returns
Status indicating success or failure

Definition at line 25 of file httplib_client.cc.

Referenced by Delete(), Get(), Post(), and Put().

◆ GetOrCreateClient()

absl::StatusOr< std::shared_ptr< httplib::Client > > yaze::net::HttpLibClient::GetOrCreateClient ( const std::string & scheme,
const std::string & host,
int port )
private

Create or get cached httplib client for a host.

Parameters
schemeURL scheme (http/https)
hostHost name
portPort number
Returns
httplib::Client pointer or error

Definition at line 54 of file httplib_client.cc.

References client_cache_, and yaze::net::IHttpClient::timeout_seconds_.

Referenced by Delete(), Get(), Post(), and Put().

◆ ConvertHeaders()

Headers yaze::net::HttpLibClient::ConvertHeaders ( const void * httplib_headers) const
private

Convert httplib headers to our Headers type.

Parameters
httplib_headershttplib header structure
Returns
Headers map

Definition at line 100 of file httplib_client.cc.

Referenced by Delete(), Get(), Post(), and Put().

Member Data Documentation

◆ client_cache_

std::map<std::string, std::shared_ptr<httplib::Client> > yaze::net::HttpLibClient::client_cache_
private

Definition at line 115 of file httplib_client.h.

Referenced by GetOrCreateClient(), SetTimeout(), and ~HttpLibClient().


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