-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhttpclient_async.hpp
64 lines (54 loc) · 2.23 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
61
62
63
64
#pragma once
#include <utils/object.hpp>
#include <curl/curl.h>
#include <filesystem>
#include <functional>
#include <map>
class HttpClientAsync : noncopyable
{
DISABLE_COPY_MOVE(HttpClientAsync) // for clang-tidy
public:
using Callback = std::function<void(const std::string &)>;
using Headers = std::map<std::string, std::string>;
HttpClientAsync();
~HttpClientAsync();
auto get(const std::string &url, const Headers &headers = {}, Callback callback = nullptr)
-> CURL *;
auto post(const std::string &url,
const std::string &data,
const Headers &headers = {},
Callback callback = nullptr) -> CURL *;
auto put(const std::string &url,
const std::string &data,
const Headers &headers = {},
Callback callback = nullptr) -> CURL *;
auto del(const std::string &url, const Headers &headers = {}, Callback callback = nullptr)
-> CURL *;
auto options(const std::string &url, const Headers &headers = {}, Callback callback = nullptr)
-> CURL *;
auto patch(const std::string &url,
const std::string &data,
const Headers &headers = {},
Callback callback = nullptr) -> CURL *;
auto sendCustomRequest(const std::string &url,
const std::string &method,
const std::string &data,
const Headers &headers,
Callback callback) -> CURL *;
void cancel(CURL *handle);
auto download(const std::string &url,
const std::filesystem::path &path,
const Headers &headers = {},
Callback callback = nullptr) -> CURL *;
auto upload_put(const std::string &url,
const std::filesystem::path &path,
const Headers &headers = {},
Callback callback = nullptr) -> CURL *;
auto upload_post(const std::string &url,
const std::filesystem::path &path,
const Headers &headers = {},
Callback callback = nullptr) -> CURL *;
private:
class HttpClientAsyncPrivate;
std::unique_ptr<HttpClientAsyncPrivate> d_ptr;
};