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
@@ -109,11 +109,16 @@ 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");
// 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());
// Set a timeout on the operation
beast::get_lowest_layer(ws_).expires_after(std::chrono::seconds(30));