Fix Host header in websocket examples

closes #1633
This commit is contained in:
Richard Hodges
2020-04-08 15:56:39 +02:00
parent 483b00d20f
commit c397227eb5
8 changed files with 56 additions and 15 deletions
@@ -95,7 +95,7 @@ public:
}
void
on_connect(beast::error_code ec, tcp::resolver::results_type::endpoint_type)
on_connect(beast::error_code ec, tcp::resolver::results_type::endpoint_type ep)
{
if(ec)
return fail(ec, "connect");
@@ -118,6 +118,11 @@ public:
" websocket-client-async");
}));
// Update the host_ string. This will provide the value of the
// Host HTTP header during the WebSocket handshake.
// See https://tools.ietf.org/html/rfc7230#section-5.4
host_ += ':' + std::to_string(ep.port());
// Perform the websocket handshake
ws_.async_handshake(host_, "/",
beast::bind_front_handler(