28 #define BOOST_TEST_MODULE hybi_00_processor 29 #include <boost/test/unit_test.hpp> 55 , p(false,server,msg_manager) {}
57 websocketpp::lib::error_code
ec;
69 std::string handshake =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nOrigin: http://example.com\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
71 env.
req.consume(handshake.c_str(),handshake.size());
72 env.
req.replace_header(
"Sec-WebSocket-Key3",
"WjN}|M(6");
83 BOOST_CHECK_EQUAL(u->get_secure(),
false);
84 BOOST_CHECK_EQUAL(u->get_host(),
"www.example.com");
85 BOOST_CHECK_EQUAL(u->get_resource(),
"/");
90 BOOST_CHECK_EQUAL(env.
res.get_header(
"Connection"),
"Upgrade");
91 BOOST_CHECK_EQUAL(env.
res.get_header(
"Upgrade"),
"WebSocket");
92 BOOST_CHECK_EQUAL(env.
res.get_header(
"Sec-WebSocket-Origin"),
"http://example.com");
94 BOOST_CHECK_EQUAL(env.
res.get_header(
"Sec-WebSocket-Location"),
"ws://www.example.com/");
95 BOOST_CHECK_EQUAL(env.
res.get_header(
"Sec-WebSocket-Key3"),
"n`9eBk9z$R8pOtVb");
101 std::string handshake =
"POST / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
103 env.
req.consume(handshake.c_str(),handshake.size());
104 env.
req.replace_header(
"Sec-WebSocket-Key3",
"janelle!");
114 std::string handshake =
"GET / HTTP/1.0\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
116 env.
req.consume(handshake.c_str(),handshake.size());
117 env.
req.replace_header(
"Sec-WebSocket-Key3",
"janelle!");
127 std::string handshake =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\n\r\n";
129 env.
req.consume(handshake.c_str(),handshake.size());
130 env.
req.replace_header(
"Sec-WebSocket-Key3",
"janelle!");
140 std::string handshake =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
142 env.
req.consume(handshake.c_str(),handshake.size());
143 env.
req.replace_header(
"Sec-WebSocket-Key3",
"janelle!");
154 std::string handshake =
"GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: upgrade\r\nUpgrade: websocket\r\nOrigin: http://example.com\r\nSec-WebSocket-Key1: 3e6b263 4 17 80\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
156 env.
req.consume(handshake.c_str(),handshake.size());
157 env.
req.replace_header(
"Sec-WebSocket-Key3",
"janelle!");
163 BOOST_CHECK( !env.
p.
get_uri(env.
req)->get_valid() );
169 std::vector<std::string> subps;
172 BOOST_CHECK_EQUAL( subps.size(), 0 );
192 for (
int i = 0; i < 0xF; i++) {
223 in->set_payload(
"foo");
227 unsigned char raw_header[1] = {0x00};
228 unsigned char raw_payload[4] = {0x66,0x6f,0x6f,0xff};
230 BOOST_CHECK( !env.
ec );
231 BOOST_CHECK_EQUAL( out->get_header(), std::string(reinterpret_cast<char*>(raw_header),1) );
232 BOOST_CHECK_EQUAL( out->get_payload(), std::string(reinterpret_cast<char*>(raw_payload),4) );
237 uint8_t frame[2] = {0x00,0x00};
243 BOOST_CHECK_EQUAL( ret, 0);
244 BOOST_CHECK( !env.
ec );
245 BOOST_CHECK_EQUAL( env.
p.
ready(), false );
249 uint8_t frame[2] = {0x00, 0xff};
255 BOOST_CHECK_EQUAL( ret, 2);
256 BOOST_CHECK( !env.
ec );
257 BOOST_CHECK_EQUAL( env.
p.
ready(), true );
258 BOOST_CHECK_EQUAL( env.
p.
get_message()->get_payload(),
"" );
259 BOOST_CHECK_EQUAL( env.
p.
ready(), false );
263 uint8_t frame[5] = {0x00, 0x66, 0x6f, 0x6f, 0xff};
269 BOOST_CHECK_EQUAL( ret, 5);
270 BOOST_CHECK( !env.
ec );
271 BOOST_CHECK_EQUAL( env.
p.
ready(), true );
272 BOOST_CHECK_EQUAL( env.
p.
get_message()->get_payload(),
"foo" );
273 BOOST_CHECK_EQUAL( env.
p.
ready(), false );
bool ready() const
Checks if there is a message ready.
int get_version() const
Get the protocol version of this processor.
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
stub_config::request_type req
BOOST_AUTO_TEST_CASE(exact_match)
lib::error_code validate_handshake(request_type const &r) const
validate a WebSocket handshake request for this version
bool is_websocket_handshake(request_type &r)
Determine whether or not a generic HTTP request is a WebSocket handshake.
lib::error_code process_handshake(request_type const &req, std::string const &subprotocol, response_type &res) const
Calculate the appropriate response for this websocket request.
int get_websocket_version(request_type &r)
Extract the version from a WebSocket handshake request.
lib::error_code extract_subprotocols(request_type const &req, std::vector< std::string > &subprotocol_list)
Extracts requested subprotocols from a handshake request.
stub_config::con_msg_manager_type con_msg_manager_type
bool invalid(value code)
Test whether a close code is invalid on the wire.
Stores, parses, and manipulates HTTP responses.
stub_config::con_msg_manager_type::ptr msg_manager
uri_ptr get_uri(request_type const &request) const
Extracts client uri from a handshake request.
websocketpp::http::parser::response response_type
message_ptr get_message()
Retrieves the most recently processed message.
size_t consume(uint8_t *buf, size_t len, lib::error_code &ec)
Process new websocket connection bytes.
Represents a buffer for a single WebSocket message.
stub_config::response_type res
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
websocketpp::http::parser::request request_type
websocketpp::processor::hybi00< stub_config > p
core::request_type request_type
static const size_t max_message_size
Stores, parses, and manipulates HTTP requests.
virtual lib::error_code prepare_data_frame(message_ptr in, message_ptr out)
Prepare a message for writing.
Opcode was invalid for requested operation.
websocketpp::lib::error_code ec
core::response_type response_type
websocketpp::message_buffer::alloc::con_msg_manager< message_type > con_msg_manager_type
stub_config::message_type::ptr message_ptr
static uint16_t const uri_default_port
Default port for ws://.
A connection message manager that allocates a new message for each request.
processor_setup(bool server)
The processor method was called with invalid arguments.
websocketpp::message_buffer::message< websocketpp::message_buffer::alloc::con_msg_manager > message_type