41 websocket::stream<boost::beast::ssl_stream<tcp::socket>> ws_;
42 http::request<http::empty_body> proxyHandshake;
43 http::response<http::empty_body> proxyHandshakeResponse;
46 http::response_parser<http::empty_body> http_proxy_handshake_parser;
52 FETPAPI_DLL_IMPORT_OR_EXPORT
SslClientSession(boost::asio::ssl::context& ctx,
53 InitializationParameters const* initializationParams,
const std::string& target,
const std::string& authorization,
const std::string& proxyAuthorization =
"",
54 const std::map<std::string, std::string>& additionalHandshakeHeaderFields = {}, std::size_t frameSize = 4096);
59 FETPAPI_DLL_IMPORT_OR_EXPORT websocket::stream<boost::beast::ssl_stream<tcp::socket>>& ws() {
return ws_; }
61 bool isTls()
const final {
return true; }
63 void on_resolve(boost::system::error_code ec, tcp::resolver::results_type results)
66 std::cerr <<
"on_resolve : " << ec.message() << std::endl;
70 boost::asio::async_connect(
71 ws_.next_layer().next_layer(),
75 &SslClientSession::on_ssl_connect,
76 std::static_pointer_cast<SslClientSession>(shared_from_this()),
77 std::placeholders::_1));
80 void on_ssl_connect(boost::system::error_code ec) {
82 std::cerr <<
"on_ssl_connect : " << ec.message() << std::endl;
85 if (!proxyHost.empty()) {
86 proxyHandshake.version(11);
87 proxyHandshake.method(http::verb::connect);
88 proxyHandshake.target(etpServerHost +
':' + etpServerPort);
89 proxyHandshake.set(http::field::host, etpServerHost +
':' + etpServerPort);
90 if (!etpServerAuthorization.empty()) {
91 proxyHandshake.set(http::field::authorization, etpServerAuthorization);
93 if (!proxyAuthorization.empty()) {
94 proxyHandshake.set(http::field::proxy_authorization, proxyAuthorization);
98 http::async_write(ws_.next_layer().next_layer(), proxyHandshake,
100 &SslClientSession::on_proxy_handshake_write,
101 std::static_pointer_cast<SslClientSession>(shared_from_this()),
102 std::placeholders::_1,
103 std::placeholders::_2));
107 ws_.next_layer().async_handshake(
108 boost::asio::ssl::stream_base::client,
110 &AbstractClientSessionCRTP::on_connect,
111 std::static_pointer_cast<AbstractClientSessionCRTP>(shared_from_this()),
112 std::placeholders::_1));
118 boost::system::error_code ec,
119 std::size_t bytes_transferred)
121 boost::ignore_unused(bytes_transferred);
124 std::cerr <<
"Proxy handshake write : " << ec.message() << std::endl;
140 http_proxy_handshake_parser.skip(
true);
143 http::async_read(ws_.next_layer().next_layer(), receivedBuffer, http_proxy_handshake_parser,
145 &SslClientSession::on_proxy_handshake_read,
146 std::static_pointer_cast<SslClientSession>(shared_from_this()),
147 std::placeholders::_1,
148 std::placeholders::_2));
152 on_proxy_handshake_read(
153 boost::system::error_code ec,
154 std::size_t bytes_transferred)
156 boost::ignore_unused(bytes_transferred);
158 std::cerr <<
"read : " << ec.message() << std::endl;
163 ws_.next_layer().async_handshake(
164 boost::asio::ssl::stream_base::client,
166 &AbstractClientSessionCRTP::on_connect,
167 std::static_pointer_cast<AbstractClientSessionCRTP>(shared_from_this()),
168 std::placeholders::_1));