Access to HTTP request bodies references #181

Use connection::get_request_body() to access. Use
endpoint::set_max_http_body_size(size_t value) to control maximum
upload size. Initial support is for single chunk bodies that define a
content-length . Transfer-Encoding: chunked is not currently supported
This commit is contained in:
Peter Thorson
2014-11-18 22:05:46 -05:00
parent 12700f2bc2
commit f6c6552622
10 changed files with 154 additions and 5 deletions
+13
View File
@@ -44,6 +44,17 @@ using websocketpp::lib::bind;
// pull out the type of messages sent by our config
typedef server::message_ptr message_ptr;
void on_http(server* s, websocketpp::connection_hdl hdl) {
server::connection_ptr con = s->get_con_from_hdl(hdl);
std::string res = con->get_request_body();
std::cout << "got HTTP request with " << res.size() << " bytes of body data." << std::endl;
con->set_body(res);
con->set_status(websocketpp::http::status_code::ok);
}
// Define a callback to handle incoming messages
void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
std::cout << "on_message called with hdl: " << hdl.lock().get()
@@ -73,6 +84,8 @@ int main() {
// Register our message handler
echo_server.set_message_handler(bind(&on_message,&echo_server,::_1,::_2));
echo_server.set_http_handler(bind(&on_http,&echo_server,::_1));
// Listen on port 9012
echo_server.listen(9012);