From ace3bb6caf788f8919fd1ff75102ecd9779720b9 Mon Sep 17 00:00:00 2001 From: yhirose Date: Tue, 25 Sep 2012 22:55:51 -0400 Subject: [PATCH] Fixed variable capture problem. --- example/sample.cc | 6 ++++++ httpsvrkit.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/example/sample.cc b/example/sample.cc index 039ccb2..2735e79 100644 --- a/example/sample.cc +++ b/example/sample.cc @@ -47,6 +47,8 @@ std::string dump_request(Context& cxt) int main(void) { if (true) { + const char* s = "abcde"; + // DSL style HTTP_SERVER("localhost", 1234) { @@ -57,6 +59,10 @@ int main(void) GET("/home", { res.set_content(dump_request(cxt)); }); + + GET("/abcde", { + res.set_content(s); + }); } } else { // Regular style diff --git a/httpsvrkit.h b/httpsvrkit.h index 9e53a6d..63deb0d 100644 --- a/httpsvrkit.h +++ b/httpsvrkit.h @@ -416,7 +416,7 @@ inline void Server::process_request(FILE* fp_read, FILE* fp_write) svr->run(), svr.reset()) #define GET(url, body) \ - svr->get(url, [](httpsvrkit::Context& cxt) { \ + svr->get(url, [&](httpsvrkit::Context& cxt) { \ const auto& req = cxt.request; \ auto& res = cxt.response; \ body \