void WebProxyAdapter::on_tcp_connect()

in src/WebProxyAdapter.cpp [68:103]


            void WebProxyAdapter::on_tcp_connect() {
                BOOST_LOG_SEV(*log, trace) << "Preparing HTTP CONNECT request";
                request.version(HTTP_VERSION);
                request.method(http::verb::connect);
                const std::string host =  localproxy_config.proxy_host +
                                     ":" + std::to_string(localproxy_config.proxy_port);
                request.target(host);
                if (!localproxy_config.web_proxy_auth.empty()) {
                    BOOST_LOG_SEV(*log, trace) << "Web proxy AuthN found, adding them to the request";
                    request.set(http::field::host, host);
                    std::string credentials;
                    credentials.resize(base64::encoded_size(localproxy_config.web_proxy_auth.size()));
                    credentials.resize(base64::encode(&credentials[0],
                                                      localproxy_config.web_proxy_auth.data(),
                                                      localproxy_config.web_proxy_auth.size()));
                    request.set(http::field::proxy_authorization, "basic " + credentials);
                }
                BOOST_LOG_SEV(*log, trace) << "Sending HTTP CONNECT";
                auto on_async_write = [this](error_code const &ec,
                                                               std::size_t bytes_transferred) {
                    boost::ignore_unused(bytes_transferred);
                    if (ec) {
                        BOOST_LOG_SEV(*log, error) << (boost::format(
                                    "Could not send HTTP CONNECT request to the Web proxy: %1%") % ec.message()).str();
                        (*on_tcp_tunnel)(WebProxyAdapterErrc::HttpWriteRequestError);
                    } else {
                        BOOST_LOG_SEV(*log, debug) << "Successfully sent HTTP CONNECT to the Web proxy";
                        on_http_connect_write();
                    }
                };
                if (localproxy_config.is_web_proxy_using_tls) {
                    http::async_write(*websocket_stream->get_web_proxy_ssl_stream(), request, on_async_write);
                } else {
                    http::async_write(websocket_stream->get_tcp_socket(), request, on_async_write);
                }
            }