28 #define BOOST_TEST_MODULE connection 29 #include <boost/test/unit_test.hpp> 42 std::string input =
"GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
43 std::string output =
"HTTP/1.1 426 Upgrade Required\r\nServer: " +
48 BOOST_CHECK(o2 == output);
113 static bool const enable_multithreading =
true;
116 static const long timeout_socket_pre_init = 5000;
117 static const long timeout_proxy = 5000;
118 static const long timeout_socket_post_init = 5000;
119 static const long timeout_connect = 5000;
120 static const long timeout_socket_shutdown = 5000;
137 websocketpp::lib::error_code
ec;
152 s->
send(hdl, msg->get_payload(), msg->get_opcode());
157 con->replace_header(
"Server",
"foo");
166 std::string res = con->get_resource();
180 websocketpp::lib::error_code ec = con->defer_http_response();
181 BOOST_CHECK_EQUAL(ec, websocketpp::lib::error_code());
189 BOOST_CHECK_EQUAL(ec, con->get_ec());
197 std::cout << con->get_uri() << std::endl;
217 std::string input =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
218 std::string output =
"HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: ";
220 output+=
"\r\nUpgrade: websocket\r\n\r\n";
229 std::string input =
"GET /foo/bar HTTP/1.1\r\nHost: www.example.com\r\nOrigin: http://www.example.com\r\n\r\n";
230 std::string output =
"HTTP/1.1 200 OK\r\nContent-Length: 8\r\nServer: ";
232 output+=
"\r\n\r\n/foo/bar";
241 std::string input =
"GET /foo/bar HTTP/1.1\r\nHost: www.example.com\r\nOrigin: http://www.example.com\r\n\r\n";
242 std::string output =
"HTTP/1.1 200 OK\r\nContent-Length: 8\r\nServer: ";
244 output+=
"\r\n\r\n/foo/bar";
254 std::stringstream ostream;
255 s.register_ostream(&ostream);
260 BOOST_CHECK(!deferred);
261 BOOST_CHECK_EQUAL(ostream.str(),
"");
262 con->read_some(input.data(),input.size());
263 BOOST_CHECK(deferred);
264 BOOST_CHECK_EQUAL(ostream.str(),
"");
266 con->set_body(con->get_resource());
269 websocketpp::lib::error_code ec;
271 BOOST_CHECK_EQUAL(ec, websocketpp::lib::error_code());
272 BOOST_CHECK_EQUAL(ostream.str(), output);
273 con->send_http_response(ec);
279 std::string input =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
280 std::string output =
"HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nUpgrade: websocket\r\n\r\n";
290 std::string input =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
291 std::string output =
"HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: foo\r\nUpgrade: websocket\r\n\r\n";
302 std::string uri =
"ws://localhost";
306 std::string ref =
"GET / HTTP/1.1\r\nConnection: Upgrade\r\nFoo: Bar\r\nHost: localhost\r\nSec-WebSocket-Key: AAAAAAAAAAAAAAAAAAAAAA==\r\nSec-WebSocket-Version: 13\r\nUpgrade: websocket\r\nUser-Agent: foo\r\n\r\n";
308 std::stringstream output;
314 e.register_ostream(&output);
317 websocketpp::lib::error_code ec;
319 con->append_header(
"Foo",
"Bar");
322 BOOST_CHECK_EQUAL(ref, output.str());
326 std::string input =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n";
329 char frame0[10] = {char(0x82), char(0x83), 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01};
330 input.append(frame0, 10);
332 std::string output =
"HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: foo\r\nUpgrade: websocket\r\n\r\n";
336 char frame1[4] = {char(0x88), 0x19, 0x03, char(0xf1)};
337 output.append(frame1, 4);
338 output.append(
"A message was too large");
349 std::string input =
"asdf\r\n\r\n";
361 std::string input =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: foo\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
373 std::string input =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 12\r\nSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\nOrigin: http://www.example.com\r\n\r\n";
411 std::string input =
"GET /foo/bar HTTP/1.1\r\nHost: www.example.com\r\nOrigin: http://www.example.com\r\n\r\n";
454 websocketpp::lib::error_code ec;
465 con->expire_timer(websocketpp::lib::error_code());
468 con->fullfil_write();
476 websocketpp::lib::error_code ec;
481 std::string output =
"HTTP/1.1 101 Switching Protocols\r\nConnection: upgrade\r\nSec-WebSocket-Accept: ICX+Yqv66kxgM0FcWaLWlFLwTAI=\r\nServer: foo\r\nUpgrade: websocket\r\n\r\n";
488 con->fullfil_write();
490 con->expire_timer(websocketpp::lib::error_code());
493 con->read_all(output.data(),output.size());
501 std::string input =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: AAAAAAAAAAAAAAAAAAAAAA==\r\n\r\n";
506 con->expire_timer(websocketpp::lib::error_code());
508 con->read_all(input.data(), input.size());
516 std::string input =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: AAAAAAAAAAAAAAAAAAAAAA==\r\n\r\n";
521 con->read_all(input.data(), input.size());
523 con->expire_timer(websocketpp::lib::error_code());
525 con->fullfil_write();
void send_http_response(connection_hdl hdl, lib::error_code &ec)
Send deferred HTTP Response.
static level const all
Special aggregate value representing "all levels".
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
void fail_on_http(websocketpp::connection_hdl)
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
static level const none
Special aggregate value representing "no levels".
type::request_type request_type
lib::error_code make_error_code(error::value e)
void fail_on_open(websocketpp::connection_hdl)
connection_extension connection_base
core::concurrency_type concurrency_type
core::con_msg_manager_type con_msg_manager_type
stub_config::rng_type rng
std::string run_server_test(std::string input, bool log)
core::message_type message_type
core::elog_type elog_type
type::response_type response_type
void http_func(server *s, websocketpp::connection_hdl hdl)
core::endpoint_base endpoint_base
core::transport_type transport_type
type::concurrency_type concurrency_type
void validate_func(server *s, websocketpp::connection_hdl hdl, message_ptr msg)
websocketpp::server< debug_config_client > debug_server
Client endpoint role based on the given config.
core::request_type request_type
websocketpp::client< debug_config_client > debug_client
stub_config::con_msg_manager_type con_msg_manager_type
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
websocketpp::lib::error_code ec
static char const user_agent[]
Default user agent string.
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
connection_ptr connect(connection_ptr con)
Begin the connection process for the given connection.
void on_open_print(server *s, websocketpp::connection_hdl hdl)
bool validate_set_ua(server *s, websocketpp::connection_hdl hdl)
core::elog_type elog_type
connection_extension connection_base
core::con_msg_manager_type con_msg_manager_type
core::alog_type alog_type
type::elog_type elog_type
core::endpoint_msg_manager_type endpoint_msg_manager_type
static level const none
Special aggregate value representing "no levels".
bool is_server() const
Get whether or not this connection is part of a server or client.
core::endpoint_base endpoint_base
void set_max_message_size(size_t new_value)
Set default maximum message size.
Invalid WebSocket protocol version.
The connection was in the wrong state for this operation.
Server endpoint role based on the given config.
Thread safe stub "random" integer generator.
void clear_error_channels(log::level channels)
Clear Error logging channels.
websocketpp::random::none::int_generator< uint32_t > rng_type
void set_access_channels(log::level channels)
Set Access logging channel.
void set_http_handler(http_handler h)
core::alog_type alog_type
websocketpp::transport::debug::endpoint< transport_config > transport_type
Transport Endpoint Component.
void defer_http_func(server *s, bool *deferred, websocketpp::connection_hdl hdl)
void set_validate_handler(validate_handler h)
void set_fail_handler(fail_handler h)
core::concurrency_type concurrency_type
core::response_type response_type
type::alog_type alog_type
connection_ptr get_connection()
Create and initialize a new connection.
std::string get_string(value code)
Return a human readable interpretation of a WebSocket close code.
stub_config::elog_type elog
core::request_type request_type
void clear_access_channels(log::level channels)
Clear Access logging channels.
stub_config::alog_type alog
core::message_type message_type
void set_error_channels(log::level channels)
Set Error logging channel.
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
BOOST_AUTO_TEST_CASE(basic_http_request)
core::endpoint_msg_manager_type endpoint_msg_manager_type
void check_on_fail(server *s, websocketpp::lib::error_code ec, bool &called, websocketpp::connection_hdl hdl)
core::response_type response_type
void set_user_agent(std::string const &ua)
Sets the user agent string that this endpoint will use.
void echo_func(server *s, websocketpp::connection_hdl hdl, message_ptr msg)
WebSocket opening handshake timed out.
uint32_t level
Type of a channel package.
void set_message_handler(message_handler h)
websocketpp::connection< stub_config > c
static level const all
Special aggregate value representing "all levels".
void send(connection_hdl hdl, std::string const &payload, frame::opcode::value op, lib::error_code &ec)
Create a message and add it to the outgoing send queue (exception free)
connection_ptr get_connection(uri_ptr location, lib::error_code &ec)
Get a new connection.
Server config with iostream transport.
Unsupported WebSocket protocol version.
connection_setup(bool p_is_server)