diff options
author | Yaroslav <electroyar3@gmail.com> | 2021-02-18 21:29:43 +0300 |
---|---|---|
committer | Yaroslav <electroyar3@gmail.com> | 2021-02-18 21:29:43 +0300 |
commit | c9b1ec39e0515684255a740dd84fb7eadcbe7712 (patch) | |
tree | 8b8f58c85453574f044b4a3edef432016410a385 | |
parent | 333f8dd4440e7d51136dd1b92f4eeb0ef2014dc0 (diff) |
added authorization for proxy
-rw-r--r-- | client_ws.hpp | 2 | ||||
-rw-r--r-- | client_wss.hpp | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/client_ws.hpp b/client_ws.hpp index 98df3b8..f56bf3a 100644 --- a/client_ws.hpp +++ b/client_ws.hpp @@ -279,6 +279,8 @@ namespace SimpleWeb { CaseInsensitiveMultimap header; /// Set proxy server (server:port) std::string proxy_server; + /// Set proxy authorization (username:password) + std::string proxy_auth; }; /// Set before calling start(). Config config; diff --git a/client_wss.hpp b/client_wss.hpp index 55ee929..f782179 100644 --- a/client_wss.hpp +++ b/client_wss.hpp @@ -86,8 +86,15 @@ namespace SimpleWeb { auto streambuf = std::make_shared<asio::streambuf>(); std::ostream ostream(streambuf.get()); auto host_port = this->host + ':' + std::to_string(this->port); - ostream << "CONNECT " + host_port + " HTTP/1.1\r\n" - << "Host: " << host_port << "\r\n\r\n"; + if(!this->config.proxy_auth.empty()) { + auto credentials_base64 = std::make_shared<std::string>(Crypto::Base64::encode(this->config.proxy_auth)); + ostream << "CONNECT " + host_port + " HTTP/1.1\r\n" + << "Proxy-Authorization: Basic " << *credentials_base64 << "\r\n" + << "Host: " << host_port << "\r\n\r\n"; + } else { + ostream << "CONNECT " + host_port + " HTTP/1.1\r\n" + << "Host: " << host_port << "\r\n\r\n"; + } connection->set_timeout(this->config.timeout_request); asio::async_write(connection->socket->next_layer(), *streambuf, [this, connection, streambuf](const error_code &ec, std::size_t /*bytes_transferred*/) { connection->cancel_timeout(); |