diff --git a/test/processors/hybi13.cpp b/test/processors/hybi13.cpp index d597073a8a..20470f930e 100644 --- a/test/processors/hybi13.cpp +++ b/test/processors/hybi13.cpp @@ -495,7 +495,7 @@ BOOST_AUTO_TEST_CASE( client_handshake_request ) { websocketpp::uri_ptr u(new websocketpp::uri("ws://localhost/")); - env.p.client_handshake_request(env.req,u); + env.p.client_handshake_request(env.req,u, std::vector()); BOOST_CHECK_EQUAL( env.req.get_method(), "GET" ); BOOST_CHECK_EQUAL( env.req.get_version(), "HTTP/1.1"); diff --git a/websocketpp/impl/connection_impl.hpp b/websocketpp/impl/connection_impl.hpp index d7a7af3afb..a0f4939048 100644 --- a/websocketpp/impl/connection_impl.hpp +++ b/websocketpp/impl/connection_impl.hpp @@ -1080,14 +1080,14 @@ template void connection::send_http_request() { m_alog.write(log::alevel::devel,"connection send_http_request"); - // TODO: origin header - // TODO: subprotocol requests + // TODO: origin header? // Have the protocol processor fill in the appropriate fields based on the // selected client version if (m_processor) { lib::error_code ec; - ec = m_processor->client_handshake_request(m_request,m_uri); + ec = m_processor->client_handshake_request(m_request,m_uri, + m_requested_subprotocols); if (ec) { m_elog.write(log::elevel::fatal, diff --git a/websocketpp/processors/hybi00.hpp b/websocketpp/processors/hybi00.hpp index 1096a4e9ff..ca9e3a35dd 100644 --- a/websocketpp/processors/hybi00.hpp +++ b/websocketpp/processors/hybi00.hpp @@ -137,8 +137,8 @@ public: } // outgoing client connection processing is not supported for this version - lib::error_code client_handshake_request(request_type& req, uri_ptr uri) - const + lib::error_code client_handshake_request(request_type& req, uri_ptr uri, + const std::vector & subprotocols) const { return error::make_error_code(error::no_protocol_support); } diff --git a/websocketpp/processors/hybi07.hpp b/websocketpp/processors/hybi07.hpp index 04712a1fe6..fe8c928f1e 100644 --- a/websocketpp/processors/hybi07.hpp +++ b/websocketpp/processors/hybi07.hpp @@ -40,6 +40,8 @@ namespace processor { template class hybi07 : public hybi08 { public: + typedef typename config::request_type request_type; + typedef typename config::con_msg_manager_type::ptr msg_manager_ptr; typedef typename config::rng_type rng_type; @@ -47,6 +49,13 @@ public: rng_type& rng) : hybi08(secure, server, manager, rng) {} + // outgoing client connection processing is not supported for this version + lib::error_code client_handshake_request(request_type& req, uri_ptr uri, + const std::vector & subprotocols) const + { + return error::make_error_code(error::no_protocol_support); + } + int get_version() const { return 7; } diff --git a/websocketpp/processors/hybi08.hpp b/websocketpp/processors/hybi08.hpp index 4658ea4a35..719b9d2700 100644 --- a/websocketpp/processors/hybi08.hpp +++ b/websocketpp/processors/hybi08.hpp @@ -50,6 +50,13 @@ public: rng_type& rng) : hybi13(secure, server, manager, rng) {} + // outgoing client connection processing is not supported for this version + lib::error_code client_handshake_request(request_type& req, uri_ptr uri, + const std::vector & subprotocols) const + { + return error::make_error_code(error::no_protocol_support); + } + int get_version() const { return 8; } diff --git a/websocketpp/processors/hybi13.hpp b/websocketpp/processors/hybi13.hpp index b6bb34d976..3009b20149 100644 --- a/websocketpp/processors/hybi13.hpp +++ b/websocketpp/processors/hybi13.hpp @@ -192,7 +192,7 @@ public: } lib::error_code client_handshake_request(request_type& req, uri_ptr - uri) const + uri, const std::vector & subprotocols) const { req.set_method("GET"); req.set_uri(uri->get_resource()); @@ -203,6 +203,17 @@ public: req.replace_header("Sec-WebSocket-Version","13"); req.replace_header("Host",uri->get_host_port()); + if (!subprotocols.empty()) { + std::ostringstream result; + std::vector::const_iterator it = subprotocols.begin(); + result << *it++; + while (it != subprotocols.end()) { + result << ", " << *it++; + } + + req.replace_header("Sec-WebSocket-Protocol",result.str()); + } + // Generate handshake key frame::uint32_converter conv; unsigned char raw_key[16]; diff --git a/websocketpp/processors/processor.hpp b/websocketpp/processors/processor.hpp index b5508f36d0..d06d88f9a2 100644 --- a/websocketpp/processors/processor.hpp +++ b/websocketpp/processors/processor.hpp @@ -200,7 +200,7 @@ public: * @return An error code, 0 on success, non-zero for other errors */ virtual lib::error_code client_handshake_request(request_type& req, - uri_ptr uri) const = 0; + uri_ptr uri, const std::vector & subprotocols) const = 0; /// Validate the server's response to an outgoing handshake request /**