28 #define BOOST_TEST_MODULE hybi_00_processor 29 #include <boost/test/unit_test.hpp> 44 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";
46 r.
consume(handshake.c_str(),handshake.size());
58 }
catch (
const websocketpp::uri_exception& e) {
62 BOOST_CHECK(exception ==
false);
63 BOOST_CHECK(u->get_secure() ==
false);
64 BOOST_CHECK(u->get_host() ==
"www.example.com");
65 BOOST_CHECK(u->get_resource() ==
"/");
66 BOOST_CHECK(u->get_port() == websocketpp::URI_DEFAULT_PORT);
70 BOOST_CHECK(response.
get_header(
"Connection") ==
"Upgrade");
71 BOOST_CHECK(response.
get_header(
"Upgrade") ==
"websocket");
72 BOOST_CHECK(response.
get_header(
"Sec-WebSocket-Origin") ==
"http://example.com");
74 BOOST_CHECK(response.
get_header(
"Sec-WebSocket-Location") ==
"ws://www.example.com/");
75 BOOST_CHECK(response.
get_header(
"Sec-WebSocket-Key3") ==
"n`9eBk9z$R8pOtVb");
82 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";
84 r.
consume(handshake.c_str(),handshake.size());
96 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";
98 r.
consume(handshake.c_str(),handshake.size());
110 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";
112 r.
consume(handshake.c_str(),handshake.size());
124 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";
126 r.
consume(handshake.c_str(),handshake.size());
138 bool exception =
false;
140 std::string handshake =
"GET / HTTP/1.1\r\nHost: www.example.com:70000\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Key2: 17 9 G`ZD9 2 2b 7X 3 /r90\r\n\r\n";
142 r.
consume(handshake.c_str(),handshake.size());
151 }
catch (
const websocketpp::uri_exception& e) {
155 BOOST_CHECK(exception ==
true);
std::string const & get_header(std::string const &key) const
Get the value of an HTTP header.
bool is_websocket_handshake(request_type &r)
Determine whether or not a generic HTTP request is a WebSocket handshake.
lib::error_code validate_handshake(request_type const &r) const
validate a WebSocket handshake request for this version
int get_websocket_version(request_type &r)
Extract the version from a WebSocket handshake request.
int get_version() const
Get the protocol version of this processor.
Stores, parses, and manipulates HTTP responses.
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
uri_ptr get_uri(request_type const &request) const
Extracts client uri from a handshake request.
void replace_header(std::string const &key, std::string const &val)
Set a value for an HTTP header, replacing an existing value.
BOOST_AUTO_TEST_CASE(exact_match)
Stores, parses, and manipulates HTTP requests.
size_t consume(char const *buf, size_t len)
Process bytes in the input buffer.
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.