Skip to content

Commit 201d99d

Browse files
authored
feat: basic auth proxy (#369)
1 parent dbb4547 commit 201d99d

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

src/internal/sio_client_impl.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ namespace sio
6969
this->sockets_invoke_void(&sio::socket::on_close);
7070
sync_close();
7171
}
72+
73+
void client_impl::set_proxy_basic_auth(const std::string& uri, const std::string& username, const std::string& password)
74+
{
75+
m_proxy_base_url = uri;
76+
m_proxy_basic_username = username;
77+
m_proxy_basic_password = password;
78+
}
7279

7380
void client_impl::connect(const string& uri, const map<string,string>& query, const map<string, string>& headers, const message::ptr& auth)
7481
{
@@ -263,6 +270,23 @@ namespace sio
263270
for( auto&& header: m_http_headers ) {
264271
con->replace_header(header.first, header.second);
265272
}
273+
274+
if (!m_proxy_base_url.empty()) {
275+
con->set_proxy(m_proxy_base_url, ec);
276+
if (ec) {
277+
m_client.get_alog().write(websocketpp::log::alevel::app,
278+
"Set Proxy Error: " + ec.message());
279+
break;
280+
}
281+
if (!m_proxy_basic_username.empty()) {
282+
con->set_proxy_basic_auth(m_proxy_basic_username, m_proxy_basic_password, ec);
283+
if (ec) {
284+
m_client.get_alog().write(websocketpp::log::alevel::app,
285+
"Set Proxy Basic Auth Error: " + ec.message());
286+
break;
287+
}
288+
}
289+
}
266290

267291
m_client.connect(con);
268292
return;

src/internal/sio_client_impl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ namespace sio
129129
void set_logs_quiet();
130130

131131
void set_logs_verbose();
132+
133+
void set_proxy_basic_auth(const std::string& uri, const std::string& username, const std::string& password);
132134

133135
protected:
134136
void send(packet& p);
@@ -203,6 +205,9 @@ namespace sio
203205
std::string m_query_string;
204206
std::map<std::string, std::string> m_http_headers;
205207
message::ptr m_auth;
208+
std::string m_proxy_base_url;
209+
std::string m_proxy_basic_username;
210+
std::string m_proxy_basic_password;
206211

207212
unsigned int m_ping_interval;
208213
unsigned int m_ping_timeout;

src/sio_client.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ namespace sio
6666
{
6767
m_impl->clear_socket_listeners();
6868
}
69+
70+
void client::set_proxy_basic_auth(const std::string& uri, const std::string& username, const std::string& password)
71+
{
72+
m_impl->set_proxy_basic_auth(uri, username, password);
73+
}
6974

7075
void client::connect(const std::string& uri)
7176
{

src/sio_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ namespace sio
8787

8888
void sync_close();
8989

90+
void set_proxy_basic_auth(const std::string& uri, const std::string& username, const std::string& password);
91+
9092
bool opened() const;
9193

9294
std::string const& get_sessionid() const;

0 commit comments

Comments
 (0)