From c9b1ec39e0515684255a740dd84fb7eadcbe7712 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Thu, 18 Feb 2021 18:29:43 +0000 Subject: added authorization for proxy --- client_ws.hpp | 2 ++ 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(); 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(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(); -- cgit v1.2.3