Slight cleanup and added convenience function to retrieve Request::content string.

This commit is contained in:
eidheim 2015-09-19 13:01:40 +02:00
commit 7951ded3ec
3 changed files with 31 additions and 15 deletions

View file

@ -24,10 +24,12 @@ int main() {
//Add resources using path-regex and method-string, and an anonymous function
//POST-example for the path /string, responds the posted string
server.resource["^/string$"]["POST"]=[](HttpServer::Response& response, shared_ptr<HttpServer::Request> request) {
//Retrieve string from istream (request->content)
stringstream ss;
ss << request->content.rdbuf();
string content=ss.str();
//Retrieve string:
auto content=request->content.string();
//request->content.string() is a convenience function for:
//stringstream ss;
//ss << request->content.rdbuf();
//string content=ss.str();
response << "HTTP/1.1 200 OK\r\nContent-Length: " << content.length() << "\r\n\r\n" << content;
};