28#define BOOST_TEST_MODULE hybi_00_processor
29#include <boost/test/unit_test.hpp>
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(),
"/");
86 BOOST_CHECK_EQUAL(u->get_port(), websocketpp::uri_default_port);
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 );
Stores, parses, and manipulates HTTP requests.
Stores, parses, and manipulates HTTP responses.
Represents a buffer for a single WebSocket message.
Processor for Hybi Draft version 00.
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.
size_t consume(uint8_t *buf, size_t len, lib::error_code &ec)
Process new websocket connection bytes.
bool ready() const
Checks if there is a message ready.
virtual lib::error_code prepare_data_frame(message_ptr in, message_ptr out)
Prepare a message for writing.
lib::error_code validate_handshake(request_type const &r) const
validate a WebSocket handshake request for this version
int get_version() const
Get the protocol version of this processor.
uri_ptr get_uri(request_type const &request) const
Extracts client uri from a handshake request.
lib::error_code extract_subprotocols(request_type const &req, std::vector< std::string > &subprotocol_list)
Extracts requested subprotocols from a handshake request.
message_ptr get_message()
Retrieves the most recently processed message.
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
BOOST_AUTO_TEST_CASE(exact_match)
stub_config::message_type::ptr message_ptr
stub_config::con_msg_manager_type con_msg_manager_type
@ missing_required_header
Missing Required Header.
@ invalid_http_method
Invalid HTTP method.
@ invalid_opcode
Opcode was invalid for requested operation.
@ invalid_http_version
Invalid HTTP version.
@ invalid_arguments
The processor method was called with invalid arguments.
int get_websocket_version(request_type &r)
Extract the version from a WebSocket handshake request.
bool is_websocket_handshake(request_type &r)
Determine whether or not a generic HTTP request is a WebSocket handshake.
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
websocketpp::lib::error_code ec
stub_config::response_type res
websocketpp::processor::hybi00< stub_config > p
processor_setup(bool server)
stub_config::con_msg_manager_type::ptr msg_manager
stub_config::request_type req
websocketpp::message_buffer::message< websocketpp::message_buffer::alloc::con_msg_manager > message_type
websocketpp::message_buffer::alloc::con_msg_manager< message_type > con_msg_manager_type
websocketpp::http::parser::request request_type
websocketpp::http::parser::response response_type
core::request_type request_type
static const size_t max_message_size
core::response_type response_type
void subps(const Xmm &xmm, const Operand &op)