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: " +
44 std::string(websocketpp::user_agent)+
"\r\n\r\n";
48 BOOST_CHECK(o2 == output);
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();
169 con->set_status(status_code::ok);
171 BOOST_CHECK_EQUAL(con->get_response_code(), status_code::ok);
172 BOOST_CHECK_EQUAL(con->get_response_msg(), status_code::get_string(status_code::ok));
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: ";
219 output+=websocketpp::user_agent;
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: ";
231 output+=websocketpp::user_agent;
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: ";
243 output+=websocketpp::user_agent;
244 output+=
"\r\n\r\n/foo/bar";
248 bool deferred =
false;
254 std::stringstream ostream;
255 s.register_ostream(&ostream);
257 con =
s.get_connection();
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;
270 s.send_http_response(con->get_handle(),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";
284 s.set_message_handler(bind(&
echo_func,&
s,::_1,::_2));
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";
295 s.set_message_handler(bind(&
echo_func,&
s,::_1,::_2));
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");
343 s.set_max_message_size(2);
349 std::string input =
"asdf\r\n\r\n";
354 s.set_fail_handler(bind(&
check_on_fail,&
s,ec,websocketpp::lib::ref(called),::_1));
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";
366 s.set_fail_handler(bind(&
check_on_fail,&
s,ec,websocketpp::lib::ref(called),::_1));
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";
378 s.set_fail_handler(bind(&
check_on_fail,&
s,ec,websocketpp::lib::ref(called),::_1));
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";
416 s.set_fail_handler(bind(&
check_on_fail,&
s,ec,websocketpp::lib::ref(called),::_1));
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();
Client endpoint role based on the given config.
connection_ptr connect(connection_ptr con)
Begin the connection process for the given connection.
connection_ptr get_connection(uri_ptr location, lib::error_code &ec)
Get a new connection.
connection_type::ptr connection_ptr
Represents an individual WebSocket connection.
bool is_server() const
Get whether or not this connection is part of a server or client.
void set_user_agent(std::string const &ua)
Sets the user agent string that this endpoint will use.
void set_message_handler(message_handler h)
void set_http_handler(http_handler h)
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)
void set_access_channels(log::level channels)
Set Access logging channel.
void set_error_channels(log::level channels)
Set Error logging channel.
Thread safe stub "random" integer generator.
Server endpoint role based on the given config.
connection_ptr get_connection()
Create and initialize a new connection.
connection_type::ptr connection_ptr
websocketpp::server< debug_config_client > debug_server
void on_open_print(server *s, websocketpp::connection_hdl hdl)
websocketpp::client< debug_config_client > debug_client
void fail_on_open(websocketpp::connection_hdl)
void check_on_fail(server *s, websocketpp::lib::error_code ec, bool &called, websocketpp::connection_hdl hdl)
void fail_on_http(websocketpp::connection_hdl)
void validate_func(server *s, websocketpp::connection_hdl hdl, message_ptr msg)
BOOST_AUTO_TEST_CASE(basic_http_request)
void http_func(server *s, websocketpp::connection_hdl hdl)
void defer_http_func(server *s, bool *deferred, websocketpp::connection_hdl hdl)
bool validate_set_ua(server *s, websocketpp::connection_hdl hdl)
std::string run_server_test(std::string input, bool log)
void echo_func(server *s, websocketpp::connection_hdl hdl, message_ptr msg)
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
@ http_parse_error
HTTP parse error.
@ invalid_state
The connection was in the wrong state for this operation.
@ unsupported_version
Unsupported WebSocket protocol version.
@ open_handshake_timeout
WebSocket opening handshake timed out.
@ invalid_version
Invalid WebSocket protocol version.
uint32_t level
Type of a channel package.
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
websocketpp::lib::error_code ec
stub_config::alog_type alog
stub_config::elog_type elog
connection_setup(bool p_is_server)
websocketpp::connection< stub_config > c
stub_config::rng_type rng
static const long timeout_connect
static const long timeout_socket_post_init
type::concurrency_type concurrency_type
type::elog_type elog_type
type::alog_type alog_type
static const long timeout_proxy
type::response_type response_type
static const long timeout_socket_shutdown
type::request_type request_type
static bool const enable_multithreading
static const long timeout_socket_pre_init
Default timer values (in ms)
core::alog_type alog_type
core::response_type response_type
core::elog_type elog_type
core::request_type request_type
static const websocketpp::log::level elog_level
websocketpp::random::none::int_generator< uint32_t > rng_type
core::message_type message_type
core::endpoint_base endpoint_base
core::endpoint_msg_manager_type endpoint_msg_manager_type
core::con_msg_manager_type con_msg_manager_type
core::concurrency_type concurrency_type
connection_extension connection_base
static const websocketpp::log::level alog_level
websocketpp::transport::debug::endpoint< transport_config > transport_type
Transport Endpoint Component.
core::alog_type alog_type
core::endpoint_msg_manager_type endpoint_msg_manager_type
core::elog_type elog_type
core::message_type message_type
core::endpoint_base endpoint_base
core::transport_type transport_type
core::con_msg_manager_type con_msg_manager_type
connection_extension connection_base
core::request_type request_type
core::concurrency_type concurrency_type
core::response_type response_type
Server config with iostream transport.
static level const none
Special aggregate value representing "no levels".
static level const all
Special aggregate value representing "all levels".
static level const all
Special aggregate value representing "all levels".
static level const none
Special aggregate value representing "no levels".