minor changes
This commit is contained in:
parent
8e52412a2e
commit
b8c3556ded
2 changed files with 14 additions and 14 deletions
|
|
@ -13,11 +13,11 @@ using namespace boost::property_tree;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
//HTTP-server at port 8080 using 4 threads
|
//HTTP-server at port 8080 using 4 threads
|
||||||
Server<HTTP> httpserver(8080, 4);
|
Server<HTTP> server(8080, 4);
|
||||||
|
|
||||||
//Add resources using regular expression for path, a method-string, and an anonymous function
|
//Add resources using regular expression for path, a method-string, and an anonymous function
|
||||||
//POST-example for the path /string, responds the posted string
|
//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)
|
//Retrieve string from istream (*request.content)
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
*request.content >> ss.rdbuf();
|
*request.content >> ss.rdbuf();
|
||||||
|
|
@ -34,7 +34,7 @@ int main() {
|
||||||
// "lastName": "Smith",
|
// "lastName": "Smith",
|
||||||
// "age": 25
|
// "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 {
|
try {
|
||||||
ptree pt;
|
ptree pt;
|
||||||
read_json(*request.content, pt);
|
read_json(*request.content, pt);
|
||||||
|
|
@ -50,7 +50,7 @@ int main() {
|
||||||
|
|
||||||
//GET-example for the path /info
|
//GET-example for the path /info
|
||||||
//Responds with request-information
|
//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;
|
stringstream content_stream;
|
||||||
content_stream << "<h1>Request:</h1>";
|
content_stream << "<h1>Request:</h1>";
|
||||||
content_stream << request.method << " " << request.path << " HTTP/" << request.http_version << "<br>";
|
content_stream << request.method << " " << request.path << " HTTP/" << request.http_version << "<br>";
|
||||||
|
|
@ -66,7 +66,7 @@ int main() {
|
||||||
|
|
||||||
//GET-example for the path /match/[number], responds with the matched string in path (number)
|
//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
|
//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];
|
string number=path_match[1];
|
||||||
response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number;
|
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.
|
//Will respond with content in the web/-directory, and its subdirectories.
|
||||||
//Default file: index.html
|
//Default file: index.html
|
||||||
//Can for instance be used to retrieve an HTML 5 client that uses REST-resources on this server
|
//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 filename="web/";
|
||||||
|
|
||||||
string path=path_match[1];
|
string path=path_match[1];
|
||||||
|
|
@ -119,7 +119,7 @@ int main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
//Start HTTP-server
|
//Start HTTP-server
|
||||||
httpserver.start();
|
server.start();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@ using namespace boost::property_tree;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
//HTTPS-server at port 8080 using 4 threads
|
//HTTPS-server at port 8080 using 4 threads
|
||||||
Server<HTTPS> httpserver(8080, 4, "server.crt", "server.key");
|
Server<HTTPS> server(8080, 4, "server.crt", "server.key");
|
||||||
|
|
||||||
//Add resources using regular expression for path, a method-string, and an anonymous function
|
//Add resources using regular expression for path, a method-string, and an anonymous function
|
||||||
//POST-example for the path /string, responds the posted string
|
//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)
|
//Retrieve string from istream (*request.content)
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
*request.content >> ss.rdbuf();
|
*request.content >> ss.rdbuf();
|
||||||
|
|
@ -34,7 +34,7 @@ int main() {
|
||||||
// "lastName": "Smith",
|
// "lastName": "Smith",
|
||||||
// "age": 25
|
// "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 {
|
try {
|
||||||
ptree pt;
|
ptree pt;
|
||||||
read_json(*request.content, pt);
|
read_json(*request.content, pt);
|
||||||
|
|
@ -50,7 +50,7 @@ int main() {
|
||||||
|
|
||||||
//GET-example for the path /info
|
//GET-example for the path /info
|
||||||
//Responds with request-information
|
//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;
|
stringstream content_stream;
|
||||||
content_stream << "<h1>Request:</h1>";
|
content_stream << "<h1>Request:</h1>";
|
||||||
content_stream << request.method << " " << request.path << " HTTP/" << request.http_version << "<br>";
|
content_stream << request.method << " " << request.path << " HTTP/" << request.http_version << "<br>";
|
||||||
|
|
@ -66,7 +66,7 @@ int main() {
|
||||||
|
|
||||||
//GET-example for the path /match/[number], responds with the matched string in path (number)
|
//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
|
//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];
|
string number=path_match[1];
|
||||||
response << "HTTP/1.1 200 OK\r\nContent-Length: " << number.length() << "\r\n\r\n" << number;
|
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.
|
//Will respond with content in the web/-directory, and its subdirectories.
|
||||||
//Default file: index.html
|
//Default file: index.html
|
||||||
//Can for instance be used to retrieve an HTML 5 client that uses REST-resources on this server
|
//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 filename="web/";
|
||||||
|
|
||||||
string path=path_match[1];
|
string path=path_match[1];
|
||||||
|
|
@ -119,7 +119,7 @@ int main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
//Start HTTP-server
|
//Start HTTP-server
|
||||||
httpserver.start();
|
server.start();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue