Added heavy work example

This commit is contained in:
eidheim 2016-06-29 10:10:34 +02:00
commit 0b397bc697
4 changed files with 24 additions and 1 deletions

View file

@ -87,6 +87,17 @@ int main() {
*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<HttpsServer::Response> response, shared_ptr<HttpsServer::Request> /*request*/) {
*response << "HTTP/1.1 200 OK\r\n";
thread work_thread([response] {
this_thread::sleep_for(chrono::seconds(5));
string message="Work done";
*response << "Content-Length: " << message.length() << "\r\n\r\n" << message;
});
work_thread.detach();
};
//Default GET-example. If no other matches, this anonymous function will be called.
//Will respond with content in the web/-directory, and its subdirectories.
//Default file: index.html