1 Star 0 Fork 92

xystar2012 / handy

forked from yedf / handy 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
http-hello.cc 729 Bytes
一键复制 编辑 原始数据 按行查看 历史
yedf 提交于 2016-04-26 09:09 . http-hello close connection when http/1.0
#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;
}
C++
1
https://gitee.com/xystar2012/handy.git
git@gitee.com:xystar2012/handy.git
xystar2012
handy
handy
master

搜索帮助