Use the port defined in the URL when setting up the transport adapter usage. (#1611)

* Use the port defined in the URL when setting up the transport adapter usage.

* Fix typo when getting the request object.
This commit is contained in:
Ahson Khan 2021-02-08 16:51:27 -08:00 committed by GitHub
parent 568d4bcc4e
commit 4d3ecf39e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -1148,6 +1148,14 @@ std::unique_ptr<CurlNetworkConnection> CurlConnectionPool::GetCurlConnection(
+ std::string(curl_easy_strerror(result)));
}
uint16_t port = request.GetUrl().GetPort();
if (port != 0 && !SetLibcurlOption(newHandle, CURLOPT_PORT, port, &result))
{
throw Azure::Core::Http::TransportException(
Details::DefaultFailedToGetNewConnectionTemplate + host + ". "
+ std::string(curl_easy_strerror(result)));
}
if (!SetLibcurlOption(newHandle, CURLOPT_CONNECT_ONLY, 1L, &result))
{
throw Azure::Core::Http::TransportException(

View File

@ -208,13 +208,15 @@ void WinHttpTransport::CreateSessionHandle(std::unique_ptr<Details::HandleManage
void WinHttpTransport::CreateConnectionHandle(
std::unique_ptr<Details::HandleManager>& handleManager)
{
// If port is 0, i.e. INTERNET_DEFAULT_PORT, it uses port 80 for HTTP and port 443 for HTTPS.
uint16_t port = handleManager->m_request.GetUrl().GetPort();
// Specify an HTTP server.
// Uses port 80 for HTTP and port 443 for HTTPS.
// This function always operates synchronously.
handleManager->m_connectionHandle = WinHttpConnect(
handleManager->m_sessionHandle,
StringToWideString(handleManager->m_request.GetUrl().GetHost()).c_str(),
INTERNET_DEFAULT_PORT,
port == 0 ? INTERNET_DEFAULT_PORT : port,
0);
if (!handleManager->m_connectionHandle)

View File

@ -205,8 +205,16 @@ namespace Azure { namespace Core { namespace Test {
TEST(URL, getPortAfterSet)
{
Http::Url url("http://test.com");
uint16_t expected = 0;
EXPECT_PRED2(
[](uint16_t expectedValue, uint16_t code) { return expectedValue == code; },
url.GetPort(),
expected);
url.SetPort(40);
uint16_t expected = 40;
expected = 40;
EXPECT_PRED2(
[](uint16_t expectedValue, uint16_t code) { return expectedValue == code; },