From df27e71a32ec578a12cb6813bea201c2fce1e097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Tue, 5 Feb 2019 16:30:53 -0500 Subject: [PATCH] proxy: resolve url with protocol and port --- src/dht_proxy_client.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index 4706a5b0..f36e7807 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -527,7 +527,14 @@ DhtProxyClient::getProxyInfos() } statusThread_ = std::thread([this, serverHost, infoState]{ try { - auto hostAndService = splitPort(serverHost); + auto endpointStr = serverHost; + auto protocol = std::string(proxy::HTTP_PROTO); + auto protocolIdx = serverHost.find("://"); + if (protocolIdx != std::string::npos) { + protocol = endpointStr.substr(0, protocolIdx + 3); + endpointStr = endpointStr.substr(protocolIdx + 3); + } + auto hostAndService = splitPort(endpointStr); auto resolved_proxies = SockAddr::resolve(hostAndService.first, hostAndService.second); std::vector<std::future<Sp<restbed::Response>>> reqs; reqs.reserve(resolved_proxies.size()); @@ -536,9 +543,9 @@ DhtProxyClient::getProxyInfos() if (resolved_proxy.getFamily() == AF_INET6) { // HACK restbed seems to not correctly handle directly http://[ipv6] // See https://github.com/Corvusoft/restbed/issues/290. - server = serverHost; + server = endpointStr; } - restbed::Uri uri(proxy::HTTP_PROTO + server + "/"); + restbed::Uri uri(protocol + server + "/"); auto req = std::make_shared<restbed::Request>(uri); if (infoState->cancel) return; -- GitLab