forked from yedf2/handy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp-hello.cc
More file actions
28 lines (26 loc) · 732 Bytes
/
http-hello.cc
File metadata and controls
28 lines (26 loc) · 732 Bytes
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
#include <handy/handy.h>
using namespace std;
using namespace handy;
int main(int argc, const char *argv[]) {
int threads = 1;
if (argc > 1) {
threads = atoi(argv[1]);
}
setloglevel("TRACE");
MultiBase base(threads);
HttpServer sample(&base);
int r = sample.bind("", 8081);
exitif(r, "bind failed %d %s", errno, strerror(errno));
sample.onGet("/hello", [](const HttpConnPtr &con) {
string v = con.getRequest().version;
HttpResponse resp;
resp.body = Slice("hello world");
con.sendResponse(resp);
if (v == "HTTP/1.0") {
con->close();
}
});
Signal::signal(SIGINT, [&] { base.exit(); });
base.loop();
return 0;
}