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
@@ -47,9 +47,9 @@ int main(int argc, char** argv)
" websocket-client-sync-ssl echo.websocket.org 443 \"Hello, world!\"\n";
return EXIT_FAILURE;
}
auto const host = argv[1];
auto const port = argv[2];
auto const text = argv[3];
std::string host = argv[1];
auto const port = argv[2];
auto const text = argv[3];
// The io_context is required for all I/O
net::io_context ioc;
@@ -68,7 +68,12 @@ int main(int argc, char** argv)
auto const results = resolver.resolve(host, port);
// Make the connection on the IP address we get from a lookup
net::connect(ws.next_layer().next_layer(), results.begin(), results.end());
auto ep = net::connect(get_lowest_layer(ws), results);
// 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 SSL handshake
ws.next_layer().handshake(ssl::stream_base::client);