tgbot-cpp
Loading...
Searching...
No Matches
CurlHttpClient.h
Go to the documentation of this file.
1#pragma once
2
3#include "tgbot/HttpClient.h"
4#include "tgbot/export.h"
5
6#include <curl/curl.h>
7
8#include <mutex>
9#include <span>
10#include <string>
11#include <thread>
12#include <unordered_map>
13
14namespace TgBot {
15
22public:
24 ~CurlHttpClient() override;
25
31 std::string makeRequest(const std::string& url, std::span<const HttpFormField> fields) const override;
32
36 std::unordered_map<std::thread::id, CURL*> curlHandles;
37
41 std::mutex curlHandlesMutex;
42
46 void setProxy(const char* url = NULL, long timeout = 20L) {
47 _proxyUrl = url;
48 _connectTimeout = timeout;
49 }
50
51private:
52 const char* _proxyUrl = NULL;
53 long _connectTimeout = 20L;
54};
55
56} // namespace TgBot
std::unordered_map< std::thread::id, CURL * > curlHandles
Raw curl handles, each thread has its own handle.
std::string makeRequest(const std::string &url, std::span< const HttpFormField > fields) const override
Sends a request to the url.
std::mutex curlHandlesMutex
Lock for curlHandles access.
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
#define TGBOT_API
Definition export.h:5
Definition Api.h:17