-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhttpclient_async.hpp
60 lines (50 loc) · 2.08 KB
/
httpclient_async.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include <utils/object.hpp>
#include <curl/curl.h>
#include <filesystem>
#include <functional>
#include <map>
class HttpClientAsync : noncopyable
{
public:
using Callback = std::function<void(const std::string &)>;
using Headers = std::map<std::string, std::string>;
HttpClientAsync();
~HttpClientAsync();
CURL *get(const std::string &url, const Headers &headers = {}, Callback callback = nullptr);
CURL *post(const std::string &url,
const std::string &data,
const Headers &headers = {},
Callback callback = nullptr);
CURL *put(const std::string &url,
const std::string &data,
const Headers &headers = {},
Callback callback = nullptr);
CURL *del(const std::string &url, const Headers &headers = {}, Callback callback = nullptr);
CURL *options(const std::string &url, const Headers &headers = {}, Callback callback = nullptr);
CURL *patch(const std::string &url,
const std::string &data,
const Headers &headers = {},
Callback callback = nullptr);
CURL *sendCustomRequest(const std::string &url,
const std::string &method,
const std::string &data,
const Headers &headers,
Callback callback);
void cancel(CURL *handle);
CURL *download(const std::string &url,
const std::filesystem::path &path,
const Headers &headers = {},
Callback callback = nullptr);
CURL *upload_put(const std::string &url,
const std::filesystem::path &path,
const Headers &headers = {},
Callback callback = nullptr);
CURL *upload_post(const std::string &url,
const std::filesystem::path &path,
const Headers &headers = {},
Callback callback = nullptr);
private:
class HttpClientAsyncPrivate;
std::unique_ptr<HttpClientAsyncPrivate> d_ptr;
};