From 415a7ea5e620c566f6048b5d6f213bab4692412e Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 30 Jun 2022 10:13:26 +0300 Subject: [PATCH] Do not add default port for requests via proxy (fixes GCS via proxy tunnel usage) GCS server does not handle requests with port, and simply report an error: InvalidURI Couldn't parse the specified URI.
Invalid URL: storage.googleapis.com:443/...
Removing the port fixes the issue. Note that there is port in the Host header anyway. Note, this is a problem only for proxy in a tunnel mode, since only it sends such requests, other sends requests directly via HTTP methods. --- Net/src/HTTPClientSession.cpp | 9 +++++++-- NetSSL_OpenSSL/src/HTTPSClientSession.cpp | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Net/src/HTTPClientSession.cpp b/Net/src/HTTPClientSession.cpp index 0fa57689b1..323e9526df 100644 --- a/Net/src/HTTPClientSession.cpp +++ b/Net/src/HTTPClientSession.cpp @@ -429,8 +429,13 @@ std::string HTTPClientSession::proxyRequestPrefix() const { std::string result("http://"); result.append(_host); - result.append(":"); - NumberFormatter::append(result, _port); + /// Do not append default by default, since this may break some servers. + /// One example of such server is GCS (Google Cloud Storage). + if (_port != HTTPSession::HTTP_PORT) + { + result.append(":"); + NumberFormatter::append(result, _port); + } return result; } diff --git a/NetSSL_OpenSSL/src/HTTPSClientSession.cpp b/NetSSL_OpenSSL/src/HTTPSClientSession.cpp index 62b6f6e3ed..91c87bd70b 100644 --- a/NetSSL_OpenSSL/src/HTTPSClientSession.cpp +++ b/NetSSL_OpenSSL/src/HTTPSClientSession.cpp @@ -138,8 +138,13 @@ std::string HTTPSClientSession::proxyRequestPrefix() const { std::string result("https://"); result.append(getHost()); - result.append(":"); - NumberFormatter::append(result, getPort()); + /// Do not append default by default, since this may break some servers. + /// One example of such server is GCS (Google Cloud Storage). + if (getPort() != HTTPS_PORT) + { + result.append(":"); + NumberFormatter::append(result, getPort()); + } return result; }