diff --git a/sdk/core/azure-core/src/http/curl/curl.cpp b/sdk/core/azure-core/src/http/curl/curl.cpp index 02bf70a8e..1c97d4bf4 100644 --- a/sdk/core/azure-core/src/http/curl/curl.cpp +++ b/sdk/core/azure-core/src/http/curl/curl.cpp @@ -19,13 +19,11 @@ std::unique_ptr CurlTransport::Send(Context const& context, Request { switch (performing) { - case CURLE_COULDNT_RESOLVE_HOST: - { + case CURLE_COULDNT_RESOLVE_HOST: { throw Azure::Core::Http::CouldNotResolveHostException( "Could not resolve host " + request.GetHost()); } - default: - { + default: { throw Azure::Core::Http::TransportException( "Error while sending request. " + std::string(curl_easy_strerror(performing))); } @@ -377,7 +375,10 @@ void CurlSession::ReadStatusLineAndHeadersFromRawResponse() // For Head request, set the length of body response to 0. // Response will give us content-length as if we were not doing Head saying what would it be the // length of the body. However, Server won't send body - if (this->m_request.GetMethod() == HttpMethod::Head) + // For NoContent status code, also need to set conentLength to 0. + // https://github.com/Azure/azure-sdk-for-cpp/issues/406 + if (this->m_request.GetMethod() == HttpMethod::Head + || this->m_response->GetStatusCode() == Azure::Core::Http::HttpStatusCode::NoContent) { this->m_contentLength = 0; this->m_bodyStartInBuffer = -1; diff --git a/sdk/core/azure-core/test/ut/transport_adapter.cpp b/sdk/core/azure-core/test/ut/transport_adapter.cpp index bb586b648..704015821 100644 --- a/sdk/core/azure-core/test/ut/transport_adapter.cpp +++ b/sdk/core/azure-core/test/ut/transport_adapter.cpp @@ -42,6 +42,17 @@ namespace Azure { namespace Core { namespace Test { CheckBodyFromBuffer(*response, expectedResponseBodySize + 6 + 13); } + TEST_F(TransportAdapter, get204) + { + std::string host("http://mt3.google.com/generate_204"); + + auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host); + auto response = pipeline.Send(context, request); + checkResponseCode(response->GetStatusCode(), Azure::Core::Http::HttpStatusCode::NoContent); + auto expectedResponseBodySize = std::stoull(response->GetHeaders().at("content-length")); + CheckBodyFromBuffer(*response, expectedResponseBodySize); + } + TEST_F(TransportAdapter, getLoop) { std::string host("http://httpbin.org/get");