-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_req.h
More file actions
60 lines (49 loc) · 1.37 KB
/
Copy pathhttp_req.h
File metadata and controls
60 lines (49 loc) · 1.37 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
#ifndef _HTTP_REQ_H_
#define _HTTP_REQ_H_
#include <string>
#include <vector>
#include <curl/curl.h>
using std::string;
using std::vector;
class HttpReqEvents
{
public:
virtual void OnReqSendHeaders() = 0;
virtual void OnReqRecvHeaders() = 0;
virtual void OnReqRecvData(size_t size) = 0;
virtual void OnComplete(unsigned long http_code) = 0;
};
class HttpReq
{
public:
HttpReq();
~HttpReq();
void SetUrl(const string &url);
void AddHeader(const string& header);
void AddHeader(const string& name, const string& value);
void AddGetRangeHeader(uint64_t start, uint64_t end);
void ReportEvents(HttpReqEvents *events);
void PerformGet();
size_t CurlReadCallback(char *data, size_t size);
size_t CurlWriteCallback(char *data, size_t size);
int CurlProgressCallback(double download_total, double download_now,
double upload_total, double upload_now);
int CurlDebugCallback(CURL *curl, curl_infotype infotype, char *buf, size_t len);
static int Init();
static void Fini();
void SetCurlOptions();
void SetCurlHeaders();
void SetDataLimit(size_t len);
void InvokeCurl();
private:
string url_;
vector<string> headers_;
HttpReqEvents *events_;
size_t recv_limit_;
size_t recv_size_;
// curl
CURL* curl_;
struct curl_slist* curl_headers_;
char curl_error_buffer_[CURL_ERROR_SIZE];
};
#endif /* _HTTP_REQ_H_ */