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;
138 , c(p_is_server,
"", alog, elog, rng) {}
140 websocketpp::lib::error_code
ec;
141 websocketpp::lib::shared_ptr<stub_config::alog_type>
alog;
142 websocketpp::lib::shared_ptr<stub_config::elog_type>
elog;
155 s->
send(hdl, msg->get_payload(), msg->get_opcode());
160 con->replace_header(
"Server",
"foo");
169 std::string res = con->get_resource();
183 websocketpp::lib::error_code ec = con->defer_http_response();
184 BOOST_CHECK_EQUAL(ec, websocketpp::lib::error_code());
192 BOOST_CHECK_EQUAL(ec, con->get_ec());
200 std::cout << con->get_uri() << std::endl;
213 BOOST_CHECK( env.
c.extension_value == 5 );
214 BOOST_CHECK( env.
c.extension_method() == 5 );
220 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";
221 std::string output =
"HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\nServer: ";
223 output+=
"\r\nUpgrade: websocket\r\n\r\n";
232 std::string input =
"GET /foo/bar HTTP/1.1\r\nHost: www.example.com\r\nOrigin: http://www.example.com\r\n\r\n";
233 std::string output =
"HTTP/1.1 200 OK\r\nContent-Length: 8\r\nServer: ";
235 output+=
"\r\n\r\n/foo/bar";
244 std::string input =
"GET /foo/bar HTTP/1.1\r\nHost: www.example.com\r\nOrigin: http://www.example.com\r\n\r\n";
245 std::string output =
"HTTP/1.1 200 OK\r\nContent-Length: 8\r\nServer: ";
247 output+=
"\r\n\r\n/foo/bar";
257 std::stringstream ostream;
258 s.register_ostream(&ostream);
263 BOOST_CHECK(!deferred);
264 BOOST_CHECK_EQUAL(ostream.str(),
"");
265 con->read_some(input.data(),input.size());
266 BOOST_CHECK(deferred);
267 BOOST_CHECK_EQUAL(ostream.str(),
"");
269 con->set_body(con->get_resource());
272 websocketpp::lib::error_code ec;
274 BOOST_CHECK_EQUAL(ec, websocketpp::lib::error_code());
275 BOOST_CHECK_EQUAL(ostream.str(), output);
276 con->send_http_response(ec);
282 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";
283 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";
293 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";
294 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";
305 std::string uri =
"ws://localhost";
309 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";
311 std::stringstream output;
317 e.register_ostream(&output);
320 websocketpp::lib::error_code ec;
322 con->append_header(
"Foo",
"Bar");
325 BOOST_CHECK_EQUAL(ref, output.str());
329 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";
332 char frame0[10] = {char(0x82), char(0x83), 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01};
333 input.append(frame0, 10);
335 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";
339 char frame1[4] = {char(0x88), 0x19, 0x03, char(0xf1)};
340 output.append(frame1, 4);
341 output.append(
"A message was too large");
352 std::string input =
"asdf\r\n\r\n";
364 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";
376 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";
414 std::string input =
"GET /foo/bar HTTP/1.1\r\nHost: www.example.com\r\nOrigin: http://www.example.com\r\n\r\n";
457 websocketpp::lib::error_code ec;
468 con->expire_timer(websocketpp::lib::error_code());
471 con->fullfil_write();
479 websocketpp::lib::error_code ec;
484 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";
491 con->fullfil_write();
493 con->expire_timer(websocketpp::lib::error_code());
496 con->read_all(output.data(),output.size());
504 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";
509 con->expire_timer(websocketpp::lib::error_code());
511 con->read_all(input.data(), input.size());
519 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";
524 con->read_all(input.data(), input.size());
526 con->expire_timer(websocketpp::lib::error_code());
528 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".
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.
bool is_server() const
Get whether or not this connection is part of a server or client.
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.
Namespace for the WebSocket++ project.
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)
websocketpp::lib::shared_ptr< stub_config::alog_type > alog
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.
core::request_type request_type
void clear_access_channels(log::level channels)
Clear Access logging channels.
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.
websocketpp::lib::shared_ptr< stub_config::elog_type > elog
connection_setup(bool p_is_server)