Skip to content

Commit

Permalink
Refactor the examples to compile with a C++11 compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Aug 17, 2018
1 parent 48b47ef commit 4af5b1e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion example/hello.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main(void)
{
Server svr;

svr.Get("/hi", [](const auto& /*req*/, auto& res) {
svr.Get("/hi", [](const Request& /*req*/, Response& res) {
res.set_content("Hello World!", "text/plain");
});

Expand Down
17 changes: 8 additions & 9 deletions example/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,35 @@ int main(void)
return -1;
}

svr.Get("/", [=](const auto& /*req*/, auto& res) {
svr.Get("/", [=](const Request& /*req*/, Response& res) {
res.set_redirect("/hi");
});

svr.Get("/hi", [](const auto& /*req*/, auto& res) {
svr.Get("/hi", [](const Request& /*req*/, Response& res) {
res.set_content("Hello World!\n", "text/plain");
});

svr.Get("/slow", [](const auto& /*req*/, auto& res) {
using namespace std::chrono_literals;
std::this_thread::sleep_for(2s);
svr.Get("/slow", [](const Request& /*req*/, Response& res) {
std::this_thread::sleep_for(std::chrono::seconds(2));
res.set_content("Slow...\n", "text/plain");
});

svr.Get("/dump", [](const auto& req, auto& res) {
svr.Get("/dump", [](const Request& req, Response& res) {
res.set_content(dump_headers(req.headers), "text/plain");
});

svr.Get("/stop", [&](const auto& /*req*/, auto& /*res*/) {
svr.Get("/stop", [&](const Request& /*req*/, Response& res) {
svr.stop();
});

svr.set_error_handler([](const auto& /*req*/, auto& res) {
svr.set_error_handler([](const Request& /*req*/, Response& res) {
const char* fmt = "<p>Error Status: <span style='color:red;'>%d</span></p>";
char buf[BUFSIZ];
snprintf(buf, sizeof(buf), fmt, res.status);
res.set_content(buf, "text/html");
});

svr.set_logger([](const auto& req, const auto& res) {
svr.set_logger([](const Request& req, const Response& res) {
printf("%s", log(req, res).c_str());
});

Expand Down
6 changes: 3 additions & 3 deletions example/simplesvr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@ int main(int argc, const char** argv)
Server svr;
#endif

svr.Post("/multipart", [](const auto& req, auto& res) {
svr.Post("/multipart", [](const Request& req, Response& res) {
auto body =
dump_headers(req.headers) +
dump_multipart_files(req.files);

res.set_content(body, "text/plain");
});

svr.set_error_handler([](const auto& /*req*/, auto& res) {
svr.set_error_handler([](const Request& /*req*/, Response& res) {
const char* fmt = "<p>Error Status: <span style='color:red;'>%d</span></p>";
char buf[BUFSIZ];
snprintf(buf, sizeof(buf), fmt, res.status);
res.set_content(buf, "text/html");
});

svr.set_logger([](const auto& req, const auto& res) {
svr.set_logger([](const Request& req, const Response& res) {
cout << log(req, res);
});

Expand Down

0 comments on commit 4af5b1e

Please sign in to comment.