diff --git a/CHANGELOG.md b/CHANGELOG.md index 60366874..62648465 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ WebSocket * stream tidying * Add rd_close_ to websocket stream state * stream uses flat_buffer +* accept requires a message -------------------------------------------------------------------------------- diff --git a/include/beast/websocket/impl/accept.ipp b/include/beast/websocket/impl/accept.ipp index 892dcffa..6702364f 100644 --- a/include/beast/websocket/impl/accept.ipp +++ b/include/beast/websocket/impl/accept.ipp @@ -42,24 +42,22 @@ class stream::response_op response_type res; int state = 0; - template - data(Handler&, stream& ws_, http::header< - true, http::basic_fields> const& req, - Decorator const& decorator, - bool cont_) + template + data(Handler&, stream& ws_, http::request< + Body, http::basic_fields> const& req, + Decorator const& decorator, bool cont_) : cont(cont_) , ws(ws_) , res(ws_.build_response(req, decorator)) { } - template - data(Handler&, stream& ws_, http::header< - true, http::basic_fields> const& req, - Buffers const& buffers, - Decorator const& decorator, - bool cont_) + data(Handler&, stream& ws_, http::request< + Body, http::basic_fields> const& req, + Buffers const& buffers, Decorator const& decorator, + bool cont_) : cont(cont_) , ws(ws_) , res(ws_.build_response(req, decorator)) @@ -443,10 +441,10 @@ accept_ex(ConstBufferSequence const& buffers, } template -template +template void stream:: -accept(http::header> const& req) { static_assert(is_sync_stream::value, @@ -458,10 +456,11 @@ accept(http::header -template +template void stream:: -accept_ex(http::header> const& req, ResponseDecorator const& decorator) { @@ -477,10 +476,10 @@ accept_ex(http::header -template +template void stream:: -accept(http::header> const& req, error_code& ec) { @@ -491,10 +490,11 @@ accept(http::header -template +template void stream:: -accept_ex(http::header> const& req, ResponseDecorator const& decorator, error_code& ec) { @@ -508,10 +508,11 @@ accept_ex(http::header -template +template void stream:: -accept(http::header> const& req, ConstBufferSequence const& buffers) { @@ -527,11 +528,11 @@ accept(http::header -template void stream:: -accept_ex(http::header> const& req, ConstBufferSequence const& buffers, ResponseDecorator const& decorator) @@ -551,11 +552,12 @@ accept_ex(http::header -template +template void stream:: -accept(http::header const& req, +accept(http::request> const& req, ConstBufferSequence const& buffers, error_code& ec) { static_assert(is_sync_stream::value, @@ -573,11 +575,11 @@ accept(http::header -template void stream:: -accept_ex(http::header> const& req, ConstBufferSequence const& buffers, ResponseDecorator const& decorator, @@ -696,11 +698,12 @@ async_accept_ex(ConstBufferSequence const& buffers, } template -template +template async_return_type< AcceptHandler, void(error_code)> stream:: -async_accept(http::header> const& req, AcceptHandler&& handler) { @@ -719,12 +722,12 @@ async_accept(http::header -template async_return_type< AcceptHandler, void(error_code)> stream:: -async_accept_ex(http::header> const& req, ResponseDecorator const& decorator, AcceptHandler&& handler) { @@ -746,12 +749,12 @@ async_accept_ex(http::header -template async_return_type< AcceptHandler, void(error_code)> stream:: -async_accept(http::header> const& req, ConstBufferSequence const& buffers, AcceptHandler&& handler) @@ -774,12 +777,13 @@ async_accept(http::header -template +template async_return_type< AcceptHandler, void(error_code)> stream:: -async_accept_ex(http::header> const& req, ConstBufferSequence const& buffers, ResponseDecorator const& decorator, diff --git a/include/beast/websocket/impl/stream.ipp b/include/beast/websocket/impl/stream.ipp index 03a00258..286b7e9a 100644 --- a/include/beast/websocket/impl/stream.ipp +++ b/include/beast/websocket/impl/stream.ipp @@ -501,10 +501,10 @@ build_request(detail::sec_ws_key_type& key, } template -template +template response_type stream:: -build_response(http::header> const& req, Decorator const& decorator) { @@ -598,10 +598,11 @@ do_accept( } template -template +template void stream:: -do_accept(http::header> const& req, Decorator const& decorator, error_code& ec) { @@ -652,7 +653,7 @@ do_handshake(response_type* res_p, template void stream:: -do_response(http::header const& res, +do_response(response_type const& res, detail::sec_ws_key_type const& key, error_code& ec) { bool const success = [&]() diff --git a/include/beast/websocket/stream.hpp b/include/beast/websocket/stream.hpp index 5d39b6cc..70864135 100644 --- a/include/beast/websocket/stream.hpp +++ b/include/beast/websocket/stream.hpp @@ -999,9 +999,10 @@ public: @throws system_error Thrown on failure. */ - template + template void - accept(http::header> const& req); + accept(http::request> const& req); /** Respond to a WebSocket HTTP Upgrade request @@ -1040,9 +1041,10 @@ public: @throws system_error Thrown on failure. */ - template + template void - accept_ex(http::header> const& req, ResponseDecorator const& decorator); @@ -1074,10 +1076,11 @@ public: @param ec Set to indicate what error occurred, if any. */ - template + template void - accept(http::header> const& req, - error_code& ec); + accept(http::request> const& req, + error_code& ec); /** Respond to a WebSocket HTTP Upgrade request @@ -1116,9 +1119,10 @@ public: @param ec Set to indicate what error occurred, if any. */ - template + template void - accept_ex(http::header> const& req, ResponseDecorator const& decorator, error_code& ec); @@ -1156,10 +1160,12 @@ public: @throws system_error Thrown on failure. */ - template + template void - accept(http::header> const& req, - ConstBufferSequence const& buffers); + accept(http::request> const& req, + ConstBufferSequence const& buffers); /** Respond to a WebSocket HTTP Upgrade request @@ -1203,10 +1209,10 @@ public: @throws system_error Thrown on failure. */ - template + template void - accept_ex(http::header> const& req, ConstBufferSequence const& buffers, ResponseDecorator const& decorator); @@ -1244,10 +1250,13 @@ public: @param ec Set to indicate what error occurred, if any. */ - template + template void - accept(http::header const& req, - ConstBufferSequence const& buffers, error_code& ec); + accept(http::request> const& req, + ConstBufferSequence const& buffers, + error_code& ec); /** Respond to a WebSocket HTTP Upgrade request @@ -1291,10 +1300,10 @@ public: @param ec Set to indicate what error occurred, if any. */ - template + template void - accept_ex(http::header> const& req, ConstBufferSequence const& buffers, ResponseDecorator const& decorator, @@ -1580,14 +1589,15 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `boost::asio::io_service::post`. */ - template + template #if BEAST_DOXYGEN void_or_deduced #else async_return_type< AcceptHandler, void(error_code)> #endif - async_accept(http::header> const& req, AcceptHandler&& handler); @@ -1645,7 +1655,7 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `boost::asio::io_service::post`. */ - template #if BEAST_DOXYGEN void_or_deduced @@ -1653,7 +1663,7 @@ public: async_return_type< AcceptHandler, void(error_code)> #endif - async_accept_ex(http::header> const& req, ResponseDecorator const& decorator, AcceptHandler&& handler); @@ -1710,7 +1720,7 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `boost::asio::io_service::post`. */ - template #if BEAST_DOXYGEN void_or_deduced @@ -1718,7 +1728,7 @@ public: async_return_type< AcceptHandler, void(error_code)> #endif - async_accept(http::header> const& req, ConstBufferSequence const& buffers, AcceptHandler&& handler); @@ -1784,19 +1794,23 @@ public: this function. Invocation of the handler will be performed in a manner equivalent to using `boost::asio::io_service::post`. */ - template + template< + class Body, class Allocator, + class ConstBufferSequence, + class ResponseDecorator, + class AcceptHandler> #if BEAST_DOXYGEN void_or_deduced #else async_return_type< AcceptHandler, void(error_code)> #endif - async_accept_ex(http::header> const& req, - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - AcceptHandler&& handler); + async_accept_ex( + http::request> const& req, + ConstBufferSequence const& buffers, + ResponseDecorator const& decorator, + AcceptHandler&& handler); /** Send an HTTP WebSocket Upgrade request and receive the response. @@ -3326,9 +3340,10 @@ private: string_view target, Decorator const& decorator); - template + template response_type - build_response(http::header> const& req, Decorator const& decorator); @@ -3337,22 +3352,22 @@ private: do_accept(Decorator const& decorator, error_code& ec); - template + template void - do_accept(http::header> const& req, Decorator const& decorator, error_code& ec); template void do_handshake(response_type* res_p, - string_view host, - string_view target, - RequestDecorator const& decorator, - error_code& ec); + string_view host, string_view target, + RequestDecorator const& decorator, + error_code& ec); void - do_response(http::header const& resp, + do_response(response_type const& resp, detail::sec_ws_key_type const& key, error_code& ec); }; diff --git a/test/websocket/stream.cpp b/test/websocket/stream.cpp index 02bab544..a129cd45 100644 --- a/test/websocket/stream.cpp +++ b/test/websocket/stream.cpp @@ -138,19 +138,18 @@ public: ws.accept(buffers); } - template + template void accept(stream& ws, - http::header const& req) const + http::request const& req) const { ws.accept(req); } - template + template void accept(stream& ws, - http::header const& req, + http::request const& req, Buffers const& buffers) const { ws.accept(req, buffers); @@ -175,22 +174,20 @@ public: ws.accept_ex(buffers, d); } - template + template void accept_ex(stream& ws, - http::header const& req, + http::request const& req, Decorator const& d) const { ws.accept_ex(req, d); } template + class Buffers, class Decorator> void accept_ex(stream& ws, - http::header const& req, + http::request const& req, Buffers const& buffers, Decorator const& d) const { @@ -332,10 +329,10 @@ public: throw system_error{ec}; } - template + template void accept(stream& ws, - http::header const& req) const + http::request const& req) const { error_code ec; ws.async_accept(req, yield_[ec]); @@ -343,11 +340,10 @@ public: throw system_error{ec}; } - template + template void accept(stream& ws, - http::header const& req, + http::request const& req, Buffers const& buffers) const { error_code ec; @@ -382,11 +378,10 @@ public: throw system_error{ec}; } - template + template void accept_ex(stream& ws, - http::header const& req, + http::request const& req, Decorator const& d) const { error_code ec; @@ -395,11 +390,11 @@ public: throw system_error{ec}; } - template void accept_ex(stream& ws, - http::header const& req, + http::request const& req, Buffers const& buffers, Decorator const& d) const {