diff --git a/src/internal/sio_client_impl.cpp b/src/internal/sio_client_impl.cpp index 6246a95a..3cd98da8 100644 --- a/src/internal/sio_client_impl.cpp +++ b/src/internal/sio_client_impl.cpp @@ -69,6 +69,13 @@ namespace sio this->sockets_invoke_void(&sio::socket::on_close); sync_close(); } + + void client_impl::set_proxy_basic_auth(const std::string& uri, const std::string& username, const std::string& password) + { + m_proxy_base_url = uri; + m_proxy_basic_username = username; + m_proxy_basic_password = password; + } void client_impl::connect(const string& uri, const map& query, const map& headers, const message::ptr& auth) { @@ -263,6 +270,23 @@ namespace sio for( auto&& header: m_http_headers ) { con->replace_header(header.first, header.second); } + + if (!m_proxy_base_url.empty()) { + con->set_proxy(m_proxy_base_url, ec); + if (ec) { + m_client.get_alog().write(websocketpp::log::alevel::app, + "Set Proxy Error: " + ec.message()); + break; + } + if (!m_proxy_basic_username.empty()) { + con->set_proxy_basic_auth(m_proxy_basic_username, m_proxy_basic_password, ec); + if (ec) { + m_client.get_alog().write(websocketpp::log::alevel::app, + "Set Proxy Basic Auth Error: " + ec.message()); + break; + } + } + } m_client.connect(con); return; diff --git a/src/internal/sio_client_impl.h b/src/internal/sio_client_impl.h index 8e35887a..3cd82a0d 100644 --- a/src/internal/sio_client_impl.h +++ b/src/internal/sio_client_impl.h @@ -129,6 +129,8 @@ namespace sio void set_logs_quiet(); void set_logs_verbose(); + + void set_proxy_basic_auth(const std::string& uri, const std::string& username, const std::string& password); protected: void send(packet& p); @@ -203,6 +205,9 @@ namespace sio std::string m_query_string; std::map m_http_headers; message::ptr m_auth; + std::string m_proxy_base_url; + std::string m_proxy_basic_username; + std::string m_proxy_basic_password; unsigned int m_ping_interval; unsigned int m_ping_timeout; diff --git a/src/sio_client.cpp b/src/sio_client.cpp index 95054780..b3fa7765 100644 --- a/src/sio_client.cpp +++ b/src/sio_client.cpp @@ -66,6 +66,11 @@ namespace sio { m_impl->clear_socket_listeners(); } + + void client::set_proxy_basic_auth(const std::string& uri, const std::string& username, const std::string& password) + { + m_impl->set_proxy_basic_auth(uri, username, password); + } void client::connect(const std::string& uri) { diff --git a/src/sio_client.h b/src/sio_client.h index 7b6f1f89..821164aa 100644 --- a/src/sio_client.h +++ b/src/sio_client.h @@ -87,6 +87,8 @@ namespace sio void sync_close(); + void set_proxy_basic_auth(const std::string& uri, const std::string& username, const std::string& password); + bool opened() const; std::string const& get_sessionid() const;