-
Notifications
You must be signed in to change notification settings - Fork 0
/
RESTChannelHandler.cpp
53 lines (32 loc) · 1.21 KB
/
RESTChannelHandler.cpp
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
#include "RESTChannelHandler.h"
void RESTChannelHandler::onMessageReceived(Channel &channel, std::string &payload) {
try {
Request request(payload, channel);
bool done = false;
boost::match_results<string::const_iterator> capture;
for (unsigned int i = 0; i < (*mRequestMap)[request.method].size(); i++) {
if (regex_search(request.path, capture, (*mRequestMap)[request.method][i].pathre) ) {
// push all matches into parameters.
for (unsigned int j = 0; j < (*mRequestMap)[request.method][i].names.size(); j++)
request.setParameter((*mRequestMap)[request.method][i].names[j], capture[j+1]);
Response res(&channel);
MethodHandler f;
f = (*mRequestMap)[request.method][i].func;
f(request, res);
done = true;
break;
}
}
if (! done) {
Response fof(&channel, 404);
fof.write();
}
}
catch(Exception e) {
Response five(&channel, 500);
five.write();
}
// done. close connection
channel.close();
}
// vim: ts=4:sw=4:expandtab