-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcHTTPClient.h
More file actions
105 lines (89 loc) · 2.51 KB
/
cHTTPClient.h
File metadata and controls
105 lines (89 loc) · 2.51 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once
#include <chrono>
#include <cstdint>
#include <string>
#include <vector>
class cHTTPClient
{
public:
struct st_Header
{
std::string name;
std::string value;
};
using td_Headers = std::vector<st_Header>;
enum class enm_Method : std::uint8_t
{
Get = 0,
Post,
Put,
Patch,
Delete,
Head
};
struct st_Request
{
std::string url;
enm_Method method{enm_Method::Get};
td_Headers headers;
std::string body;
std::string userAgent{"HotBits/cHTTPClient"};
std::string contentType;
std::string accept;
std::string basicAuthUser;
std::string basicAuthPassword;
std::string bearerToken;
std::string caInfoPath;
std::chrono::milliseconds connectTimeout{10000};
std::chrono::milliseconds timeout{30000};
long maxRedirects{10};
bool followRedirects{true};
bool verifyPeer{true};
bool verifyHost{true};
bool acceptCompressedResponse{true};
};
struct st_Response
{
long statusCode{0};
std::int32_t curlCode{0};
std::string body;
td_Headers headers;
std::string rawHeaders;
std::string effectiveUrl;
std::string errorMessage;
std::chrono::milliseconds elapsed{0};
[[nodiscard]] bool ok() const noexcept;
[[nodiscard]] std::string headerValue(const std::string &name) const;
};
cHTTPClient() = default;
~cHTTPClient() = default;
cHTTPClient(const cHTTPClient &) = default;
cHTTPClient &operator=(const cHTTPClient &) = default;
cHTTPClient(cHTTPClient &&) noexcept = default;
cHTTPClient &operator=(cHTTPClient &&) noexcept = default;
[[nodiscard]] st_Response perform(const st_Request &request) const;
[[nodiscard]] st_Response get(
const std::string &url,
const td_Headers &headers = {}) const;
[[nodiscard]] st_Response post(
const std::string &url,
const std::string &body,
const td_Headers &headers = {},
const std::string &contentType = {}) const;
[[nodiscard]] st_Response put(
const std::string &url,
const std::string &body,
const td_Headers &headers = {},
const std::string &contentType = {}) const;
[[nodiscard]] st_Response patch(
const std::string &url,
const std::string &body,
const td_Headers &headers = {},
const std::string &contentType = {}) const;
[[nodiscard]] st_Response del(
const std::string &url,
const td_Headers &headers = {}) const;
[[nodiscard]] st_Response head(
const std::string &url,
const td_Headers &headers = {}) const;
};