WebSocket Decorator is a socket option (API Change):

This changes the interface used to apply a decorator to the HTTP
request or response messages used to perform the WebSocket handshake
as follows:

* Add the `stream_base::decorator` option object

* Add `stream::set_option` overload to set the decorator from
  the option

* The decorator applies to all client and server handshakes
  performed on the stream after the option is set.

* Overloads of the following functions which accept a Decorator
  are deprecated:
  - accept, accept_ex
  - handshake, handshake_ex
  - async_accept, async_accept_ex
  - async_handshake, async_handshake_ex

Actions Required:

* Code which passes decorator to any `websocket::stream` member
  function should call `stream::set_option` instead with a newly
  constructed `stream_base::decorator` object containing the
  decorator. Alternatively, the macro `BOOST_BEAST_ALLOW_DEPRECATED`
  may be defined to 1.
This commit is contained in:
Vinnie Falco
2019-02-19 16:23:30 -08:00
parent 085fb66b26
commit 3f50efa138
41 changed files with 1097 additions and 1391 deletions
@@ -90,13 +90,15 @@ do_sync_session(ws_type& ws)
setup_stream(ws);
ws.accept_ex(
// Set a decorator to change the Server of the handshake
ws.set_option(websocket::stream_base::decorator(
[](websocket::response_type& res)
{
res.set(http::field::server,
"Boost.Beast/" + std::to_string(BOOST_BEAST_VERSION) + "-Sync");
},
ec);
res.set(http::field::server, std::string(
BOOST_BEAST_VERSION_STRING) + "-Sync");
}));
ws.accept(ec);
if(ec)
return fail(ec, "accept");
@@ -158,13 +160,16 @@ public:
void
run()
{
// Accept the websocket handshake
ws_.async_accept_ex(
// Set a decorator to change the Server of the handshake
ws_.set_option(websocket::stream_base::decorator(
[](websocket::response_type& res)
{
res.set(http::field::server,
"Boost.Beast/" + std::to_string(BOOST_BEAST_VERSION) + "-Async");
},
res.set(http::field::server, std::string(
BOOST_BEAST_VERSION_STRING) + "-Async");
}));
// Accept the websocket handshake
ws_.async_accept(
beast::bind_front_handler(
&async_session::on_accept,
shared_from_this()));
@@ -324,13 +329,15 @@ do_coro_session(ws_type& ws, net::yield_context yield)
setup_stream(ws);
ws.async_accept_ex(
[&](websocket::response_type& res)
// Set a decorator to change the Server of the handshake
ws.set_option(websocket::stream_base::decorator(
[](websocket::response_type& res)
{
res.set(http::field::server,
"Boost.Beast/" + std::to_string(BOOST_BEAST_VERSION) + "-Coro");
},
yield[ec]);
res.set(http::field::server, std::string(
BOOST_BEAST_VERSION_STRING) + "-Fiber");
}));
ws.async_accept(yield[ec]);
if(ec)
return fail(ec, "accept");