Skip to content

Commit 967f6a2

Browse files
committed
Fix some proxy usage corner cases
1 parent fb22c59 commit 967f6a2

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/RequestImpl.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ class RequestImpl : public Request {
596596
tuple<string, string> GetRequestEndpoint() {
597597
const auto proxy_type = properties_->proxy.type;
598598

599+
//https connections via http proxy is not possible
600+
assert(!(proxy_type == Request::Proxy::Type::HTTP
601+
&& parsed_url_.GetProtocol() == Url::Protocol::HTTPS));
602+
599603
if (proxy_type == Request::Proxy::Type::SOCKS5) {
600604
string host;
601605
uint16_t port = 0;
@@ -608,10 +612,9 @@ class RequestImpl : public Request {
608612
return { host, to_string(port) };
609613
}
610614

611-
if ( (proxy_type == Request::Proxy::Type::HTTP &&
612-
parsed_url_.GetProtocol() == Url::Protocol::HTTP) ||
613-
(proxy_type == Request::Proxy::Type::HTTPS &&
614-
parsed_url_.GetProtocol() == Url::Protocol::HTTPS) ) {
615+
if ( (proxy_type == Request::Proxy::Type::HTTP
616+
&& parsed_url_.GetProtocol() == Url::Protocol::HTTP)
617+
|| proxy_type == Request::Proxy::Type::HTTPS ) {
615618
Url proxy {properties_->proxy.address.c_str()};
616619

617620
RESTC_CPP_LOG_TRACE_("Using " << properties_->proxy.GetName()
@@ -726,7 +729,8 @@ class RequestImpl : public Request {
726729

727730
const Connection::Type protocol_type =
728731
(parsed_url_.GetProtocol() == Url::Protocol::HTTPS ||
729-
properties_->proxy.type == Request::Proxy::Type::HTTPS)
732+
(properties_->proxy.type == Request::Proxy::Type::HTTPS
733+
&& parsed_url_.GetProtocol() == Url::Protocol::HTTPS))
730734
? Connection::Type::HTTPS
731735
: Connection::Type::HTTP;
732736

@@ -861,6 +865,15 @@ class RequestImpl : public Request {
861865
<< ex.what()
862866
<< "\" while connecting to " << endpoint);
863867
break; // Go to the next endpoint
868+
} catch(const RequestFailedWithErrorException& ex) {
869+
RESTC_CPP_LOG_WARN_("Connect to "
870+
<< endpoint
871+
<< " failed with HTTP protocol exception type: "
872+
<< typeid(ex).name()
873+
<< ", message: " << ex.what());
874+
875+
connection->GetSocket().GetSocket().close();
876+
break; // Go to the next endpoint
864877
} catch(const exception& ex) {
865878
RESTC_CPP_LOG_WARN_("Connect to "
866879
<< endpoint

0 commit comments

Comments
 (0)