-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_session.h
46 lines (33 loc) · 1.25 KB
/
http_session.h
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
#ifndef HTTP_SESSION_H
#define HTTP_SESSION_H
#include <string>
#include <vector>
#include <curl/curl.h>
namespace reddit {
class HttpSession {
public:
~HttpSession();
static HttpSession* ConstructNew(const std::string& user_agent);
struct PostField {
std::string key;
std::string value;
};
std::string user_agent() const;
static std::string PostFieldToString(const PostField& field);
static std::string PostFieldsToString(const std::vector<PostField>& fields);
bool Get(const std::string& url, std::string* hdrs, std::string* body);
bool Get(const std::string& url, const std::vector<PostField>& fields, std::string* hdrs, std::string* body);
bool Post(const std::string& url, const std::vector<PostField>& post_data, std::string* hdrs, std::string* body);
bool Post(const std::string& url, const std::string& post_data, std::string* hdrs, std::string* body);
void AddCustomHeader(const std::string& key, const std::string& value);
void ClearCustomHeaders();
private:
CURL* curl_;
curl_slist* custom_headers_;
const std::string user_agent_;
HttpSession(const std::string& user_agent);
bool Init();
static size_t WriteData(void* ptr, size_t size, size_t nmemb, void* arg);
};
}; // namespace
#endif