mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Changed examples to use the generic lambda.
This commit is contained in:
parent
98e3e7b3c1
commit
34e5903167
4 changed files with 12 additions and 12 deletions
|
@ -3,10 +3,10 @@ USE_CLANG = 1
|
||||||
|
|
||||||
ifdef USE_CLANG
|
ifdef USE_CLANG
|
||||||
CC = clang++
|
CC = clang++
|
||||||
CFLAGS = -std=c++0x -stdlib=libc++ -g
|
CFLAGS = -std=c++1y -stdlib=libc++ -g
|
||||||
else
|
else
|
||||||
CC = g++
|
CC = g++-4.9
|
||||||
CFLAGS = -std=c++11 -g
|
CFLAGS = -std=c++1y -g
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: server client hello simplesvr
|
all: server client hello simplesvr
|
||||||
|
|
|
@ -12,7 +12,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
Server svr;
|
Server svr;
|
||||||
|
|
||||||
svr.get("/hi", [](const Request& req, Response& res) {
|
svr.get("/hi", [](const auto& req, auto& res) {
|
||||||
res.set_content("Hello World!", "text/plain");
|
res.set_content("Hello World!", "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -65,30 +65,30 @@ int main(void)
|
||||||
{
|
{
|
||||||
Server svr;
|
Server svr;
|
||||||
|
|
||||||
svr.get("/", [=](const Request& req, Response& res) {
|
svr.get("/", [=](const auto& req, auto& res) {
|
||||||
res.set_redirect("/hi");
|
res.set_redirect("/hi");
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.get("/hi", [](const Request& req, Response& res) {
|
svr.get("/hi", [](const auto& req, auto& res) {
|
||||||
res.set_content("Hello World!", "text/plain");
|
res.set_content("Hello World!", "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.get("/dump", [](const Request& req, Response& res) {
|
svr.get("/dump", [](const auto& req, auto& res) {
|
||||||
res.set_content(dump_headers(req.headers), "text/plain");
|
res.set_content(dump_headers(req.headers), "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.get("/stop", [&](const Request& req, Response& res) {
|
svr.get("/stop", [&](const auto& req, auto& res) {
|
||||||
svr.stop();
|
svr.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.set_error_handler([](const Request& req, Response& res) {
|
svr.set_error_handler([](const auto& req, auto& res) {
|
||||||
const char* fmt = "<p>Error Status: <span style='color:red;'>%d</span></p>";
|
const char* fmt = "<p>Error Status: <span style='color:red;'>%d</span></p>";
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
snprintf(buf, sizeof(buf), fmt, res.status);
|
snprintf(buf, sizeof(buf), fmt, res.status);
|
||||||
res.set_content(buf, "text/html");
|
res.set_content(buf, "text/html");
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.set_logger([](const Request& req, const Response& res) {
|
svr.set_logger([](const auto& req, const auto& res) {
|
||||||
printf("%s", log(req, res).c_str());
|
printf("%s", log(req, res).c_str());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -65,14 +65,14 @@ int main(int argc, const char** argv)
|
||||||
|
|
||||||
Server svr;
|
Server svr;
|
||||||
|
|
||||||
svr.set_error_handler([](const Request& req, Response& res) {
|
svr.set_error_handler([](const auto& req, auto& res) {
|
||||||
const char* fmt = "<p>Error Status: <span style='color:red;'>%d</span></p>";
|
const char* fmt = "<p>Error Status: <span style='color:red;'>%d</span></p>";
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
snprintf(buf, sizeof(buf), fmt, res.status);
|
snprintf(buf, sizeof(buf), fmt, res.status);
|
||||||
res.set_content(buf, "text/html");
|
res.set_content(buf, "text/html");
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.set_logger([](const Request& req, const Response& res) {
|
svr.set_logger([](const auto& req, const auto& res) {
|
||||||
cout << log(req, res);
|
cout << log(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue