tgbot-cpp
Loading...
Searching...
No Matches
TgBot::CurlHttpClient Class Reference

This class makes http requests via libcurl. More...

#include <CurlHttpClient.h>

Inheritance diagram for TgBot::CurlHttpClient:
TgBot::HttpClient

Public Member Functions

 CurlHttpClient ()
 ~CurlHttpClient () override
std::string makeRequest (const std::string &url, std::span< const HttpFormField > fields) const override
 Sends a request to the url.
void setProxy (const char *url=NULL, long timeout=20L)
 Proxy URL (NULL = no proxy).
Public Member Functions inherited from TgBot::HttpClient
virtual ~HttpClient ()=default
virtual int getRequestMaxRetries () const
 Get the maximum number of makeRequest() retries before giving up and throwing an exception.
virtual int getRequestBackoff () const
 Get the makeRequest() backoff duration between retries, in seconds.
virtual void cancel (const bool eternal=false) const
 Cancels the requests.
virtual bool isEternalCancelled () const
 Checks if the HTTP client is permanently disabled.
virtual const std::string & getCancelExceptionText () const
 Get the exception message that occurs when the request is aborted.

Public Attributes

std::unordered_map< std::thread::id, CURL * > curlHandles
 Raw curl handles, each thread has its own handle.
std::mutex curlHandlesMutex
 Lock for curlHandles access.
Public Attributes inherited from TgBot::HttpClient
std::int32_t _timeout = 25

Additional Inherited Members

Protected Attributes inherited from TgBot::HttpClient
std::atomic< bool > _isEternalCancel { false }
 Flag indicating whether the HTTP client is permanently disabled.
std::atomic< uint64_t > _cancelEpoch { 0 }
 Counter used to invalidate current requests.

Detailed Description

This class makes http requests via libcurl.

Definition at line 21 of file CurlHttpClient.h.

Constructor & Destructor Documentation

◆ CurlHttpClient()

TgBot::CurlHttpClient::CurlHttpClient ( )

◆ ~CurlHttpClient()

TgBot::CurlHttpClient::~CurlHttpClient ( )
override

Member Function Documentation

◆ makeRequest()

std::string TgBot::CurlHttpClient::makeRequest ( const std::string & url,
std::span< const HttpFormField > fields ) const
overridevirtual

Sends a request to the url.

If there are no fields, a GET request is sent. Otherwise, a multipart/form-data POST request is sent.

Implements TgBot::HttpClient.

◆ setProxy()

void TgBot::CurlHttpClient::setProxy ( const char * url = NULL,
long timeout = 20L )
inline

Proxy URL (NULL = no proxy).

Definition at line 46 of file CurlHttpClient.h.

Member Data Documentation

◆ curlHandles

std::unordered_map<std::thread::id, CURL*> TgBot::CurlHttpClient::curlHandles

Raw curl handles, each thread has its own handle.

Definition at line 36 of file CurlHttpClient.h.

◆ curlHandlesMutex

std::mutex TgBot::CurlHttpClient::curlHandlesMutex

Lock for curlHandles access.

Definition at line 41 of file CurlHttpClient.h.


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