diff --git a/test/connection/connection.cpp b/test/connection/connection.cpp index 5cbcea6ca8..38b147da9d 100644 --- a/test/connection/connection.cpp +++ b/test/connection/connection.cpp @@ -100,7 +100,14 @@ void validate_func(server* s, websocketpp::connection_hdl hdl, message_ptr msg) s->send(hdl, msg->get_payload(), msg->get_opcode()); } - +void http_func(server* s, websocketpp::connection_hdl hdl) { + server::connection_ptr con = s->get_con_from_hdl(hdl); + + std::string res = con->get_resource(); + + con->set_body(res); + con->set_status(websocketpp::http::status_code::ok); +} BOOST_AUTO_TEST_CASE( connection_extensions ) { connection_setup env(true); @@ -123,6 +130,18 @@ BOOST_AUTO_TEST_CASE( basic_websocket_request ) { BOOST_CHECK(run_server_test(s,input) == output); } +BOOST_AUTO_TEST_CASE( http_request ) { + std::string input = "GET /foo/bar HTTP/1.1\r\nHost: www.example.com\r\nOrigin: http://www.example.com\r\n\r\n"; + std::string output = "HTTP/1.1 200 OK\r\nContent-Length: 8\r\nServer: "; + output+=websocketpp::user_agent; + output+="\r\n\r\n/foo/bar"; + + server s; + s.set_http_handler(bind(&http_func,&s,::_1)); + + BOOST_CHECK_EQUAL(run_server_test(s,input), output); +} + /* BOOST_AUTO_TEST_CASE( user_reject_origin ) { diff --git a/test/connection/connection_tu2.cpp b/test/connection/connection_tu2.cpp index 9abd009afd..bbbc0287ec 100644 --- a/test/connection/connection_tu2.cpp +++ b/test/connection/connection_tu2.cpp @@ -33,24 +33,7 @@ void echo_func(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { std::string run_server_test(std::string input) { server test_server; - server::connection_ptr con; - - test_server.set_message_handler(bind(&echo_func,&test_server,::_1,::_2)); - - std::stringstream output; - - test_server.register_ostream(&output); - - con = test_server.get_connection(); - - con->start(); - - std::stringstream channel; - - channel << input; - channel >> *con; - - return output.str(); + return run_server_test(test_server,input); } std::string run_server_test(server& s, std::string input) {