diff --git a/src/common/http/platform/beast/http.cpp b/src/common/http/platform/beast/http.cpp index 3675fa18a..8b9ef1e7f 100644 --- a/src/common/http/platform/beast/http.cpp +++ b/src/common/http/platform/beast/http.cpp @@ -439,6 +439,21 @@ error::Error Client::AsyncCall( return error::NoError; } +static inline error::Error AddProxyAuthHeader(OutgoingRequest &req, BrokenDownUrl &proxy_address) { + if (proxy_address.username == "") { + // nothing to do + return error::NoError; + } + auto creds = proxy_address.username + ":" + proxy_address.password; + auto ex_encoded_creds = crypto::EncodeBase64(common::ByteVectorFromString(creds)); + if (!ex_encoded_creds) { + return ex_encoded_creds.error(); + } + req.SetHeader("Proxy-Authorization", "Basic " + ex_encoded_creds.value()); + + return error::NoError; +} + error::Error Client::HandleProxySetup() { secondary_req_.reset(); @@ -448,7 +463,7 @@ error::Error Client::HandleProxySetup() { if (http_proxy_ != "" && !HostNameMatchesNoProxy(request_->address_.host, no_proxy_)) { // Make a modified proxy request. BrokenDownUrl proxy_address; - auto err = BreakDownUrl(http_proxy_, proxy_address); + auto err = BreakDownUrl(http_proxy_, proxy_address, true); if (err != error::NoError) { return err.WithContext("HTTP proxy URL is invalid"); } @@ -464,6 +479,11 @@ error::Error Client::HandleProxySetup() { request_->address_.port = proxy_address.port; request_->address_.protocol = proxy_address.protocol; + err = AddProxyAuthHeader(*request_, proxy_address); + if (err != error::NoError) { + return err; + } + if (proxy_address.protocol == "https") { socket_mode_ = SocketMode::Tls; } else if (proxy_address.protocol == "http") { @@ -484,7 +504,7 @@ error::Error Client::HandleProxySetup() { request_ = make_shared(); request_->SetMethod(Method::CONNECT); BrokenDownUrl proxy_address; - auto err = BreakDownUrl(https_proxy_, proxy_address); + auto err = BreakDownUrl(https_proxy_, proxy_address, true); if (err != error::NoError) { return err.WithContext("HTTPS proxy URL is invalid"); } @@ -499,6 +519,11 @@ error::Error Client::HandleProxySetup() { request_->address_.port = proxy_address.port; request_->address_.protocol = proxy_address.protocol; + err = AddProxyAuthHeader(*request_, proxy_address); + if (err != error::NoError) { + return err; + } + if (proxy_address.protocol == "https") { socket_mode_ = SocketMode::Tls; } else if (proxy_address.protocol == "http") {