adds more unit tests for http requests

This commit is contained in:
Peter Thorson
2013-05-18 06:56:49 -05:00
parent d7e5235036
commit 8f8bbb99e9
2 changed files with 21 additions and 19 deletions

View File

@@ -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 ) {

View File

@@ -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) {