diff --git a/main_http.cpp b/main_http.cpp index 68418a3..da718a4 100644 --- a/main_http.cpp +++ b/main_http.cpp @@ -13,11 +13,11 @@ using namespace boost::property_tree; int main() { //HTTP-server at port 8080 using 4 threads - Server httpserver(8080, 4); + Server server(8080, 4); //Add resources using regular expression for path, a method-string, and an anonymous function //POST-example for the path /string, responds the posted string - httpserver.resources["^/string/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) { + server.resources["^/string/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) { //Retrieve string from istream (*request.content) stringstream ss; *request.content >> ss.rdbuf(); @@ -34,7 +34,7 @@ int main() { // "lastName": "Smith", // "age": 25 //} - httpserver.resources["^/json/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) { + server.resources["^/json/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) { try { ptree pt; read_json(*request.content, pt); @@ -50,7 +50,7 @@ int main() { //GET-example for the path /info //Responds with request-information - httpserver.resources["^/info/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { + server.resources["^/info/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { stringstream content_stream; content_stream << "

Request:

"; content_stream << request.method << " " << request.path << " HTTP/" << request.http_version << "
"; @@ -66,7 +66,7 @@ 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 - httpserver.resources["^/match/([0-9]+)/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { + server.resources["^/match/([0-9]+)/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { string number=path_match[1]; response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number; }; @@ -75,7 +75,7 @@ int main() { //Will respond with content in the web/-directory, and its subdirectories. //Default file: index.html //Can for instance be used to retrieve an HTML 5 client that uses REST-resources on this server - httpserver.default_resource["^/?(.*)$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { + server.default_resource["^/?(.*)$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { string filename="web/"; string path=path_match[1]; @@ -119,7 +119,7 @@ int main() { }; //Start HTTP-server - httpserver.start(); + server.start(); return 0; } diff --git a/main_https.cpp b/main_https.cpp index 6c6787e..139429e 100644 --- a/main_https.cpp +++ b/main_https.cpp @@ -13,11 +13,11 @@ using namespace boost::property_tree; int main() { //HTTPS-server at port 8080 using 4 threads - Server httpserver(8080, 4, "server.crt", "server.key"); + Server server(8080, 4, "server.crt", "server.key"); //Add resources using regular expression for path, a method-string, and an anonymous function //POST-example for the path /string, responds the posted string - httpserver.resources["^/string/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) { + server.resources["^/string/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) { //Retrieve string from istream (*request.content) stringstream ss; *request.content >> ss.rdbuf(); @@ -34,7 +34,7 @@ int main() { // "lastName": "Smith", // "age": 25 //} - httpserver.resources["^/json/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) { + server.resources["^/json/?$"]["POST"]=[](ostream& response, const Request& request, const smatch& path_match) { try { ptree pt; read_json(*request.content, pt); @@ -50,7 +50,7 @@ int main() { //GET-example for the path /info //Responds with request-information - httpserver.resources["^/info/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { + server.resources["^/info/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { stringstream content_stream; content_stream << "

Request:

"; content_stream << request.method << " " << request.path << " HTTP/" << request.http_version << "
"; @@ -66,7 +66,7 @@ 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 - httpserver.resources["^/match/([0-9]+)/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { + server.resources["^/match/([0-9]+)/?$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { string number=path_match[1]; response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number; }; @@ -75,7 +75,7 @@ int main() { //Will respond with content in the web/-directory, and its subdirectories. //Default file: index.html //Can for instance be used to retrieve an HTML 5 client that uses REST-resources on this server - httpserver.default_resource["^/?(.*)$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { + server.default_resource["^/?(.*)$"]["GET"]=[](ostream& response, const Request& request, const smatch& path_match) { string filename="web/"; string path=path_match[1]; @@ -119,7 +119,7 @@ int main() { }; //Start HTTP-server - httpserver.start(); + server.start(); return 0; }