diff --git a/http_examples.cpp b/http_examples.cpp index 26ff6eb6..a099370e 100644 --- a/http_examples.cpp +++ b/http_examples.cpp @@ -89,13 +89,13 @@ int main() { //GET-example for the path /match/[number], responds with the matched string in path (number) //For instance a request GET /match/123 will receive: 123 - server.resource["^/match/([0-9]+)$"]["GET"]=[&server](shared_ptr response, shared_ptr request) { + server.resource["^/match/([0-9]+)$"]["GET"]=[](shared_ptr response, shared_ptr request) { string number=request->path_match[1]; *response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number; }; //Get example simulating heavy work in a separate thread - server.resource["^/work$"]["GET"]=[&server](shared_ptr response, shared_ptr /*request*/) { + server.resource["^/work$"]["GET"]=[](shared_ptr response, shared_ptr /*request*/) { thread work_thread([response] { this_thread::sleep_for(chrono::seconds(5)); string message="Work done"; diff --git a/https_examples.cpp b/https_examples.cpp index 88621709..3dff0c9f 100644 --- a/https_examples.cpp +++ b/https_examples.cpp @@ -87,13 +87,13 @@ int main() { //GET-example for the path /match/[number], responds with the matched string in path (number) //For instance a request GET /match/123 will receive: 123 - server.resource["^/match/([0-9]+)$"]["GET"]=[&server](shared_ptr response, shared_ptr request) { + server.resource["^/match/([0-9]+)$"]["GET"]=[](shared_ptr response, shared_ptr request) { string number=request->path_match[1]; *response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number; }; //Get example simulating heavy work in a separate thread - server.resource["^/work$"]["GET"]=[&server](shared_ptr response, shared_ptr /*request*/) { + server.resource["^/work$"]["GET"]=[](shared_ptr response, shared_ptr /*request*/) { thread work_thread([response] { this_thread::sleep_for(chrono::seconds(5)); string message="Work done"; diff --git a/server_http.hpp b/server_http.hpp index 967486d6..ff0c44e5 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -217,7 +217,8 @@ namespace SimpleWeb { ///Use this function if you need to recursively send parts of a longer message void send(const std::shared_ptr &response, const std::function& callback=nullptr) const { - boost::asio::async_write(*response->socket, response->streambuf, [this, response, callback](const boost::system::error_code& ec, size_t /*bytes_transferred*/) { + boost::asio::async_write(*response->socket, response->streambuf, [response, callback](const boost::system::error_code& ec, size_t /*bytes_transferred*/) { + (void) response; // response is not used here, but needs to captured to keep it alive because async_write is using response->*-fields if(callback) callback(ec); }); diff --git a/tests/io_test.cpp b/tests/io_test.cpp index db999cc7..9ce7963b 100644 --- a/tests/io_test.cpp +++ b/tests/io_test.cpp @@ -28,7 +28,8 @@ int main() { *response << "HTTP/1.1 200 OK\r\nContent-Length: " << content_stream.tellp() << "\r\n\r\n" << content_stream.rdbuf(); }; - server.resource["^/match/([0-9]+)$"]["GET"]=[&server](shared_ptr response, shared_ptr request) { + + server.resource["^/match/([0-9]+)$"]["GET"]=[](shared_ptr response, shared_ptr request) { string number=request->path_match[1]; *response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number; };