diff options
author | nalpp <nalpp@yandex-team.ru> | 2022-02-10 16:46:45 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:45 +0300 |
commit | 87f3eb38999df2d3c1cb77f8ffb9c52ec9c516fb (patch) | |
tree | f4ab0734eecf35b22f21952d1aa15496f267a6a3 /contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client | |
parent | 198698b9c1e18958addc9682fbfba4576d604757 (diff) | |
download | ydb-87f3eb38999df2d3c1cb77f8ffb9c52ec9c516fb.tar.gz |
Restoring authorship annotation for <nalpp@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client')
6 files changed, 893 insertions, 893 deletions
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp index e1ff064840..0a1d9e6388 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp @@ -1,75 +1,75 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/core/client/AWSClient.h> -#include <aws/core/AmazonWebServiceRequest.h> -#include <aws/core/auth/AWSAuthSigner.h> -#include <aws/core/auth/AWSAuthSignerProvider.h> -#include <aws/core/client/AWSError.h> -#include <aws/core/client/AWSErrorMarshaller.h> -#include <aws/core/client/ClientConfiguration.h> -#include <aws/core/client/CoreErrors.h> -#include <aws/core/client/RetryStrategy.h> -#include <aws/core/http/HttpClient.h> -#include <aws/core/http/HttpClientFactory.h> -#include <aws/core/http/HttpResponse.h> -#include <aws/core/http/standard/StandardHttpResponse.h> + */ + +#include <aws/core/client/AWSClient.h> +#include <aws/core/AmazonWebServiceRequest.h> +#include <aws/core/auth/AWSAuthSigner.h> +#include <aws/core/auth/AWSAuthSignerProvider.h> +#include <aws/core/client/AWSError.h> +#include <aws/core/client/AWSErrorMarshaller.h> +#include <aws/core/client/ClientConfiguration.h> +#include <aws/core/client/CoreErrors.h> +#include <aws/core/client/RetryStrategy.h> +#include <aws/core/http/HttpClient.h> +#include <aws/core/http/HttpClientFactory.h> +#include <aws/core/http/HttpResponse.h> +#include <aws/core/http/standard/StandardHttpResponse.h> #include <aws/core/http/URI.h> -#include <aws/core/utils/stream/ResponseStream.h> -#include <aws/core/utils/json/JsonSerializer.h> -#include <aws/core/utils/Outcome.h> -#include <aws/core/utils/StringUtils.h> -#include <aws/core/utils/xml/XmlSerializer.h> -#include <aws/core/utils/memory/stl/AWSStringStream.h> -#include <aws/core/utils/logging/LogMacros.h> -#include <aws/core/Globals.h> -#include <aws/core/utils/EnumParseOverflowContainer.h> -#include <aws/core/utils/crypto/MD5.h> -#include <aws/core/utils/HashingUtils.h> -#include <aws/core/utils/crypto/Factories.h> +#include <aws/core/utils/stream/ResponseStream.h> +#include <aws/core/utils/json/JsonSerializer.h> +#include <aws/core/utils/Outcome.h> +#include <aws/core/utils/StringUtils.h> +#include <aws/core/utils/xml/XmlSerializer.h> +#include <aws/core/utils/memory/stl/AWSStringStream.h> +#include <aws/core/utils/logging/LogMacros.h> +#include <aws/core/Globals.h> +#include <aws/core/utils/EnumParseOverflowContainer.h> +#include <aws/core/utils/crypto/MD5.h> +#include <aws/core/utils/HashingUtils.h> +#include <aws/core/utils/crypto/Factories.h> #include <aws/core/utils/event/EventStream.h> #include <aws/core/utils/UUID.h> -#include <aws/core/monitoring/MonitoringManager.h> +#include <aws/core/monitoring/MonitoringManager.h> #include <aws/core/Region.h> #include <aws/core/utils/DNS.h> #include <aws/core/Version.h> #include <aws/core/platform/OSVersionInfo.h> - + #include <cstring> #include <cassert> -using namespace Aws; -using namespace Aws::Client; -using namespace Aws::Http; -using namespace Aws::Utils; -using namespace Aws::Utils::Json; -using namespace Aws::Utils::Xml; - -static const int SUCCESS_RESPONSE_MIN = 200; -static const int SUCCESS_RESPONSE_MAX = 299; - -static const char AWS_CLIENT_LOG_TAG[] = "AWSClient"; -//4 Minutes +using namespace Aws; +using namespace Aws::Client; +using namespace Aws::Http; +using namespace Aws::Utils; +using namespace Aws::Utils::Json; +using namespace Aws::Utils::Xml; + +static const int SUCCESS_RESPONSE_MIN = 200; +static const int SUCCESS_RESPONSE_MAX = 299; + +static const char AWS_CLIENT_LOG_TAG[] = "AWSClient"; +//4 Minutes static const std::chrono::milliseconds TIME_DIFF_MAX = std::chrono::minutes(4); -//-4 Minutes -static const std::chrono::milliseconds TIME_DIFF_MIN = std::chrono::minutes(-4); - -static CoreErrors GuessBodylessErrorType(Aws::Http::HttpResponseCode responseCode) -{ - switch (responseCode) - { - case HttpResponseCode::FORBIDDEN: - case HttpResponseCode::UNAUTHORIZED: - return CoreErrors::ACCESS_DENIED; - case HttpResponseCode::NOT_FOUND: - return CoreErrors::RESOURCE_NOT_FOUND; - default: - return CoreErrors::UNKNOWN; +//-4 Minutes +static const std::chrono::milliseconds TIME_DIFF_MIN = std::chrono::minutes(-4); + +static CoreErrors GuessBodylessErrorType(Aws::Http::HttpResponseCode responseCode) +{ + switch (responseCode) + { + case HttpResponseCode::FORBIDDEN: + case HttpResponseCode::UNAUTHORIZED: + return CoreErrors::ACCESS_DENIED; + case HttpResponseCode::NOT_FOUND: + return CoreErrors::RESOURCE_NOT_FOUND; + default: + return CoreErrors::UNKNOWN; } -} - +} + struct RequestInfo { Aws::Utils::DateTime ttl; @@ -93,44 +93,44 @@ struct RequestInfo } }; -AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration, - const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer, - const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : +AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration, + const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer, + const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : m_region(configuration.region), - m_httpClient(CreateHttpClient(configuration)), - m_signerProvider(Aws::MakeUnique<Aws::Auth::DefaultAuthSignerProvider>(AWS_CLIENT_LOG_TAG, signer)), - m_errorMarshaller(errorMarshaller), - m_retryStrategy(configuration.retryStrategy), - m_writeRateLimiter(configuration.writeRateLimiter), - m_readRateLimiter(configuration.readRateLimiter), - m_userAgent(configuration.userAgent), + m_httpClient(CreateHttpClient(configuration)), + m_signerProvider(Aws::MakeUnique<Aws::Auth::DefaultAuthSignerProvider>(AWS_CLIENT_LOG_TAG, signer)), + m_errorMarshaller(errorMarshaller), + m_retryStrategy(configuration.retryStrategy), + m_writeRateLimiter(configuration.writeRateLimiter), + m_readRateLimiter(configuration.readRateLimiter), + m_userAgent(configuration.userAgent), m_customizedUserAgent(!m_userAgent.empty()), - m_hash(Aws::Utils::Crypto::CreateMD5Implementation()), + m_hash(Aws::Utils::Crypto::CreateMD5Implementation()), m_requestTimeoutMs(configuration.requestTimeoutMs), - m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment) -{ + m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment) +{ SetServiceClientName("AWSBaseClient"); -} - -AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration, - const std::shared_ptr<Aws::Auth::AWSAuthSignerProvider>& signerProvider, - const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : +} + +AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration, + const std::shared_ptr<Aws::Auth::AWSAuthSignerProvider>& signerProvider, + const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : m_region(configuration.region), - m_httpClient(CreateHttpClient(configuration)), - m_signerProvider(signerProvider), - m_errorMarshaller(errorMarshaller), - m_retryStrategy(configuration.retryStrategy), - m_writeRateLimiter(configuration.writeRateLimiter), - m_readRateLimiter(configuration.readRateLimiter), - m_userAgent(configuration.userAgent), + m_httpClient(CreateHttpClient(configuration)), + m_signerProvider(signerProvider), + m_errorMarshaller(errorMarshaller), + m_retryStrategy(configuration.retryStrategy), + m_writeRateLimiter(configuration.writeRateLimiter), + m_readRateLimiter(configuration.readRateLimiter), + m_userAgent(configuration.userAgent), m_customizedUserAgent(!m_userAgent.empty()), - m_hash(Aws::Utils::Crypto::CreateMD5Implementation()), + m_hash(Aws::Utils::Crypto::CreateMD5Implementation()), m_requestTimeoutMs(configuration.requestTimeoutMs), - m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment) -{ + m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment) +{ SetServiceClientName("AWSBaseClient"); -} - +} + void AWSClient::SetServiceClientName(const Aws::String& name) { m_serviceName = name; @@ -141,8 +141,8 @@ void AWSClient::SetServiceClientName(const Aws::String& name) << " " << Version::GetCompilerVersionString(); m_userAgent = ss.str(); } -} - +} + void AWSClient::DisableRequestProcessing() { m_httpClient->DisableRequestProcessing(); @@ -150,15 +150,15 @@ void AWSClient::DisableRequestProcessing() void AWSClient::EnableRequestProcessing() { - m_httpClient->EnableRequestProcessing(); -} - -Aws::Client::AWSAuthSigner* AWSClient::GetSignerByName(const char* name) const -{ - const auto& signer = m_signerProvider->GetSigner(name); - return signer ? signer.get() : nullptr; -} - + m_httpClient->EnableRequestProcessing(); +} + +Aws::Client::AWSAuthSigner* AWSClient::GetSignerByName(const char* name) const +{ + const auto& signer = m_signerProvider->GetSigner(name); + return signer ? signer.get() : nullptr; +} + static DateTime GetServerTimeFromError(const AWSError<CoreErrors> error) { const Http::HeaderValueCollection& headers = error.GetResponseHeaders(); @@ -178,60 +178,60 @@ static DateTime GetServerTimeFromError(const AWSError<CoreErrors> error) } } -bool AWSClient::AdjustClockSkew(HttpResponseOutcome& outcome, const char* signerName) const -{ - if (m_enableClockSkewAdjustment) - { - auto signer = GetSignerByName(signerName); +bool AWSClient::AdjustClockSkew(HttpResponseOutcome& outcome, const char* signerName) const +{ + if (m_enableClockSkewAdjustment) + { + auto signer = GetSignerByName(signerName); //detect clock skew and try to correct. - AWS_LOGSTREAM_WARN(AWS_CLIENT_LOG_TAG, "If the signature check failed. This could be because of a time skew. Attempting to adjust the signer."); - + AWS_LOGSTREAM_WARN(AWS_CLIENT_LOG_TAG, "If the signature check failed. This could be because of a time skew. Attempting to adjust the signer."); + DateTime serverTime = GetServerTimeFromError(outcome.GetError()); - const auto signingTimestamp = signer->GetSigningTimestamp(); - if (!serverTime.WasParseSuccessful() || serverTime == DateTime()) - { - AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Date header was not found in the response, can't attempt to detect clock skew"); - return false; - } - - AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Server time is " << serverTime.ToGmtString(DateFormat::RFC822) << ", while client time is " << DateTime::Now().ToGmtString(DateFormat::RFC822)); - auto diff = DateTime::Diff(serverTime, signingTimestamp); - //only try again if clock skew was the cause of the error. - if (diff >= TIME_DIFF_MAX || diff <= TIME_DIFF_MIN) - { - diff = DateTime::Diff(serverTime, DateTime::Now()); - AWS_LOGSTREAM_INFO(AWS_CLIENT_LOG_TAG, "Computed time difference as " << diff.count() << " milliseconds. Adjusting signer with the skew."); - signer->SetClockSkew(diff); + const auto signingTimestamp = signer->GetSigningTimestamp(); + if (!serverTime.WasParseSuccessful() || serverTime == DateTime()) + { + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Date header was not found in the response, can't attempt to detect clock skew"); + return false; + } + + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Server time is " << serverTime.ToGmtString(DateFormat::RFC822) << ", while client time is " << DateTime::Now().ToGmtString(DateFormat::RFC822)); + auto diff = DateTime::Diff(serverTime, signingTimestamp); + //only try again if clock skew was the cause of the error. + if (diff >= TIME_DIFF_MAX || diff <= TIME_DIFF_MIN) + { + diff = DateTime::Diff(serverTime, DateTime::Now()); + AWS_LOGSTREAM_INFO(AWS_CLIENT_LOG_TAG, "Computed time difference as " << diff.count() << " milliseconds. Adjusting signer with the skew."); + signer->SetClockSkew(diff); AWSError<CoreErrors> newError( - outcome.GetError().GetErrorType(), outcome.GetError().GetExceptionName(), outcome.GetError().GetMessage(), true); - newError.SetResponseHeaders(outcome.GetError().GetResponseHeaders()); - newError.SetResponseCode(outcome.GetError().GetResponseCode()); + outcome.GetError().GetErrorType(), outcome.GetError().GetExceptionName(), outcome.GetError().GetMessage(), true); + newError.SetResponseHeaders(outcome.GetError().GetResponseHeaders()); + newError.SetResponseCode(outcome.GetError().GetResponseCode()); outcome = std::move(newError); - return true; - } - } - return false; -} - -HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, - const Aws::AmazonWebServiceRequest& request, - HttpMethod method, + return true; + } + } + return false; +} + +HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, + const Aws::AmazonWebServiceRequest& request, + HttpMethod method, const char* signerName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ +{ if (!Aws::Utils::IsValidHost(uri.GetAuthority())) { return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::VALIDATION, "", "Invalid DNS Label found in URI host", false/*retryable*/)); } - std::shared_ptr<HttpRequest> httpRequest(CreateHttpRequest(uri, method, request.GetResponseStreamFactory())); - HttpResponseOutcome outcome; + std::shared_ptr<HttpRequest> httpRequest(CreateHttpRequest(uri, method, request.GetResponseStreamFactory())); + HttpResponseOutcome outcome; AWSError<CoreErrors> lastError; - Aws::Monitoring::CoreMetricsCollection coreMetrics; - auto contexts = Aws::Monitoring::OnRequestStarted(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest); + Aws::Monitoring::CoreMetricsCollection coreMetrics; + auto contexts = Aws::Monitoring::OnRequestStarted(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest); const char* signerRegion = signerRegionOverride; Aws::String regionFromResponse; - + Aws::String invocationId = UUID::RandomUUID(); RequestInfo requestInfo; requestInfo.attempt = 1; @@ -239,8 +239,8 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, httpRequest->SetHeaderValue(Http::SDK_INVOCATION_ID_HEADER, invocationId); httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); - for (long retries = 0;; retries++) - { + for (long retries = 0;; retries++) + { m_retryStrategy->GetSendToken(); httpRequest->SetEventStreamRequest(request.IsEventStreamRequest()); @@ -253,26 +253,26 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, { m_retryStrategy->RequestBookkeeping(outcome, lastError); } - coreMetrics.httpClientMetrics = httpRequest->GetRequestMetrics(); - if (outcome.IsSuccess()) - { - Aws::Monitoring::OnRequestSucceeded(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, outcome, coreMetrics, contexts); - AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Request successful returning."); - break; - } + coreMetrics.httpClientMetrics = httpRequest->GetRequestMetrics(); + if (outcome.IsSuccess()) + { + Aws::Monitoring::OnRequestSucceeded(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, outcome, coreMetrics, contexts); + AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Request successful returning."); + break; + } lastError = outcome.GetError(); - + DateTime serverTime = GetServerTimeFromError(outcome.GetError()); auto clockSkew = DateTime::Diff(serverTime, DateTime::Now()); - Aws::Monitoring::OnRequestFailed(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, outcome, coreMetrics, contexts); - - if (!m_httpClient->IsRequestProcessingEnabled()) - { - AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Request was cancelled externally."); - break; - } - + Aws::Monitoring::OnRequestFailed(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, outcome, coreMetrics, contexts); + + if (!m_httpClient->IsRequestProcessingEnabled()) + { + AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Request was cancelled externally."); + break; + } + // Adjust region bool retryWithCorrectRegion = false; HttpResponseCode httpResponseCode = outcome.GetError().GetResponseCode(); @@ -289,32 +289,32 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, } } - long sleepMillis = m_retryStrategy->CalculateDelayBeforeNextRetry(outcome.GetError(), retries); - //AdjustClockSkew returns true means clock skew was the problem and skew was adjusted, false otherwise. + long sleepMillis = m_retryStrategy->CalculateDelayBeforeNextRetry(outcome.GetError(), retries); + //AdjustClockSkew returns true means clock skew was the problem and skew was adjusted, false otherwise. //sleep if clock skew and region was NOT the problem. AdjustClockSkew may update error inside outcome. bool shouldSleep = !AdjustClockSkew(outcome, signerName) && !retryWithCorrectRegion; - + if (!retryWithCorrectRegion && !m_retryStrategy->ShouldRetry(outcome.GetError(), retries)) - { - break; - } - - AWS_LOGSTREAM_WARN(AWS_CLIENT_LOG_TAG, "Request failed, now waiting " << sleepMillis << " ms before attempting again."); - if(request.GetBody()) - { - request.GetBody()->clear(); - request.GetBody()->seekg(0); - } - - if (request.GetRequestRetryHandler()) - { - request.GetRequestRetryHandler()(request); - } - - if (shouldSleep) - { - m_httpClient->RetryRequestSleep(std::chrono::milliseconds(sleepMillis)); - } + { + break; + } + + AWS_LOGSTREAM_WARN(AWS_CLIENT_LOG_TAG, "Request failed, now waiting " << sleepMillis << " ms before attempting again."); + if(request.GetBody()) + { + request.GetBody()->clear(); + request.GetBody()->seekg(0); + } + + if (request.GetRequestRetryHandler()) + { + request.GetRequestRetryHandler()(request); + } + + if (shouldSleep) + { + m_httpClient->RetryRequestSleep(std::chrono::milliseconds(sleepMillis)); + } Aws::Http::URI newUri = uri; Aws::String newEndpoint = GetErrorMarshaller()->ExtractEndpoint(outcome.GetError()); @@ -332,32 +332,32 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, requestInfo.attempt ++; requestInfo.maxAttempts = m_retryStrategy->GetMaxAttempts(); httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); - Aws::Monitoring::OnRequestRetry(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, contexts); - } - Aws::Monitoring::OnFinish(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, contexts); - return outcome; -} - + Aws::Monitoring::OnRequestRetry(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, contexts); + } + Aws::Monitoring::OnFinish(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, contexts); + return outcome; +} + HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, HttpMethod method, const char* signerName, const char* requestName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ +{ if (!Aws::Utils::IsValidHost(uri.GetAuthority())) { return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::VALIDATION, "", "Invalid DNS Label found in URI host", false/*retryable*/)); } - std::shared_ptr<HttpRequest> httpRequest(CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod)); - HttpResponseOutcome outcome; + std::shared_ptr<HttpRequest> httpRequest(CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod)); + HttpResponseOutcome outcome; AWSError<CoreErrors> lastError; - Aws::Monitoring::CoreMetricsCollection coreMetrics; - auto contexts = Aws::Monitoring::OnRequestStarted(this->GetServiceClientName(), requestName, httpRequest); + Aws::Monitoring::CoreMetricsCollection coreMetrics; + auto contexts = Aws::Monitoring::OnRequestStarted(this->GetServiceClientName(), requestName, httpRequest); const char* signerRegion = signerRegionOverride; Aws::String regionFromResponse; - + Aws::String invocationId = UUID::RandomUUID(); RequestInfo requestInfo; requestInfo.attempt = 1; @@ -365,8 +365,8 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, httpRequest->SetHeaderValue(Http::SDK_INVOCATION_ID_HEADER, invocationId); httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); - for (long retries = 0;; retries++) - { + for (long retries = 0;; retries++) + { m_retryStrategy->GetSendToken(); outcome = AttemptOneRequest(httpRequest, signerName, requestName, signerRegion, signerServiceNameOverride); if (retries == 0) @@ -377,26 +377,26 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, { m_retryStrategy->RequestBookkeeping(outcome, lastError); } - coreMetrics.httpClientMetrics = httpRequest->GetRequestMetrics(); - if (outcome.IsSuccess()) - { - Aws::Monitoring::OnRequestSucceeded(this->GetServiceClientName(), requestName, httpRequest, outcome, coreMetrics, contexts); - AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Request successful returning."); - break; - } + coreMetrics.httpClientMetrics = httpRequest->GetRequestMetrics(); + if (outcome.IsSuccess()) + { + Aws::Monitoring::OnRequestSucceeded(this->GetServiceClientName(), requestName, httpRequest, outcome, coreMetrics, contexts); + AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Request successful returning."); + break; + } lastError = outcome.GetError(); - + DateTime serverTime = GetServerTimeFromError(outcome.GetError()); auto clockSkew = DateTime::Diff(serverTime, DateTime::Now()); - Aws::Monitoring::OnRequestFailed(this->GetServiceClientName(), requestName, httpRequest, outcome, coreMetrics, contexts); - - if (!m_httpClient->IsRequestProcessingEnabled()) - { - AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Request was cancelled externally."); - break; - } - + Aws::Monitoring::OnRequestFailed(this->GetServiceClientName(), requestName, httpRequest, outcome, coreMetrics, contexts); + + if (!m_httpClient->IsRequestProcessingEnabled()) + { + AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Request was cancelled externally."); + break; + } + // Adjust region bool retryWithCorrectRegion = false; HttpResponseCode httpResponseCode = outcome.GetError().GetResponseCode(); @@ -413,22 +413,22 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, } } - long sleepMillis = m_retryStrategy->CalculateDelayBeforeNextRetry(outcome.GetError(), retries); - //AdjustClockSkew returns true means clock skew was the problem and skew was adjusted, false otherwise. + long sleepMillis = m_retryStrategy->CalculateDelayBeforeNextRetry(outcome.GetError(), retries); + //AdjustClockSkew returns true means clock skew was the problem and skew was adjusted, false otherwise. //sleep if clock skew and region was NOT the problem. AdjustClockSkew may update error inside outcome. bool shouldSleep = !AdjustClockSkew(outcome, signerName) && !retryWithCorrectRegion; - + if (!retryWithCorrectRegion && !m_retryStrategy->ShouldRetry(outcome.GetError(), retries)) - { - break; - } - - AWS_LOGSTREAM_WARN(AWS_CLIENT_LOG_TAG, "Request failed, now waiting " << sleepMillis << " ms before attempting again."); - - if (shouldSleep) - { - m_httpClient->RetryRequestSleep(std::chrono::milliseconds(sleepMillis)); - } + { + break; + } + + AWS_LOGSTREAM_WARN(AWS_CLIENT_LOG_TAG, "Request failed, now waiting " << sleepMillis << " ms before attempting again."); + + if (shouldSleep) + { + m_httpClient->RetryRequestSleep(std::chrono::milliseconds(sleepMillis)); + } Aws::Http::URI newUri = uri; Aws::String newEndpoint = GetErrorMarshaller()->ExtractEndpoint(outcome.GetError()); @@ -446,120 +446,120 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, requestInfo.attempt ++; requestInfo.maxAttempts = m_retryStrategy->GetMaxAttempts(); httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); - Aws::Monitoring::OnRequestRetry(this->GetServiceClientName(), requestName, httpRequest, contexts); - } - Aws::Monitoring::OnFinish(this->GetServiceClientName(), requestName, httpRequest, contexts); - return outcome; -} - -static bool DoesResponseGenerateError(const std::shared_ptr<HttpResponse>& response) -{ + Aws::Monitoring::OnRequestRetry(this->GetServiceClientName(), requestName, httpRequest, contexts); + } + Aws::Monitoring::OnFinish(this->GetServiceClientName(), requestName, httpRequest, contexts); + return outcome; +} + +static bool DoesResponseGenerateError(const std::shared_ptr<HttpResponse>& response) +{ if (response->HasClientError()) return true; - - int responseCode = static_cast<int>(response->GetResponseCode()); - return responseCode < SUCCESS_RESPONSE_MIN || responseCode > SUCCESS_RESPONSE_MAX; - -} - + + int responseCode = static_cast<int>(response->GetResponseCode()); + return responseCode < SUCCESS_RESPONSE_MIN || responseCode > SUCCESS_RESPONSE_MAX; + +} + HttpResponseOutcome AWSClient::AttemptOneRequest(const std::shared_ptr<HttpRequest>& httpRequest, const Aws::AmazonWebServiceRequest& request, const char* signerName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ - BuildHttpRequest(request, httpRequest); - auto signer = GetSignerByName(signerName); +{ + BuildHttpRequest(request, httpRequest); + auto signer = GetSignerByName(signerName); if (!signer->SignRequest(*httpRequest, signerRegionOverride, signerServiceNameOverride, request.SignBody())) - { - AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, "Request signing failed. Returning error."); - return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::CLIENT_SIGNING_FAILURE, "", "SDK failed to sign the request", false/*retryable*/)); - } - + { + AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, "Request signing failed. Returning error."); + return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::CLIENT_SIGNING_FAILURE, "", "SDK failed to sign the request", false/*retryable*/)); + } + if (request.GetRequestSignedHandler()) { request.GetRequestSignedHandler()(*httpRequest); } - AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request Successfully signed"); - std::shared_ptr<HttpResponse> httpResponse( - m_httpClient->MakeRequest(httpRequest, m_readRateLimiter.get(), m_writeRateLimiter.get())); - - if (DoesResponseGenerateError(httpResponse)) - { - AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned error. Attempting to generate appropriate error codes from response"); + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request Successfully signed"); + std::shared_ptr<HttpResponse> httpResponse( + m_httpClient->MakeRequest(httpRequest, m_readRateLimiter.get(), m_writeRateLimiter.get())); + + if (DoesResponseGenerateError(httpResponse)) + { + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned error. Attempting to generate appropriate error codes from response"); auto error = BuildAWSError(httpResponse); return HttpResponseOutcome(std::move(error)); - } - - AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned successful response."); - + } + + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned successful response."); + return HttpResponseOutcome(std::move(httpResponse)); -} - +} + HttpResponseOutcome AWSClient::AttemptOneRequest(const std::shared_ptr<HttpRequest>& httpRequest, const char* signerName, const char* requestName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ - AWS_UNREFERENCED_PARAM(requestName); - - auto signer = GetSignerByName(signerName); +{ + AWS_UNREFERENCED_PARAM(requestName); + + auto signer = GetSignerByName(signerName); if (!signer->SignRequest(*httpRequest, signerRegionOverride, signerServiceNameOverride, true)) - { - AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, "Request signing failed. Returning error."); - return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::CLIENT_SIGNING_FAILURE, "", "SDK failed to sign the request", false/*retryable*/)); - } - - //user agent and headers like that shouldn't be signed for the sake of compatibility with proxies which MAY mutate that header. - AddCommonHeaders(*httpRequest); - - AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request Successfully signed"); - std::shared_ptr<HttpResponse> httpResponse( - m_httpClient->MakeRequest(httpRequest, m_readRateLimiter.get(), m_writeRateLimiter.get())); - - if (DoesResponseGenerateError(httpResponse)) - { - AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned error. Attempting to generate appropriate error codes from response"); + { + AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, "Request signing failed. Returning error."); + return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::CLIENT_SIGNING_FAILURE, "", "SDK failed to sign the request", false/*retryable*/)); + } + + //user agent and headers like that shouldn't be signed for the sake of compatibility with proxies which MAY mutate that header. + AddCommonHeaders(*httpRequest); + + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request Successfully signed"); + std::shared_ptr<HttpResponse> httpResponse( + m_httpClient->MakeRequest(httpRequest, m_readRateLimiter.get(), m_writeRateLimiter.get())); + + if (DoesResponseGenerateError(httpResponse)) + { + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned error. Attempting to generate appropriate error codes from response"); auto error = BuildAWSError(httpResponse); return HttpResponseOutcome(std::move(error)); - } - - AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned successful response."); - + } + + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned successful response."); + return HttpResponseOutcome(std::move(httpResponse)); -} - -StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& uri, - const Aws::AmazonWebServiceRequest& request, - Http::HttpMethod method, +} + +StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& uri, + const Aws::AmazonWebServiceRequest& request, + Http::HttpMethod method, const char* signerName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ +{ HttpResponseOutcome httpResponseOutcome = AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride); - if (httpResponseOutcome.IsSuccess()) - { - return StreamOutcome(AmazonWebServiceResult<Stream::ResponseStream>( - httpResponseOutcome.GetResult()->SwapResponseStreamOwnership(), - httpResponseOutcome.GetResult()->GetHeaders(), httpResponseOutcome.GetResult()->GetResponseCode())); - } - + if (httpResponseOutcome.IsSuccess()) + { + return StreamOutcome(AmazonWebServiceResult<Stream::ResponseStream>( + httpResponseOutcome.GetResult()->SwapResponseStreamOwnership(), + httpResponseOutcome.GetResult()->GetHeaders(), httpResponseOutcome.GetResult()->GetResponseCode())); + } + return StreamOutcome(std::move(httpResponseOutcome)); -} - +} + StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& uri, Http::HttpMethod method, const char* signerName, const char* requestName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ +{ HttpResponseOutcome httpResponseOutcome = AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride); - if (httpResponseOutcome.IsSuccess()) - { - return StreamOutcome(AmazonWebServiceResult<Stream::ResponseStream>( - httpResponseOutcome.GetResult()->SwapResponseStreamOwnership(), - httpResponseOutcome.GetResult()->GetHeaders(), httpResponseOutcome.GetResult()->GetResponseCode())); - } - + if (httpResponseOutcome.IsSuccess()) + { + return StreamOutcome(AmazonWebServiceResult<Stream::ResponseStream>( + httpResponseOutcome.GetResult()->SwapResponseStreamOwnership(), + httpResponseOutcome.GetResult()->GetHeaders(), httpResponseOutcome.GetResult()->GetResponseCode())); + } + return StreamOutcome(std::move(httpResponseOutcome)); -} - +} + XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::Http::URI& uri, const Aws::AmazonWebServiceRequest& request, Http::HttpMethod method, @@ -592,80 +592,80 @@ XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::Http::URI& uri, return XmlOutcome(std::move(httpOutcome)); } -void AWSClient::AddHeadersToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, - const Http::HeaderValueCollection& headerValues) const -{ - for (auto const& headerValue : headerValues) - { - httpRequest->SetHeaderValue(headerValue.first, headerValue.second); - } - - AddCommonHeaders(*httpRequest); -} - -void AWSClient::AddContentBodyToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, +void AWSClient::AddHeadersToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, + const Http::HeaderValueCollection& headerValues) const +{ + for (auto const& headerValue : headerValues) + { + httpRequest->SetHeaderValue(headerValue.first, headerValue.second); + } + + AddCommonHeaders(*httpRequest); +} + +void AWSClient::AddContentBodyToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, const std::shared_ptr<Aws::IOStream>& body, bool needsContentMd5, bool isChunked) const -{ - httpRequest->AddContentBody(body); - - //If there is no body, we have a content length of 0 - //note: we also used to remove content-type, but S3 actually needs content-type on InitiateMultipartUpload and it isn't - //forbiden by the spec. If we start getting weird errors related to this, make sure it isn't caused by this removal. - if (!body) - { - AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "No content body, content-length headers"); - - if(httpRequest->GetMethod() == HttpMethod::HTTP_POST || httpRequest->GetMethod() == HttpMethod::HTTP_PUT) +{ + httpRequest->AddContentBody(body); + + //If there is no body, we have a content length of 0 + //note: we also used to remove content-type, but S3 actually needs content-type on InitiateMultipartUpload and it isn't + //forbiden by the spec. If we start getting weird errors related to this, make sure it isn't caused by this removal. + if (!body) + { + AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "No content body, content-length headers"); + + if(httpRequest->GetMethod() == HttpMethod::HTTP_POST || httpRequest->GetMethod() == HttpMethod::HTTP_PUT) { httpRequest->SetHeaderValue(Http::CONTENT_LENGTH_HEADER, "0"); - } - else - { - httpRequest->DeleteHeader(Http::CONTENT_LENGTH_HEADER); - } - } - + } + else + { + httpRequest->DeleteHeader(Http::CONTENT_LENGTH_HEADER); + } + } + //Add transfer-encoding:chunked to header if (body && isChunked) { httpRequest->SetTransferEncoding(CHUNKED_VALUE); } - //in the scenario where we are adding a content body as a stream, the request object likely already - //has a content-length header set and we don't want to seek the stream just to find this information. + //in the scenario where we are adding a content body as a stream, the request object likely already + //has a content-length header set and we don't want to seek the stream just to find this information. else if (body && !httpRequest->HasHeader(Http::CONTENT_LENGTH_HEADER)) - { + { if (!m_httpClient->SupportsChunkedTransferEncoding()) { AWS_LOGSTREAM_WARN(AWS_CLIENT_LOG_TAG, "This http client doesn't support transfer-encoding:chunked. " << "The request may fail if it's not a seekable stream."); } - AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Found body, but content-length has not been set, attempting to compute content-length"); - body->seekg(0, body->end); - auto streamSize = body->tellg(); - body->seekg(0, body->beg); - Aws::StringStream ss; - ss << streamSize; - httpRequest->SetContentLength(ss.str()); - } - - if (needsContentMd5 && body && !httpRequest->HasHeader(Http::CONTENT_MD5_HEADER)) - { - AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Found body, and content-md5 needs to be set" << - ", attempting to compute content-md5"); - - //changing the internal state of the hash computation is not a logical state - //change as far as constness goes for this class. Due to the platform specificness - //of hash computations, we can't control the fact that computing a hash mutates - //state on some platforms such as windows (but that isn't a concern of this class. - auto md5HashResult = const_cast<AWSClient*>(this)->m_hash->Calculate(*body); - body->clear(); - if (md5HashResult.IsSuccess()) - { - httpRequest->SetHeaderValue(Http::CONTENT_MD5_HEADER, HashingUtils::Base64Encode(md5HashResult.GetResult())); - } - } -} - + AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Found body, but content-length has not been set, attempting to compute content-length"); + body->seekg(0, body->end); + auto streamSize = body->tellg(); + body->seekg(0, body->beg); + Aws::StringStream ss; + ss << streamSize; + httpRequest->SetContentLength(ss.str()); + } + + if (needsContentMd5 && body && !httpRequest->HasHeader(Http::CONTENT_MD5_HEADER)) + { + AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Found body, and content-md5 needs to be set" << + ", attempting to compute content-md5"); + + //changing the internal state of the hash computation is not a logical state + //change as far as constness goes for this class. Due to the platform specificness + //of hash computations, we can't control the fact that computing a hash mutates + //state on some platforms such as windows (but that isn't a concern of this class. + auto md5HashResult = const_cast<AWSClient*>(this)->m_hash->Calculate(*body); + body->clear(); + if (md5HashResult.IsSuccess()) + { + httpRequest->SetHeaderValue(Http::CONTENT_MD5_HEADER, HashingUtils::Base64Encode(md5HashResult.GetResult())); + } + } +} + Aws::String Aws::Client::GetAuthorizationHeader(const Aws::Http::HttpRequest& httpRequest) { // Extract the hex-encoded signature from the authorization header rather than recalculating it. @@ -697,47 +697,47 @@ void AWSClient::BuildHttpRequest(const Aws::AmazonWebServiceRequest& request, AddContentBodyToRequest(httpRequest, request.GetBody(), request.ShouldComputeContentMd5(), request.IsStreaming() && request.IsChunked() && m_httpClient->SupportsChunkedTransferEncoding()); } - // Pass along handlers for processing data sent/received in bytes - httpRequest->SetDataReceivedEventHandler(request.GetDataReceivedEventHandler()); - httpRequest->SetDataSentEventHandler(request.GetDataSentEventHandler()); - httpRequest->SetContinueRequestHandle(request.GetContinueRequestHandler()); - - request.AddQueryStringParameters(httpRequest->GetUri()); -} - -void AWSClient::AddCommonHeaders(HttpRequest& httpRequest) const -{ - httpRequest.SetUserAgent(m_userAgent); -} - -Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, long long expirationInSeconds) -{ - std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); - auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); - if (signer->PresignRequest(*request, expirationInSeconds)) - { - return request->GetURIString(); - } - + // Pass along handlers for processing data sent/received in bytes + httpRequest->SetDataReceivedEventHandler(request.GetDataReceivedEventHandler()); + httpRequest->SetDataSentEventHandler(request.GetDataSentEventHandler()); + httpRequest->SetContinueRequestHandle(request.GetContinueRequestHandler()); + + request.AddQueryStringParameters(httpRequest->GetUri()); +} + +void AWSClient::AddCommonHeaders(HttpRequest& httpRequest) const +{ + httpRequest.SetUserAgent(m_userAgent); +} + +Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, long long expirationInSeconds) +{ + std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); + auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); + if (signer->PresignRequest(*request, expirationInSeconds)) + { + return request->GetURIString(); + } + return {}; -} - -Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds) -{ - std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); - for (const auto& it: customizedHeaders) - { - request->SetHeaderValue(it.first.c_str(), it.second); - } - auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); - if (signer->PresignRequest(*request, expirationInSeconds)) - { - return request->GetURIString(); - } - +} + +Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds) +{ + std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); + for (const auto& it: customizedHeaders) + { + request->SetHeaderValue(it.first.c_str(), it.second); + } + auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); + if (signer->PresignRequest(*request, expirationInSeconds)) + { + return request->GetURIString(); + } + return {}; -} - +} + Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const char* region, long long expirationInSeconds) const { std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); @@ -766,165 +766,165 @@ Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const c return {}; } -Aws::String AWSClient::GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, long long expirationInSeconds) const -{ - std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); - auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); - if (signer->PresignRequest(*request, region, serviceName, expirationInSeconds)) - { - return request->GetURIString(); - } - +Aws::String AWSClient::GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, long long expirationInSeconds) const +{ + std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); + auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); + if (signer->PresignRequest(*request, region, serviceName, expirationInSeconds)) + { + return request->GetURIString(); + } + return {}; -} - +} + Aws::String AWSClient::GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds) -{ - std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); +{ + std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); for (const auto& it: customizedHeaders) { request->SetHeaderValue(it.first.c_str(), it.second); } - auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); + auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); if (signer->PresignRequest(*request, region, serviceName, expirationInSeconds)) - { - return request->GetURIString(); - } - + { + return request->GetURIString(); + } + return {}; -} - -Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, - const Aws::Http::QueryStringParameterCollection& extraParams, long long expirationInSeconds) const -{ - std::shared_ptr<HttpRequest> httpRequest = - ConvertToRequestForPresigning(request, uri, method, extraParams); - auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); - if (signer->PresignRequest(*httpRequest, region, expirationInSeconds)) - { - return httpRequest->GetURIString(); - } - +} + +Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, + const Aws::Http::QueryStringParameterCollection& extraParams, long long expirationInSeconds) const +{ + std::shared_ptr<HttpRequest> httpRequest = + ConvertToRequestForPresigning(request, uri, method, extraParams); + auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); + if (signer->PresignRequest(*httpRequest, region, expirationInSeconds)) + { + return httpRequest->GetURIString(); + } + return {}; -} - -Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, -const Aws::Http::QueryStringParameterCollection& extraParams, long long expirationInSeconds) const -{ - std::shared_ptr<HttpRequest> httpRequest = - ConvertToRequestForPresigning(request, uri, method, extraParams); - auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); - if (signer->PresignRequest(*httpRequest, region, serviceName, expirationInSeconds)) - { - return httpRequest->GetURIString(); - } - +} + +Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, +const Aws::Http::QueryStringParameterCollection& extraParams, long long expirationInSeconds) const +{ + std::shared_ptr<HttpRequest> httpRequest = + ConvertToRequestForPresigning(request, uri, method, extraParams); + auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); + if (signer->PresignRequest(*httpRequest, region, serviceName, expirationInSeconds)) + { + return httpRequest->GetURIString(); + } + return {}; -} - -Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, Aws::Http::HttpMethod method, - const Aws::Http::QueryStringParameterCollection& extraParams, long long expirationInSeconds) const -{ - std::shared_ptr<HttpRequest> httpRequest = - ConvertToRequestForPresigning(request, uri, method, extraParams); - auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); - if (signer->PresignRequest(*httpRequest, expirationInSeconds)) - { - return httpRequest->GetURIString(); - } - +} + +Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, Aws::Http::HttpMethod method, + const Aws::Http::QueryStringParameterCollection& extraParams, long long expirationInSeconds) const +{ + std::shared_ptr<HttpRequest> httpRequest = + ConvertToRequestForPresigning(request, uri, method, extraParams); + auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); + if (signer->PresignRequest(*httpRequest, expirationInSeconds)) + { + return httpRequest->GetURIString(); + } + return {}; -} - -std::shared_ptr<Aws::Http::HttpRequest> AWSClient::ConvertToRequestForPresigning(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, - Aws::Http::HttpMethod method, const Aws::Http::QueryStringParameterCollection& extraParams) const -{ - request.PutToPresignedUrl(uri); - std::shared_ptr<HttpRequest> httpRequest = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); - - for (auto& param : extraParams) - { - httpRequest->AddQueryStringParameter(param.first.c_str(), param.second); - } - - return httpRequest; -} - +} + +std::shared_ptr<Aws::Http::HttpRequest> AWSClient::ConvertToRequestForPresigning(const Aws::AmazonWebServiceRequest& request, Aws::Http::URI& uri, + Aws::Http::HttpMethod method, const Aws::Http::QueryStringParameterCollection& extraParams) const +{ + request.PutToPresignedUrl(uri); + std::shared_ptr<HttpRequest> httpRequest = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); + + for (auto& param : extraParams) + { + httpRequest->AddQueryStringParameter(param.first.c_str(), param.second); + } + + return httpRequest; +} + std::shared_ptr<Aws::Http::HttpResponse> AWSClient::MakeHttpRequest(std::shared_ptr<Aws::Http::HttpRequest>& request) const { return m_httpClient->MakeRequest(request, m_readRateLimiter.get(), m_writeRateLimiter.get()); } - - -//////////////////////////////////////////////////////////////////////////// -AWSJsonClient::AWSJsonClient(const Aws::Client::ClientConfiguration& configuration, - const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer, - const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : - BASECLASS(configuration, signer, errorMarshaller) -{ -} - -AWSJsonClient::AWSJsonClient(const Aws::Client::ClientConfiguration& configuration, - const std::shared_ptr<Aws::Auth::AWSAuthSignerProvider>& signerProvider, - const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : - BASECLASS(configuration, signerProvider, errorMarshaller) -{ -} - - -JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri, - const Aws::AmazonWebServiceRequest& request, - Http::HttpMethod method, + + +//////////////////////////////////////////////////////////////////////////// +AWSJsonClient::AWSJsonClient(const Aws::Client::ClientConfiguration& configuration, + const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer, + const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : + BASECLASS(configuration, signer, errorMarshaller) +{ +} + +AWSJsonClient::AWSJsonClient(const Aws::Client::ClientConfiguration& configuration, + const std::shared_ptr<Aws::Auth::AWSAuthSignerProvider>& signerProvider, + const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : + BASECLASS(configuration, signerProvider, errorMarshaller) +{ +} + + +JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri, + const Aws::AmazonWebServiceRequest& request, + Http::HttpMethod method, const char* signerName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ +{ HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride)); - if (!httpOutcome.IsSuccess()) - { + if (!httpOutcome.IsSuccess()) + { return JsonOutcome(std::move(httpOutcome)); - } - - if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) - //this is stupid, but gcc doesn't pick up the covariant on the dereference so we have to give it a little hint. - return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(httpOutcome.GetResult()->GetResponseBody()), - httpOutcome.GetResult()->GetHeaders(), - httpOutcome.GetResult()->GetResponseCode())); - - else - return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(), httpOutcome.GetResult()->GetHeaders())); -} - -JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri, - Http::HttpMethod method, - const char* signerName, + } + + if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) + //this is stupid, but gcc doesn't pick up the covariant on the dereference so we have to give it a little hint. + return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(httpOutcome.GetResult()->GetResponseBody()), + httpOutcome.GetResult()->GetHeaders(), + httpOutcome.GetResult()->GetResponseCode())); + + else + return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(), httpOutcome.GetResult()->GetHeaders())); +} + +JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri, + Http::HttpMethod method, + const char* signerName, const char* requestName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ +{ HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride)); - if (!httpOutcome.IsSuccess()) - { + if (!httpOutcome.IsSuccess()) + { return JsonOutcome(std::move(httpOutcome)); - } - - if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) - { - JsonValue jsonValue(httpOutcome.GetResult()->GetResponseBody()); - if (!jsonValue.WasParseSuccessful()) - { - return JsonOutcome(AWSError<CoreErrors>(CoreErrors::UNKNOWN, "Json Parser Error", jsonValue.GetErrorMessage(), false)); - } - - //this is stupid, but gcc doesn't pick up the covariant on the dereference so we have to give it a little hint. - return JsonOutcome(AmazonWebServiceResult<JsonValue>(std::move(jsonValue), - httpOutcome.GetResult()->GetHeaders(), - httpOutcome.GetResult()->GetResponseCode())); - } - - return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(), httpOutcome.GetResult()->GetHeaders())); -} - + } + + if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) + { + JsonValue jsonValue(httpOutcome.GetResult()->GetResponseBody()); + if (!jsonValue.WasParseSuccessful()) + { + return JsonOutcome(AWSError<CoreErrors>(CoreErrors::UNKNOWN, "Json Parser Error", jsonValue.GetErrorMessage(), false)); + } + + //this is stupid, but gcc doesn't pick up the covariant on the dereference so we have to give it a little hint. + return JsonOutcome(AmazonWebServiceResult<JsonValue>(std::move(jsonValue), + httpOutcome.GetResult()->GetHeaders(), + httpOutcome.GetResult()->GetResponseCode())); + } + + return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(), httpOutcome.GetResult()->GetHeaders())); +} + JsonOutcome AWSJsonClient::MakeEventStreamRequest(std::shared_ptr<Aws::Http::HttpRequest>& request) const { // request is assumed to be signed @@ -958,141 +958,141 @@ JsonOutcome AWSJsonClient::MakeEventStreamRequest(std::shared_ptr<Aws::Http::Htt return JsonOutcome(AmazonWebServiceResult<JsonValue>(JsonValue(), httpOutcome.GetResult()->GetHeaders())); } -AWSError<CoreErrors> AWSJsonClient::BuildAWSError( - const std::shared_ptr<Aws::Http::HttpResponse>& httpResponse) const -{ - AWSError<CoreErrors> error; +AWSError<CoreErrors> AWSJsonClient::BuildAWSError( + const std::shared_ptr<Aws::Http::HttpResponse>& httpResponse) const +{ + AWSError<CoreErrors> error; if (httpResponse->HasClientError()) - { + { bool retryable = httpResponse->GetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false; error = AWSError<CoreErrors>(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable); - } - else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1) - { - auto responseCode = httpResponse->GetResponseCode(); - auto errorCode = GuessBodylessErrorType(responseCode); - - Aws::StringStream ss; - ss << "No response body."; - error = AWSError<CoreErrors>(errorCode, "", ss.str(), - IsRetryableHttpResponseCode(responseCode)); - } - else - { - assert(httpResponse->GetResponseCode() != HttpResponseCode::OK); - error = GetErrorMarshaller()->Marshall(*httpResponse); - } - - error.SetResponseHeaders(httpResponse->GetHeaders()); - error.SetResponseCode(httpResponse->GetResponseCode()); + } + else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1) + { + auto responseCode = httpResponse->GetResponseCode(); + auto errorCode = GuessBodylessErrorType(responseCode); + + Aws::StringStream ss; + ss << "No response body."; + error = AWSError<CoreErrors>(errorCode, "", ss.str(), + IsRetryableHttpResponseCode(responseCode)); + } + else + { + assert(httpResponse->GetResponseCode() != HttpResponseCode::OK); + error = GetErrorMarshaller()->Marshall(*httpResponse); + } + + error.SetResponseHeaders(httpResponse->GetHeaders()); + error.SetResponseCode(httpResponse->GetResponseCode()); error.SetRemoteHostIpAddress(httpResponse->GetOriginatingRequest().GetResolvedRemoteHost()); - AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, error); - return error; -} - -///////////////////////////////////////////////////////////////////////////////////////// -AWSXMLClient::AWSXMLClient(const Aws::Client::ClientConfiguration& configuration, - const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer, - const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : - BASECLASS(configuration, signer, errorMarshaller) -{ -} - -AWSXMLClient::AWSXMLClient(const Aws::Client::ClientConfiguration& configuration, - const std::shared_ptr<Aws::Auth::AWSAuthSignerProvider>& signerProvider, - const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : - BASECLASS(configuration, signerProvider, errorMarshaller) -{ -} - -XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri, - const Aws::AmazonWebServiceRequest& request, - Http::HttpMethod method, + AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, error); + return error; +} + +///////////////////////////////////////////////////////////////////////////////////////// +AWSXMLClient::AWSXMLClient(const Aws::Client::ClientConfiguration& configuration, + const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer, + const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : + BASECLASS(configuration, signer, errorMarshaller) +{ +} + +AWSXMLClient::AWSXMLClient(const Aws::Client::ClientConfiguration& configuration, + const std::shared_ptr<Aws::Auth::AWSAuthSignerProvider>& signerProvider, + const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : + BASECLASS(configuration, signerProvider, errorMarshaller) +{ +} + +XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri, + const Aws::AmazonWebServiceRequest& request, + Http::HttpMethod method, const char* signerName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ +{ HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride)); - if (!httpOutcome.IsSuccess()) - { + if (!httpOutcome.IsSuccess()) + { return XmlOutcome(std::move(httpOutcome)); - } - - if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) - { - XmlDocument xmlDoc = XmlDocument::CreateFromXmlStream(httpOutcome.GetResult()->GetResponseBody()); - - if (!xmlDoc.WasParseSuccessful()) - { - AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, "Xml parsing for error failed with message " << xmlDoc.GetErrorMessage().c_str()); - return AWSError<CoreErrors>(CoreErrors::UNKNOWN, "Xml Parse Error", xmlDoc.GetErrorMessage(), false); - } - - return XmlOutcome(AmazonWebServiceResult<XmlDocument>(std::move(xmlDoc), - httpOutcome.GetResult()->GetHeaders(), httpOutcome.GetResult()->GetResponseCode())); - } - - return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); -} - -XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri, - Http::HttpMethod method, - const char* signerName, + } + + if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) + { + XmlDocument xmlDoc = XmlDocument::CreateFromXmlStream(httpOutcome.GetResult()->GetResponseBody()); + + if (!xmlDoc.WasParseSuccessful()) + { + AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, "Xml parsing for error failed with message " << xmlDoc.GetErrorMessage().c_str()); + return AWSError<CoreErrors>(CoreErrors::UNKNOWN, "Xml Parse Error", xmlDoc.GetErrorMessage(), false); + } + + return XmlOutcome(AmazonWebServiceResult<XmlDocument>(std::move(xmlDoc), + httpOutcome.GetResult()->GetHeaders(), httpOutcome.GetResult()->GetResponseCode())); + } + + return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); +} + +XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri, + Http::HttpMethod method, + const char* signerName, const char* requestName, const char* signerRegionOverride, const char* signerServiceNameOverride) const -{ +{ HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride)); - if (!httpOutcome.IsSuccess()) - { + if (!httpOutcome.IsSuccess()) + { return XmlOutcome(std::move(httpOutcome)); - } - - if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) - { - return XmlOutcome(AmazonWebServiceResult<XmlDocument>( - XmlDocument::CreateFromXmlStream(httpOutcome.GetResult()->GetResponseBody()), - httpOutcome.GetResult()->GetHeaders(), httpOutcome.GetResult()->GetResponseCode())); - } - - return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); -} - -AWSError<CoreErrors> AWSXMLClient::BuildAWSError(const std::shared_ptr<Http::HttpResponse>& httpResponse) const -{ - AWSError<CoreErrors> error; + } + + if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) + { + return XmlOutcome(AmazonWebServiceResult<XmlDocument>( + XmlDocument::CreateFromXmlStream(httpOutcome.GetResult()->GetResponseBody()), + httpOutcome.GetResult()->GetHeaders(), httpOutcome.GetResult()->GetResponseCode())); + } + + return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); +} + +AWSError<CoreErrors> AWSXMLClient::BuildAWSError(const std::shared_ptr<Http::HttpResponse>& httpResponse) const +{ + AWSError<CoreErrors> error; if (httpResponse->HasClientError()) - { + { bool retryable = httpResponse->GetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false; error = AWSError<CoreErrors>(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable); - } + } else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1) - { - auto responseCode = httpResponse->GetResponseCode(); - auto errorCode = GuessBodylessErrorType(responseCode); - - Aws::StringStream ss; - ss << "No response body."; - error = AWSError<CoreErrors>(errorCode, "", ss.str(), IsRetryableHttpResponseCode(responseCode)); - } - else - { - assert(httpResponse->GetResponseCode() != HttpResponseCode::OK); - - // When trying to build an AWS Error from a response which is an FStream, we need to rewind the - // file pointer back to the beginning in order to correctly read the input using the XML string iterator - if ((httpResponse->GetResponseBody().tellp() > 0) - && (httpResponse->GetResponseBody().tellg() > 0)) - { - httpResponse->GetResponseBody().seekg(0); - } - - error = GetErrorMarshaller()->Marshall(*httpResponse); - } - - error.SetResponseHeaders(httpResponse->GetHeaders()); - error.SetResponseCode(httpResponse->GetResponseCode()); + { + auto responseCode = httpResponse->GetResponseCode(); + auto errorCode = GuessBodylessErrorType(responseCode); + + Aws::StringStream ss; + ss << "No response body."; + error = AWSError<CoreErrors>(errorCode, "", ss.str(), IsRetryableHttpResponseCode(responseCode)); + } + else + { + assert(httpResponse->GetResponseCode() != HttpResponseCode::OK); + + // When trying to build an AWS Error from a response which is an FStream, we need to rewind the + // file pointer back to the beginning in order to correctly read the input using the XML string iterator + if ((httpResponse->GetResponseBody().tellp() > 0) + && (httpResponse->GetResponseBody().tellg() > 0)) + { + httpResponse->GetResponseBody().seekg(0); + } + + error = GetErrorMarshaller()->Marshall(*httpResponse); + } + + error.SetResponseHeaders(httpResponse->GetHeaders()); + error.SetResponseCode(httpResponse->GetResponseCode()); error.SetRemoteHostIpAddress(httpResponse->GetOriginatingRequest().GetResolvedRemoteHost()); - AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, error); - return error; -} + AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, error); + return error; +} diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp index f5fa676f98..061b3d9deb 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp @@ -2,41 +2,41 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ - -#include <aws/core/client/AWSErrorMarshaller.h> -#include <aws/core/utils/logging/LogMacros.h> -#include <aws/core/utils/json/JsonSerializer.h> -#include <aws/core/utils/xml/XmlSerializer.h> -#include <aws/core/utils/StringUtils.h> -#include <aws/core/client/AWSError.h> -#include <aws/core/client/CoreErrors.h> - -using namespace Aws::Utils::Logging; -using namespace Aws::Utils::Json; -using namespace Aws::Utils::Xml; -using namespace Aws::Http; -using namespace Aws::Utils; -using namespace Aws::Client; - + +#include <aws/core/client/AWSErrorMarshaller.h> +#include <aws/core/utils/logging/LogMacros.h> +#include <aws/core/utils/json/JsonSerializer.h> +#include <aws/core/utils/xml/XmlSerializer.h> +#include <aws/core/utils/StringUtils.h> +#include <aws/core/client/AWSError.h> +#include <aws/core/client/CoreErrors.h> + +using namespace Aws::Utils::Logging; +using namespace Aws::Utils::Json; +using namespace Aws::Utils::Xml; +using namespace Aws::Http; +using namespace Aws::Utils; +using namespace Aws::Client; + static const char AWS_ERROR_MARSHALLER_LOG_TAG[] = "AWSErrorMarshaller"; AWS_CORE_API extern const char MESSAGE_LOWER_CASE[] = "message"; AWS_CORE_API extern const char MESSAGE_CAMEL_CASE[] = "Message"; AWS_CORE_API extern const char ERROR_TYPE_HEADER[] = "x-amzn-ErrorType"; AWS_CORE_API extern const char REQUEST_ID_HEADER[] = "x-amzn-RequestId"; AWS_CORE_API extern const char TYPE[] = "__type"; - -AWSError<CoreErrors> JsonErrorMarshaller::Marshall(const Aws::Http::HttpResponse& httpResponse) const -{ - JsonValue exceptionPayload(httpResponse.GetResponseBody()); - JsonView payloadView(exceptionPayload); + +AWSError<CoreErrors> JsonErrorMarshaller::Marshall(const Aws::Http::HttpResponse& httpResponse) const +{ + JsonValue exceptionPayload(httpResponse.GetResponseBody()); + JsonView payloadView(exceptionPayload); AWSError<CoreErrors> error; if (exceptionPayload.WasParseSuccessful()) - { + { AWS_LOGSTREAM_TRACE(AWS_ERROR_MARSHALLER_LOG_TAG, "Error response is " << payloadView.WriteReadable()); - + Aws::String message(payloadView.ValueExists(MESSAGE_CAMEL_CASE) ? payloadView.GetString(MESSAGE_CAMEL_CASE) : payloadView.ValueExists(MESSAGE_LOWER_CASE) ? payloadView.GetString(MESSAGE_LOWER_CASE) : ""); - + if (httpResponse.HasHeader(ERROR_TYPE_HEADER)) { error = Marshall(httpResponse.GetHeader(ERROR_TYPE_HEADER), message); @@ -50,131 +50,131 @@ AWSError<CoreErrors> JsonErrorMarshaller::Marshall(const Aws::Http::HttpResponse error = FindErrorByHttpResponseCode(httpResponse.GetResponseCode()); error.SetMessage(message); } - } - else - { + } + else + { error = AWSError<CoreErrors>(CoreErrors::UNKNOWN, "", "Failed to parse error payload", false); - } + } error.SetRequestId(httpResponse.HasHeader(REQUEST_ID_HEADER) ? httpResponse.GetHeader(REQUEST_ID_HEADER) : ""); error.SetJsonPayload(std::move(exceptionPayload)); return error; -} - +} + const JsonValue& JsonErrorMarshaller::GetJsonPayloadFromError(const AWSError<CoreErrors>& error) const { return error.GetJsonPayload(); } -AWSError<CoreErrors> XmlErrorMarshaller::Marshall(const Aws::Http::HttpResponse& httpResponse) const -{ - XmlDocument doc = XmlDocument::CreateFromXmlStream(httpResponse.GetResponseBody()); - AWS_LOGSTREAM_TRACE(AWS_ERROR_MARSHALLER_LOG_TAG, "Error response is " << doc.ConvertToString()); - bool errorParsed = false; - AWSError<CoreErrors> error; +AWSError<CoreErrors> XmlErrorMarshaller::Marshall(const Aws::Http::HttpResponse& httpResponse) const +{ + XmlDocument doc = XmlDocument::CreateFromXmlStream(httpResponse.GetResponseBody()); + AWS_LOGSTREAM_TRACE(AWS_ERROR_MARSHALLER_LOG_TAG, "Error response is " << doc.ConvertToString()); + bool errorParsed = false; + AWSError<CoreErrors> error; if (doc.WasParseSuccessful() && !doc.GetRootElement().IsNull()) - { - XmlNode errorNode = doc.GetRootElement(); + { + XmlNode errorNode = doc.GetRootElement(); Aws::String requestId(!errorNode.FirstChild("RequestId").IsNull() ? errorNode.FirstChild("RequestId").GetText() : !errorNode.FirstChild("RequestID").IsNull() ? errorNode.FirstChild("RequestID").GetText() : ""); - if (errorNode.GetName() != "Error") - { - errorNode = doc.GetRootElement().FirstChild("Error"); - } - if (errorNode.IsNull()) - { - errorNode = doc.GetRootElement().FirstChild("Errors"); - if(!errorNode.IsNull()) - { - errorNode = errorNode.FirstChild("Error"); - } - } - - if (!errorNode.IsNull()) - { + if (errorNode.GetName() != "Error") + { + errorNode = doc.GetRootElement().FirstChild("Error"); + } + if (errorNode.IsNull()) + { + errorNode = doc.GetRootElement().FirstChild("Errors"); + if(!errorNode.IsNull()) + { + errorNode = errorNode.FirstChild("Error"); + } + } + + if (!errorNode.IsNull()) + { requestId = !requestId.empty() ? requestId : !errorNode.FirstChild("RequestId").IsNull() ? errorNode.FirstChild("RequestId").GetText() : !errorNode.FirstChild("RequestID").IsNull() ? errorNode.FirstChild("RequestID").GetText() : ""; - XmlNode codeNode = errorNode.FirstChild("Code"); - XmlNode messageNode = errorNode.FirstChild("Message"); - - if (!codeNode.IsNull()) - { - error = Marshall(StringUtils::Trim(codeNode.GetText().c_str()), - StringUtils::Trim(messageNode.GetText().c_str())); - errorParsed = true; - } - } + XmlNode codeNode = errorNode.FirstChild("Code"); + XmlNode messageNode = errorNode.FirstChild("Message"); + + if (!codeNode.IsNull()) + { + error = Marshall(StringUtils::Trim(codeNode.GetText().c_str()), + StringUtils::Trim(messageNode.GetText().c_str())); + errorParsed = true; + } + } error.SetRequestId(requestId); - } - - if(!errorParsed) - { - // An error occurred attempting to parse the httpResponse as an XML stream, so we're just - // going to dump the XML parsing error and the http response code as a string - AWS_LOGSTREAM_WARN(AWS_ERROR_MARSHALLER_LOG_TAG, "Unable to generate a proper httpResponse from the response " - "stream. Response code: " << static_cast< uint32_t >(httpResponse.GetResponseCode())); - error = FindErrorByHttpResponseCode(httpResponse.GetResponseCode()); - } - + } + + if(!errorParsed) + { + // An error occurred attempting to parse the httpResponse as an XML stream, so we're just + // going to dump the XML parsing error and the http response code as a string + AWS_LOGSTREAM_WARN(AWS_ERROR_MARSHALLER_LOG_TAG, "Unable to generate a proper httpResponse from the response " + "stream. Response code: " << static_cast< uint32_t >(httpResponse.GetResponseCode())); + error = FindErrorByHttpResponseCode(httpResponse.GetResponseCode()); + } + error.SetXmlPayload(std::move(doc)); - return error; -} - + return error; +} + const XmlDocument& XmlErrorMarshaller::GetXmlPayloadFromError(const AWSError<CoreErrors>& error) const { return error.GetXmlPayload(); } -AWSError<CoreErrors> AWSErrorMarshaller::Marshall(const Aws::String& exceptionName, const Aws::String& message) const -{ - if(exceptionName.empty()) - { - return AWSError<CoreErrors>(CoreErrors::UNKNOWN, "", message, false); - } - - auto locationOfPound = exceptionName.find_first_of('#'); - auto locationOfColon = exceptionName.find_first_of(':'); - Aws::String formalExceptionName; - - if (locationOfPound != Aws::String::npos) - { +AWSError<CoreErrors> AWSErrorMarshaller::Marshall(const Aws::String& exceptionName, const Aws::String& message) const +{ + if(exceptionName.empty()) + { + return AWSError<CoreErrors>(CoreErrors::UNKNOWN, "", message, false); + } + + auto locationOfPound = exceptionName.find_first_of('#'); + auto locationOfColon = exceptionName.find_first_of(':'); + Aws::String formalExceptionName; + + if (locationOfPound != Aws::String::npos) + { formalExceptionName = exceptionName.substr(locationOfPound + 1); - } - else if (locationOfColon != Aws::String::npos) - { + } + else if (locationOfColon != Aws::String::npos) + { formalExceptionName = exceptionName.substr(0, locationOfColon); + } + else + { + formalExceptionName = exceptionName; + } + + AWSError<CoreErrors> error = FindErrorByName(formalExceptionName.c_str()); + if (error.GetErrorType() != CoreErrors::UNKNOWN) + { + AWS_LOGSTREAM_WARN(AWS_ERROR_MARSHALLER_LOG_TAG, "Encountered AWSError '" << formalExceptionName.c_str() << + "': " << message.c_str()); + error.SetExceptionName(formalExceptionName); + error.SetMessage(message); + return error; } - else - { - formalExceptionName = exceptionName; - } - - AWSError<CoreErrors> error = FindErrorByName(formalExceptionName.c_str()); - if (error.GetErrorType() != CoreErrors::UNKNOWN) - { - AWS_LOGSTREAM_WARN(AWS_ERROR_MARSHALLER_LOG_TAG, "Encountered AWSError '" << formalExceptionName.c_str() << - "': " << message.c_str()); - error.SetExceptionName(formalExceptionName); - error.SetMessage(message); - return error; - } - - AWS_LOGSTREAM_WARN(AWS_ERROR_MARSHALLER_LOG_TAG, "Encountered Unknown AWSError '" << exceptionName.c_str() << - "': " << message.c_str()); - - return AWSError<CoreErrors>(CoreErrors::UNKNOWN, exceptionName, "Unable to parse ExceptionName: " + exceptionName + " Message: " + message, false); -} - -AWSError<CoreErrors> AWSErrorMarshaller::FindErrorByName(const char* errorName) const -{ - return CoreErrorsMapper::GetErrorForName(errorName); -} - -AWSError<CoreErrors> AWSErrorMarshaller::FindErrorByHttpResponseCode(Aws::Http::HttpResponseCode code) const -{ - return CoreErrorsMapper::GetErrorForHttpResponseCode(code); -} + + AWS_LOGSTREAM_WARN(AWS_ERROR_MARSHALLER_LOG_TAG, "Encountered Unknown AWSError '" << exceptionName.c_str() << + "': " << message.c_str()); + + return AWSError<CoreErrors>(CoreErrors::UNKNOWN, exceptionName, "Unable to parse ExceptionName: " + exceptionName + " Message: " + message, false); +} + +AWSError<CoreErrors> AWSErrorMarshaller::FindErrorByName(const char* errorName) const +{ + return CoreErrorsMapper::GetErrorForName(errorName); +} + +AWSError<CoreErrors> AWSErrorMarshaller::FindErrorByHttpResponseCode(Aws::Http::HttpResponseCode code) const +{ + return CoreErrorsMapper::GetErrorForHttpResponseCode(code); +} diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AsyncCallerContext.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AsyncCallerContext.cpp index 4f9abdc9e4..5e0e12c8e0 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AsyncCallerContext.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AsyncCallerContext.cpp @@ -2,15 +2,15 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ - -#include <aws/core/client/AsyncCallerContext.h> -#include <aws/core/utils/UUID.h> - -namespace Aws -{ - namespace Client - { - AsyncCallerContext::AsyncCallerContext() : m_uuid(Aws::Utils::UUID::RandomUUID()) - {} - } -}
\ No newline at end of file + +#include <aws/core/client/AsyncCallerContext.h> +#include <aws/core/utils/UUID.h> + +namespace Aws +{ + namespace Client + { + AsyncCallerContext::AsyncCallerContext() : m_uuid(Aws::Utils::UUID::RandomUUID()) + {} + } +}
\ No newline at end of file diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp index e517379a77..69e1742988 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp @@ -2,63 +2,63 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ - -#include <aws/core/client/ClientConfiguration.h> + +#include <aws/core/client/ClientConfiguration.h> #include <aws/core/auth/AWSCredentialsProvider.h> -#include <aws/core/client/DefaultRetryStrategy.h> +#include <aws/core/client/DefaultRetryStrategy.h> #include <aws/core/platform/Environment.h> -#include <aws/core/platform/OSVersionInfo.h> -#include <aws/core/utils/memory/AWSMemory.h> +#include <aws/core/platform/OSVersionInfo.h> +#include <aws/core/utils/memory/AWSMemory.h> #include <aws/core/utils/StringUtils.h> -#include <aws/core/utils/threading/Executor.h> -#include <aws/core/utils/memory/stl/AWSStringStream.h> -#include <aws/core/Version.h> +#include <aws/core/utils/threading/Executor.h> +#include <aws/core/utils/memory/stl/AWSStringStream.h> +#include <aws/core/Version.h> #include <aws/core/config/AWSProfileConfigLoader.h> #include <aws/core/utils/logging/LogMacros.h> - -namespace Aws -{ + +namespace Aws +{ namespace Auth { AWS_CORE_API Aws::String GetConfigProfileFilename(); } -namespace Client -{ - +namespace Client +{ + static const char* CLIENT_CONFIG_TAG = "ClientConfiguration"; - + AWS_CORE_API Aws::String ComputeUserAgentString() -{ - Aws::StringStream ss; - ss << "aws-sdk-cpp/" << Version::GetVersionString() << " " << Aws::OSVersionInfo::ComputeOSVersionString() - << " " << Version::GetCompilerVersionString(); - return ss.str(); -} - +{ + Aws::StringStream ss; + ss << "aws-sdk-cpp/" << Version::GetVersionString() << " " << Aws::OSVersionInfo::ComputeOSVersionString() + << " " << Version::GetCompilerVersionString(); + return ss.str(); +} + ClientConfiguration::ClientConfiguration() : scheme(Aws::Http::Scheme::HTTPS), - useDualStack(false), + useDualStack(false), maxConnections(25), httpRequestTimeoutMs(0), requestTimeoutMs(3000), - connectTimeoutMs(1000), + connectTimeoutMs(1000), enableTcpKeepAlive(true), tcpKeepAliveIntervalMs(30000), lowSpeedLimit(1), - proxyScheme(Aws::Http::Scheme::HTTP), - proxyPort(0), + proxyScheme(Aws::Http::Scheme::HTTP), + proxyPort(0), executor(Aws::MakeShared<Aws::Utils::Threading::DefaultExecutor>(CLIENT_CONFIG_TAG)), - verifySSL(true), - writeRateLimiter(nullptr), - readRateLimiter(nullptr), - httpLibOverride(Aws::Http::TransferLibType::DEFAULT_CLIENT), + verifySSL(true), + writeRateLimiter(nullptr), + readRateLimiter(nullptr), + httpLibOverride(Aws::Http::TransferLibType::DEFAULT_CLIENT), followRedirects(FollowRedirectsPolicy::DEFAULT), - disableExpectHeader(false), + disableExpectHeader(false), enableClockSkewAdjustment(true), enableHostPrefixInjection(true), enableEndpointDiscovery(false), profileName(Aws::Auth::GetConfigProfileName()) -{ +{ AWS_LOGSTREAM_DEBUG(CLIENT_CONFIG_TAG, "ClientConfiguration will use SDK Auto Resolved profile: [" << profileName << "] if not specified by users."); // Initialize Retry Strategy @@ -138,8 +138,8 @@ ClientConfiguration::ClientConfiguration() : } region = Aws::String(Aws::Region::US_EAST_1); -} - +} + ClientConfiguration::ClientConfiguration(const char* profile) : ClientConfiguration() { if (profile && Aws::Config::HasCachedConfigProfile(profile)) @@ -156,5 +156,5 @@ ClientConfiguration::ClientConfiguration(const char* profile) : ClientConfigurat AWS_LOGSTREAM_WARN(CLIENT_CONFIG_TAG, "User specified profile: [" << profile << "] is not found, will use the SDK resolved one."); } -} // namespace Client -} // namespace Aws +} // namespace Client +} // namespace Aws diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp index 8c2c288dcd..f9e1357c86 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp @@ -2,22 +2,22 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ - -#include <aws/core/client/AWSError.h> -#include <aws/core/client/CoreErrors.h> + +#include <aws/core/client/AWSError.h> +#include <aws/core/client/CoreErrors.h> #include <aws/core/utils/memory/stl/AWSMap.h> -#include <aws/core/utils/HashingUtils.h> - -using namespace Aws::Client; -using namespace Aws::Utils; -using namespace Aws::Http; - +#include <aws/core/utils/HashingUtils.h> + +using namespace Aws::Client; +using namespace Aws::Utils; +using namespace Aws::Http; + #ifdef _MSC_VER #pragma warning(push) // VS2015 compiler's bug, warning s_CoreErrorsMapper: symbol will be dynamically initialized (implementation limitation) #pragma warning(disable : 4592) #endif - + static Aws::UniquePtr<Aws::Map<Aws::String, AWSError<CoreErrors> > > s_CoreErrorsMapper(nullptr); #ifdef _MSC_VER @@ -25,7 +25,7 @@ static Aws::UniquePtr<Aws::Map<Aws::String, AWSError<CoreErrors> > > s_CoreError #endif void CoreErrorsMapper::InitCoreErrorsMapper() -{ +{ if (s_CoreErrorsMapper) { return; @@ -89,7 +89,7 @@ void CoreErrorsMapper::InitCoreErrorsMapper() s_CoreErrorsMapper->emplace("RequestTimeoutException", AWSError<CoreErrors>(CoreErrors::REQUEST_TIMEOUT, true)); s_CoreErrorsMapper->emplace("RequestTimeout", AWSError<CoreErrors>(CoreErrors::REQUEST_TIMEOUT, true)); } - + void CoreErrorsMapper::CleanupCoreErrorsMapper() { if (s_CoreErrorsMapper) @@ -97,7 +97,7 @@ void CoreErrorsMapper::CleanupCoreErrorsMapper() s_CoreErrorsMapper = nullptr; } } - + AWSError<CoreErrors> CoreErrorsMapper::GetErrorForName(const char* errorName) { auto iter = s_CoreErrorsMapper->find(errorName); @@ -106,46 +106,46 @@ AWSError<CoreErrors> CoreErrorsMapper::GetErrorForName(const char* errorName) return iter->second; } return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false); -} - -AWS_CORE_API AWSError<CoreErrors> CoreErrorsMapper::GetErrorForHttpResponseCode(HttpResponseCode code) -{ - // best effort attempt to map HTTP response codes to CoreErrors - bool retryable = IsRetryableHttpResponseCode(code); +} + +AWS_CORE_API AWSError<CoreErrors> CoreErrorsMapper::GetErrorForHttpResponseCode(HttpResponseCode code) +{ + // best effort attempt to map HTTP response codes to CoreErrors + bool retryable = IsRetryableHttpResponseCode(code); AWSError<CoreErrors> error; switch (code) - { - case HttpResponseCode::UNAUTHORIZED: - case HttpResponseCode::FORBIDDEN: + { + case HttpResponseCode::UNAUTHORIZED: + case HttpResponseCode::FORBIDDEN: error = AWSError<CoreErrors>(CoreErrors::ACCESS_DENIED, retryable); break; - case HttpResponseCode::NOT_FOUND: + case HttpResponseCode::NOT_FOUND: error = AWSError<CoreErrors>(CoreErrors::RESOURCE_NOT_FOUND, retryable); break; - case HttpResponseCode::TOO_MANY_REQUESTS: + case HttpResponseCode::TOO_MANY_REQUESTS: error = AWSError<CoreErrors>(CoreErrors::SLOW_DOWN, retryable); break; - case HttpResponseCode::INTERNAL_SERVER_ERROR: + case HttpResponseCode::INTERNAL_SERVER_ERROR: error = AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, retryable); break; - case HttpResponseCode::BANDWIDTH_LIMIT_EXCEEDED: + case HttpResponseCode::BANDWIDTH_LIMIT_EXCEEDED: error = AWSError<CoreErrors>(CoreErrors::THROTTLING, retryable); break; - case HttpResponseCode::SERVICE_UNAVAILABLE: + case HttpResponseCode::SERVICE_UNAVAILABLE: error = AWSError<CoreErrors>(CoreErrors::SERVICE_UNAVAILABLE, retryable); break; - case HttpResponseCode::REQUEST_TIMEOUT: - case HttpResponseCode::AUTHENTICATION_TIMEOUT: - case HttpResponseCode::LOGIN_TIMEOUT: - case HttpResponseCode::GATEWAY_TIMEOUT: - case HttpResponseCode::NETWORK_READ_TIMEOUT: - case HttpResponseCode::NETWORK_CONNECT_TIMEOUT: + case HttpResponseCode::REQUEST_TIMEOUT: + case HttpResponseCode::AUTHENTICATION_TIMEOUT: + case HttpResponseCode::LOGIN_TIMEOUT: + case HttpResponseCode::GATEWAY_TIMEOUT: + case HttpResponseCode::NETWORK_READ_TIMEOUT: + case HttpResponseCode::NETWORK_CONNECT_TIMEOUT: error = AWSError<CoreErrors>(CoreErrors::REQUEST_TIMEOUT, retryable); break; - default: - int codeValue = static_cast<int>(code); + default: + int codeValue = static_cast<int>(code); error = AWSError<CoreErrors>(CoreErrors::UNKNOWN, codeValue >= 500 && codeValue < 600); - } + } error.SetResponseCode(code); return error; -} +} diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/DefaultRetryStrategy.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/DefaultRetryStrategy.cpp index 7e57c79ffc..ad5c3d613f 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/DefaultRetryStrategy.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/DefaultRetryStrategy.cpp @@ -2,31 +2,31 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ - -#include <aws/core/client/DefaultRetryStrategy.h> - -#include <aws/core/client/AWSError.h> -#include <aws/core/utils/UnreferencedParam.h> - -using namespace Aws; -using namespace Aws::Client; - -bool DefaultRetryStrategy::ShouldRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const -{ - if (attemptedRetries >= m_maxRetries) - return false; - - return error.ShouldRetry(); -} - -long DefaultRetryStrategy::CalculateDelayBeforeNextRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const -{ - AWS_UNREFERENCED_PARAM(error); - - if (attemptedRetries == 0) - { - return 0; - } - - return (1 << attemptedRetries) * m_scaleFactor; -} + +#include <aws/core/client/DefaultRetryStrategy.h> + +#include <aws/core/client/AWSError.h> +#include <aws/core/utils/UnreferencedParam.h> + +using namespace Aws; +using namespace Aws::Client; + +bool DefaultRetryStrategy::ShouldRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const +{ + if (attemptedRetries >= m_maxRetries) + return false; + + return error.ShouldRetry(); +} + +long DefaultRetryStrategy::CalculateDelayBeforeNextRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const +{ + AWS_UNREFERENCED_PARAM(error); + + if (attemptedRetries == 0) + { + return 0; + } + + return (1 << attemptedRetries) * m_scaleFactor; +} |