diff --git a/src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp b/src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp index a573cb0155d..946cbfc005b 100644 --- a/src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp +++ b/src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp @@ -129,10 +129,12 @@ static char* strdup_callback(const char* str) struct CurlWriteCallbackContext { CurlWriteCallbackContext(const CurlHttpClient* client, + CURL* curlHandle, HttpRequest* request, HttpResponse* response, Aws::Utils::RateLimits::RateLimiterInterface* rateLimiter) : m_client(client), + m_curlHandle(curlHandle), m_request(request), m_response(response), m_rateLimiter(rateLimiter), @@ -140,6 +142,7 @@ struct CurlWriteCallbackContext {} const CurlHttpClient* m_client; + CURL* m_curlHandle{nullptr}; HttpRequest* m_request; HttpResponse* m_response; Aws::Utils::RateLimits::RateLimiterInterface* m_rateLimiter; @@ -187,7 +190,6 @@ static size_t WriteData(char* ptr, size_t size, size_t nmemb, void* userdata) { if (ptr) { - std::cout<<"WriteData called"<(userdata); @@ -264,7 +266,6 @@ static size_t WriteHeader(char* ptr, size_t size, size_t nmemb, void* userdata) { if (ptr) { - std::cout<<"WriteHeader called"<(userdata); AWS_LOGSTREAM_TRACE(CURL_HTTP_CLIENT_TAG, ptr); HttpResponse* response = context->m_response; @@ -275,6 +276,14 @@ static size_t WriteHeader(char* ptr, size_t size, size_t nmemb, void* userdata) { response->AddHeader(StringUtils::Trim(keyValuePair[0].c_str()), StringUtils::Trim(keyValuePair[1].c_str())); } + //checking for end of all the headers before setting response code + else if (headerLine == "\r\n") + { + long responseCode{-1}; + curl_easy_getinfo(context->m_curlHandle, CURLINFO_RESPONSE_CODE, &responseCode); + response->SetResponseCode(static_cast(responseCode)); + AWS_LOGSTREAM_DEBUG(CURL_HTTP_CLIENT_TAG, "Returned http response code " << responseCode); + } return size * nmemb; } @@ -686,7 +695,7 @@ std::shared_ptr CurlHttpClient::MakeRequest(const std::shared_ptr< curl_easy_setopt(connectionHandle, CURLOPT_HTTPHEADER, headers); } - CurlWriteCallbackContext writeContext(this, request.get(), response.get(), readLimiter); + CurlWriteCallbackContext writeContext(this, connectionHandle ,request.get(), response.get(), readLimiter); const auto readContext = [this, &connectionHandle, &request, &writeLimiter]() -> CurlReadCallbackContext { if (request->GetContentBody() != nullptr) { @@ -832,9 +841,7 @@ std::shared_ptr CurlHttpClient::MakeRequest(const std::shared_ptr< OverrideOptionsOnConnectionHandle(connectionHandle); Aws::Utils::DateTime startTransmissionTime = Aws::Utils::DateTime::Now(); - std::cout<<"curl_easy_perform starting"< client = Aws::MakeShared("test",configuration); - const String fullBucketName = CalculateBucketName(BASE_CONTENT_ENCODING_BUCKET_NAME.c_str()); CreateBucketRequest createBucketRequest; createBucketRequest.SetBucket(fullBucketName); @@ -2596,11 +2595,9 @@ namespace CreateBucketOutcome createBucketOutcome = CreateBucket(createBucketRequest,client); AWS_EXPECT_SUCCESS(createBucketOutcome); - Aws::S3::Model::GetObjectRequest request; request.SetBucket(fullBucketName); request.SetKey("one_object_that_does_not_exist_in_the_bucket"); // <== we should get 404 when calling GetResponseCode - request.SetHeadersReceivedEventHandler ( [] ( const Aws::Http::HttpRequest * , @@ -2608,22 +2605,14 @@ namespace ) { ::std::cout << "response headers received: " << response->GetResponseCode ( ) - << ::std::endl; // <== current implementation is always "response headers received: -1" + << ::std::endl; + EXPECT_EQ(response->GetResponseCode(), Aws::Http::HttpResponseCode::NOT_FOUND ); } ); Aws::S3::Model::GetObjectOutcome outcome = client->GetObject(request); + EXPECT_FALSE(outcome.IsSuccess()); - if (!outcome.IsSuccess()) { - const Aws::S3::S3Error &err = outcome.GetError(); - std::cerr << "Error: getObject: " << - err.GetExceptionName() << ": " << err.GetMessage() << std::endl; - } else { - std::cout << "Successfully retrieved from '" - << fullBucketName << "'." << std::endl; - } - - AWS_EXPECT_SUCCESS(outcome); } }