blob: 18546d7ed23e53d0dd7b207b39ff0496d3ea76a6 (
plain) (
blame)
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
|
// license:MIT
// copyright-holders:Ole Christian Eidheim, Miodrag Milanovic
#ifndef MAME_LIB_UTIL_SERVER_WS_HPP
#define MAME_LIB_UTIL_SERVER_WS_HPP
#include <memory>
#include <atomic>
#ifndef CASE_INSENSITIVE_EQUALS_AND_HASH
#define CASE_INSENSITIVE_EQUALS_AND_HASH
class case_insensitive_equals {
public:
bool operator()(const std::string &key1, const std::string &key2) const {
return key1.size() == key2.size()
&& equal(key1.cbegin(), key1.cend(), key2.cbegin(),
[](std::string::value_type key1v, std::string::value_type key2v)
{ return tolower(key1v) == tolower(key2v); });
}
};
class case_insensitive_hash {
public:
size_t operator()(const std::string &key) const {
size_t seed = 0;
for (auto &c : key) {
std::hash<char> hasher;
seed ^= hasher(std::tolower(c)) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
return seed;
}
};
#endif /* CASE_INSENSITIVE_EQUALS_AND_HASH */
namespace webpp {
struct Connection {
std::string method, path, http_version;
std::unordered_multimap<std::string, std::string, case_insensitive_hash, case_insensitive_equals> header;
std::smatch path_match;
std::string remote_endpoint_address;
unsigned short remote_endpoint_port;
Connection(unsigned short remote_endpoint_port) : remote_endpoint_port(remote_endpoint_port) {}
virtual ~Connection() {}
};
class ws_server;
}
#endif /* MAME_LIB_UTIL_SERVER_WS_HPP */
|