diff --git a/sdk/core/azure-core/src/http/curl/curl.cpp b/sdk/core/azure-core/src/http/curl/curl.cpp index e7d1ccd19..f8467e0cc 100644 --- a/sdk/core/azure-core/src/http/curl/curl.cpp +++ b/sdk/core/azure-core/src/http/curl/curl.cpp @@ -557,6 +557,12 @@ CURLcode CurlConnection::SendBuffer( size_t bufferSize, Context const& context) { + // Once you've shutdown the connection, we can't send any more data (although we can continue to + // receive). + if (IsShutdown()) + { + return CURLE_SEND_ERROR; + } for (size_t sentBytesTotal = 0; sentBytesTotal < bufferSize;) { // check cancelation for each chunk of data. @@ -1065,16 +1071,6 @@ size_t CurlSession::OnRead(uint8_t* buffer, size_t count, Context const& context return totalRead; } -void CurlConnection::Shutdown() -{ -#if defined(AZ_PLATFORM_POSIX) - ::shutdown(m_curlSocket, SHUT_RDWR); -#elif defined(AZ_PLATFORM_WINDOWS) - ::shutdown(m_curlSocket, SD_BOTH); -#endif - CurlNetworkConnection::Shutdown(); -} - // Read from socket and return the number of bytes taken from socket size_t CurlConnection::ReadFromSocket(uint8_t* buffer, size_t bufferSize, Context const& context) { diff --git a/sdk/core/azure-core/src/http/curl/curl_connection_private.hpp b/sdk/core/azure-core/src/http/curl/curl_connection_private.hpp index 019dea9e7..ce6354a6c 100644 --- a/sdk/core/azure-core/src/http/curl/curl_connection_private.hpp +++ b/sdk/core/azure-core/src/http/curl/curl_connection_private.hpp @@ -230,8 +230,6 @@ namespace Azure { namespace Core { */ CURLcode SendBuffer(uint8_t const* buffer, size_t bufferSize, Context const& context) override; - - void Shutdown() override; }; } // namespace Http }} // namespace Azure::Core diff --git a/sdk/core/azure-core/test/ut/curl_connection_pool_test.cpp b/sdk/core/azure-core/test/ut/curl_connection_pool_test.cpp index 6ec133b8a..a02b2eec1 100644 --- a/sdk/core/azure-core/test/ut/curl_connection_pool_test.cpp +++ b/sdk/core/azure-core/test/ut/curl_connection_pool_test.cpp @@ -601,6 +601,29 @@ namespace Azure { namespace Core { namespace Test { } } + TEST(CurlConnectionPool, forceConnectionClosed) + { + Azure::Core::Http::Request req( + Azure::Core::Http::HttpMethod::Get, Azure::Core::Url(AzureSdkHttpbinServer::Status(101))); + + Azure::Core::Http::CurlTransportOptions options; + auto connection + = CurlConnectionPool::g_curlConnectionPool.ExtractOrCreateCurlConnection(req, options); + + { + // Check we can use the connection to retrieve headers in the response, but the connection + // is still flagged as shutdown. + auto session + = std::make_unique(req, std::move(connection), options); + + auto r = session->Perform(Azure::Core::Context::ApplicationContext); + EXPECT_EQ(CURLE_OK, r); + auto response = session->ExtractResponse(); + EXPECT_EQ(response->GetStatusCode(), Azure::Core::Http::HttpStatusCode::SwitchingProtocols); + EXPECT_EQ("close", response->GetHeaders().find("Connection")->second); + } + } + TEST(CurlConnectionPool, connectionClose) { /// When getting the header connection: close from an HTTP response, the connection should not diff --git a/sdk/core/azure-core/test/ut/transport_adapter_base_test.hpp b/sdk/core/azure-core/test/ut/transport_adapter_base_test.hpp index 6c357ce9f..768ba5117 100644 --- a/sdk/core/azure-core/test/ut/transport_adapter_base_test.hpp +++ b/sdk/core/azure-core/test/ut/transport_adapter_base_test.hpp @@ -33,6 +33,10 @@ namespace Azure { namespace Core { namespace Test { inline static std::string Delete() { return Schema() + "://" + Host() + "/delete"; } inline static std::string Patch() { return Schema() + "://" + Host() + "/patch"; } inline static std::string Delay() { return Schema() + "://" + Host() + "/delay"; } + inline static std::string Status(int statusCode) + { + return Schema() + "://" + Host() + "/status/" + std::to_string(statusCode); + } inline static std::string Host() { return std::string(_detail::AzureSdkHttpbinServer); } inline static std::string Schema() { return std::string(_detail::AzureSdkHttpbinServerSchema); } };