mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-30 13:00:42 +00:00
Add set_basic_auth and set_bearer_token_auth to WebSocketClient (#2652)
ClientImpl and SSLClient let callers set origin credentials with set_basic_auth()/set_bearer_token_auth(), but WebSocketClient could only take a fixed Authorization header through its constructor. Add both setters: each connect() adds the Authorization header to the upgrade request from the current credentials (Basic over Bearer), unless the constructor headers already carry one, and never to the proxy's CONNECT request.
This commit is contained in:
1 parent
290c4c0bbe
commit
a0ab09fc0a
3 files changed
+157
No files matched your search
@@ -4768,6 +4768,9 @@ public:
|
||||
void
|
||||
set_tunnel_hostname_addr_map(std::map<std::string, std::string> addr_map);
|
||||
|
||||
void set_basic_auth(const std::string &username, const std::string &password);
|
||||
void set_bearer_token_auth(const std::string &token);
|
||||
|
||||
void set_proxy(const std::string &host, int port);
|
||||
void set_proxy_basic_auth(const std::string &username,
|
||||
const std::string &password);
|
||||
@@ -4841,6 +4844,10 @@ private:
|
||||
// Hostname to CONNECT target map, used only through a proxy.
|
||||
std::map<std::string, std::string> tunnel_addr_map_;
|
||||
|
||||
std::string basic_auth_username_;
|
||||
std::string basic_auth_password_;
|
||||
std::string bearer_token_auth_token_;
|
||||
|
||||
std::string proxy_host_;
|
||||
int proxy_port_ = -1;
|
||||
std::string proxy_basic_auth_username_;
|
||||
@@ -23990,6 +23997,9 @@ inline void WebSocketClient::prepare_default_headers(Request &req) {
|
||||
}
|
||||
|
||||
detail::add_default_user_agent_header(req);
|
||||
detail::add_authorization_header(req, basic_auth_username_,
|
||||
basic_auth_password_,
|
||||
bearer_token_auth_token_, false);
|
||||
}
|
||||
|
||||
inline Result WebSocketClient::connect() {
|
||||
@@ -24212,6 +24222,16 @@ inline bool WebSocketClient::connect_with_proxy(Response &proxy_res,
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void WebSocketClient::set_basic_auth(const std::string &username,
|
||||
const std::string &password) {
|
||||
basic_auth_username_ = username;
|
||||
basic_auth_password_ = password;
|
||||
}
|
||||
|
||||
inline void WebSocketClient::set_bearer_token_auth(const std::string &token) {
|
||||
bearer_token_auth_token_ = token;
|
||||
}
|
||||
|
||||
inline void WebSocketClient::set_proxy(const std::string &host, int port) {
|
||||
proxy_host_ = host;
|
||||
proxy_port_ = port;
|
||||
|
||||
Reference in new issue
Block a user