-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhttp_types.h
More file actions
60 lines (52 loc) · 1.07 KB
/
http_types.h
File metadata and controls
60 lines (52 loc) · 1.07 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 DCUE_HTTP_TYPES_H
#define DCUE_HTTP_TYPES_H
#include <cstdint>
#include <string>
#include <vector>
enum class HttpStatus { OK, NOT_FOUND, FORBIDDEN, INT_ERR, OTHER_FAIL };
inline HttpStatus rawCodeToHttpStatus(long respCode) {
auto rv = HttpStatus::OTHER_FAIL;
switch (respCode) {
case 200:
rv = HttpStatus::OK;
break;
case 403:
rv = HttpStatus::FORBIDDEN;
break;
case 404:
rv = HttpStatus::NOT_FOUND;
break;
case 500:
rv = HttpStatus::INT_ERR;
break;
}
return rv;
}
struct HttpHeader {
std::string name;
std::string value;
};
struct HttpResponse {
HttpStatus status;
std::vector<HttpHeader> headers;
std::vector<std::uint8_t> body;
};
namespace http_internal {
class HttpGetCommon {
protected:
std::vector<HttpHeader> headers;
std::string hostname;
std::string resource;
public:
void add_header(HttpHeader&& header) {
headers.emplace_back(header);
}
void set_resource(std::string_view res) {
resource = res;
}
void set_hostname(std::string_view hname) {
hostname = hname;
}
};
}
#endif