-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheaders.h
More file actions
99 lines (81 loc) · 1.74 KB
/
headers.h
File metadata and controls
99 lines (81 loc) · 1.74 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
#ifndef __HEADERS_H
#define __HEADERS_H
#include <string>
#include <algorithm>
#include <map>
namespace Http
{
class Headers
{
public:
enum class Method
{
NONE,
GET,
HEAD,
POST,
PUT,
DELETE,
TRACE,
OPTIONS,
CONNECT,
PATCH
};
enum class Upgrade
{
NONE,
TLS,
WEBSOCKET
};
struct Version
{
int major;
int minor;
int patch;
inline bool operator==(const Version& other) const
{
return major == other.major &&
minor == other.minor &&
patch == other.patch;
}
};
Headers() :
m_upgrade(Upgrade::NONE),
m_method(Method::NONE),
m_path(),
m_http_version{0, 0, 0},
m_fields()
{}
std::string& get_field(std::string name)
{
return m_fields[name];
}
void set_field(std::string &name, const std::string &value)
{
// http://goo.gl/gEA0Tn
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
m_fields[name] = value;
}
Upgrade get_upgrade()
{
if (m_fields["upgrade"] == "websocket")
{
return Upgrade::WEBSOCKET;
}
return Upgrade::NONE;
}
Method get_method() { return m_method; }
void set_method(Method method) { m_method = method; }
Version get_http_version() { return m_http_version; }
void set_http_version(Version v) { m_http_version = v; }
std::string& get_path() { return m_path; }
void set_path(std::string &path) { m_path = path; }
private:
Method m_method;
std::string m_path;
Upgrade m_upgrade;
Version m_http_version;
std::map<std::string, std::string> m_fields;
};
} // namespace
#endif