-
Notifications
You must be signed in to change notification settings - Fork 3
/
http.h
97 lines (81 loc) · 1.81 KB
/
http.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
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
#include <stdint.h>
#include <string>
#include <map>
#include "network.h"
class URL {
public:
URL(const std::string &url);
URL(const char *url);
const std::string &url() const;
const std::string &host() const;
uint16_t port() const;
const std::string &path() const;
bool secure() const;
private:
void parse();
std::string mUrl;
std::string mHost;
uint16_t mPort;
std::string mPath;
bool mSecure;
};
class HTTPRequest {
public:
typedef enum {
HEAD = 0,
GET = 1,
POST = 2,
PUT = 3,
DELETE = 4,
OPTIONS = 5,
TRACE = 6
// , CONNECT = 7 ?
} Method;
static const std::string methodStr[];
HTTPRequest(Method method, const URL &url);
std::string &operator [](const std::string &key);
void send(InstantSend::Connection conn);
private:
std::string mFirst;
std::map<std::string, std::string> mFields;
};
class HTTPResponse {
public:
HTTPResponse(InstantSend::Connection conn);
const std::string &version() const;
int code() const;
const std::string &respStr();
const std::string &operator [](const std::string &key) const;
private:
static std::string readLine(InstantSend::Connection conn);
std::string mVer, mRS;
int mCode;
std::map<std::string, std::string> mFields;
};
inline const std::string &URL::url() const {
return mUrl;
}
inline const std::string &URL::host() const {
return mHost;
}
inline uint16_t URL::port() const {
return mPort;
}
inline const std::string &URL::path() const {
return mPath;
}
inline bool URL::secure() const {
return mSecure;
}
inline std::string &HTTPRequest::operator [](const std::string &key) {
return mFields[key];
}
inline const std::string &HTTPResponse::version() const {
return mVer;
}
inline int HTTPResponse::code() const {
return mCode;
}
inline const std::string &HTTPResponse::respStr() {
return mRS;
}