-
Notifications
You must be signed in to change notification settings - Fork 0
/
25_cn_url_server.cc
44 lines (36 loc) · 881 Bytes
/
25_cn_url_server.cc
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
#include "workflow/WFFacilities.h"
#include <csignal>
#include "wfrest/HttpServer.h"
#include "wfrest/CodeUtil.h"
using namespace wfrest;
static WFFacilities::WaitGroup wait_group(1);
void sig_handler(int signo)
{
wait_group.done();
}
int main()
{
signal(SIGINT, sig_handler);
HttpServer svr;
// curl -v http://ip:port/你好
// or you can use 25_cn_url_client
svr.GET(CodeUtil::url_encode("/你好"), [](const HttpReq *req, HttpResp *resp)
{
resp->String("world\n");
});
svr.GET(CodeUtil::url_encode("/你好/吃了吗/"), [](const HttpReq *req, HttpResp *resp)
{
resp->String("eat\n");
});
if (svr.track().start(8888) == 0)
{
svr.list_routes();
wait_group.wait();
svr.stop();
} else
{
fprintf(stderr, "Cannot start server");
exit(1);
}
return 0;
}