@@ -327,6 +327,10 @@ void DoProxyConnect(const Connection::ptr_t& connection,
327
327
328
328
// sets status_code, reason_phrase in response
329
329
stream->ReadServerResponse (proxy_response);
330
+ stream->ReadHeaderLines (
331
+ [](std::string&& name, std::string&& value) {
332
+ RESTC_CPP_LOG_TRACE_ (" Read proxy header: " << name);
333
+ });
330
334
331
335
} catch (const exception& ex) {
332
336
RESTC_CPP_LOG_DEBUG_ (" DoProxyConnect: exception from ReceivingFromProxy: " << ex.what ());
@@ -614,8 +618,8 @@ class RequestImpl : public Request {
614
618
return request_buffer.str ();
615
619
}
616
620
617
- // returns {protocol_type, host, service} instead of deprecated ip::resolver::query
618
- tuple<Connection::Type, string, string> GetRequestEndpoint () {
621
+ // returns {host, service} instead of deprecated ip::resolver::query
622
+ tuple<string, string> GetRequestEndpoint () {
619
623
const auto proxy_type = properties_->proxy .type ;
620
624
621
625
if (proxy_type == Request::Proxy::Type::SOCKS5) {
@@ -627,11 +631,7 @@ class RequestImpl : public Request {
627
631
<< " Proxy at: "
628
632
<< host << ' :' << port);
629
633
630
- // what connection type should we use for SOCKS tunnel?
631
- return { (parsed_url_.GetProtocol () == Url::Protocol::HTTPS)
632
- ? Connection::Type::HTTPS
633
- : Connection::Type::HTTP,
634
- host, to_string (port) };
634
+ return { host, to_string (port) };
635
635
}
636
636
637
637
if ( (proxy_type == Request::Proxy::Type::HTTP &&
@@ -645,17 +645,11 @@ class RequestImpl : public Request {
645
645
<< " Proxy at: "
646
646
<< proxy.GetHost () << ' :' << proxy.GetPort ());
647
647
648
- return { (proxy.GetProtocol () == Url::Protocol::HTTPS)
649
- ? Connection::Type::HTTPS
650
- : Connection::Type::HTTP,
651
- proxy.GetHost ().to_string (),
648
+ return { proxy.GetHost ().to_string (),
652
649
proxy.GetPort ().to_string () };
653
650
}
654
651
655
- return { (parsed_url_.GetProtocol () == Url::Protocol::HTTPS)
656
- ? Connection::Type::HTTPS
657
- : Connection::Type::HTTP,
658
- parsed_url_.GetHost ().to_string (),
652
+ return { parsed_url_.GetHost ().to_string (),
659
653
parsed_url_.GetPort ().to_string () };
660
654
}
661
655
@@ -756,15 +750,21 @@ class RequestImpl : public Request {
756
750
757
751
auto prot_filter = GetBindProtocols (properties_->bindToLocalAddress , ctx);
758
752
753
+ const Connection::Type protocol_type =
754
+ (parsed_url_.GetProtocol () == Url::Protocol::HTTPS ||
755
+ properties_->proxy .type == Request::Proxy::Type::HTTPS)
756
+ ? Connection::Type::HTTPS
757
+ : Connection::Type::HTTP;
758
+
759
759
boost::asio::ip::tcp::resolver resolver (owner_.GetIoService ());
760
760
// Resolve the hostname
761
- const auto ep_tuple = GetRequestEndpoint (); // {protocol_type, host, service=port}
761
+ const auto ep_tuple = GetRequestEndpoint (); // {host, service=port}
762
762
763
- RESTC_CPP_LOG_TRACE_ (" Resolving " << get<1 >(ep_tuple) << " :"
764
- << get<2 >(ep_tuple));
763
+ RESTC_CPP_LOG_TRACE_ (" Resolving " << get<0 >(ep_tuple) << " :"
764
+ << get<1 >(ep_tuple));
765
765
766
- auto address_it = resolver.async_resolve (/* host*/ get<1 >(ep_tuple),
767
- /* port*/ get<2 >(ep_tuple),
766
+ auto address_it = resolver.async_resolve (/* host*/ get<0 >(ep_tuple),
767
+ /* port*/ get<1 >(ep_tuple),
768
768
ctx.GetYield ());
769
769
const decltype (address_it) addr_end;
770
770
@@ -781,7 +781,7 @@ class RequestImpl : public Request {
781
781
for (size_t retries = 0 ; retries < 8 ; ++retries) {
782
782
// Get a connection from the pool
783
783
auto connection = owner_.GetConnectionPool ()->GetConnection (
784
- endpoint, /* protocol_type*/ get< 0 >(ep_tuple) );
784
+ endpoint, protocol_type);
785
785
786
786
// Connect if the connection is new.
787
787
if (connection->GetSocket ().IsOpen ()) {
0 commit comments