tgbot-cpp
Loading...
Searching...
No Matches
CurlHttpClient.h
Go to the documentation of this file.
1#ifndef TGBOT_CURLHTTPCLIENT_H
2#define TGBOT_CURLHTTPCLIENT_H
3
4#ifdef HAVE_CURL
5
7#include "tgbot/net/Url.h"
10
11#include <curl/curl.h>
12
13#include <mutex>
14#include <string>
15#include <vector>
16#include <thread>
17#include <unordered_map>
18
19namespace TgBot {
20
26class TGBOT_API CurlHttpClient : public HttpClient {
27
28public:
30 ~CurlHttpClient() override;
31
38 std::string makeRequest(const Url& url, const std::vector<HttpReqArg>& args) const override;
39
43 std::unordered_map<std::thread::id, CURL*> curlHandles;
44
48 std::mutex curlHandlesMutex;
49
53 void setProxy(const char* url = NULL, long timeout = 20L) {
54 _proxyUrl = url;
55 _connectTimeout = timeout;
56 }
57
58private:
59 const HttpParser _httpParser;
60 const char* _proxyUrl = NULL;
61 long _connectTimeout = 20L;
62
63};
64
65}
66
67#endif
68
69#endif //TGBOT_CURLHTTPCLIENT_H
std::unordered_map< std::thread::id, CURL * > curlHandles
Raw curl handles, each thread has its own handle.
std::mutex curlHandlesMutex
Lock for curlHandles access.
std::string makeRequest(const Url &url, const std::vector< HttpReqArg > &args) const override
Sends a request to the url.
void setProxy(const char *url=NULL, long timeout=20L)
Proxy URL (NULL = no proxy).
~CurlHttpClient() override
This class makes http requests.
Definition HttpClient.h:18
This class parses a string with the url.
Definition Url.h:15
Definition Api.h:40