Skip to content

Commit 28a4eb9

Browse files
committed
AmazonWebServiceRequest - RetryContext to be private, and contain a pointer to the request hash pair
1 parent 4a559fc commit 28a4eb9

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/aws-cpp-sdk-core/include/aws/core/AmazonWebServiceRequest.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Aws
3636
typedef std::function<void(const Aws::Http::HttpRequest&)> RequestSignedHandler;
3737

3838
struct RetryContext {
39-
std::pair<Aws::String, std::shared_ptr<Aws::Utils::Crypto::Hash>> m_requestHash;
39+
std::shared_ptr<std::pair<Aws::String, std::shared_ptr<Aws::Utils::Crypto::Hash>>> m_requestHash = nullptr;
4040
};
4141

4242
/**
@@ -228,7 +228,9 @@ namespace Aws
228228

229229
inline virtual bool RequestChecksumRequired() const { return false; }
230230

231-
mutable Aws::RetryContext m_retryContext;
231+
RetryContext GetRetryContext() const { return m_retryContext; }
232+
233+
void SetRetryContext(const RetryContext& context) const { m_retryContext = context; }
232234
protected:
233235
/**
234236
* Default does nothing. Override this to convert what would otherwise be the payload of the
@@ -248,6 +250,7 @@ namespace Aws
248250
RequestRetryHandler m_requestRetryHandler;
249251
mutable std::shared_ptr<Aws::Http::ServiceSpecificParameters> m_serviceSpecificParameters;
250252
mutable Aws::Set<Client::UserAgentFeature> m_userAgentFeatures;
253+
mutable Aws::RetryContext m_retryContext;
251254
};
252255

253256
} // namespace Aws

src/aws-cpp-sdk-core/source/client/AWSClient.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,13 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri,
391391
}
392392

393393
// Save checksum information from the original request if we haven't already - safe to assume that the checksum has been finalized, since we have sent and received a response
394-
if (request.m_retryContext.m_requestHash.second == nullptr) {
394+
RetryContext context = request.GetRetryContext();
395+
if (context.m_requestHash == nullptr) {
395396
auto originalRequestHash = httpRequest->GetRequestHash();
396-
request.m_retryContext.m_requestHash = originalRequestHash;
397+
if (originalRequestHash.second != nullptr) {
398+
context.m_requestHash = Aws::MakeShared<std::pair<Aws::String, std::shared_ptr<Aws::Utils::Crypto::Hash>>>(AWS_CLIENT_LOG_TAG, originalRequestHash);
399+
request.SetRetryContext(context);
400+
}
397401
}
398402

399403
httpRequest = CreateHttpRequest(newUri, method, request.GetResponseStreamFactory());
@@ -929,9 +933,10 @@ void AWSClient::BuildHttpRequest(const Aws::AmazonWebServiceRequest& request, co
929933
request.AddQueryStringParameters(httpRequest->GetUri());
930934

931935
// check for retry context, if present use it
932-
if (request.m_retryContext.m_requestHash.second != nullptr) {
933-
const auto hash = Aws::MakeShared<Aws::Utils::Crypto::PrecalculatedHash>(smithy::client::AWS_SMITHY_CLIENT_CHECKSUM, HashingUtils::Base64Encode(request.m_retryContext.m_requestHash.second->GetHash().GetResult()));
934-
httpRequest->SetRequestHash(request.m_retryContext.m_requestHash.first, hash);
936+
RetryContext context = request.GetRetryContext();
937+
if (context.m_requestHash != nullptr) {
938+
const auto hash = Aws::MakeShared<Aws::Utils::Crypto::PrecalculatedHash>(smithy::client::AWS_SMITHY_CLIENT_CHECKSUM, HashingUtils::Base64Encode(context.m_requestHash->second->GetHash().GetResult()));
939+
httpRequest->SetRequestHash(context.m_requestHash->first, hash);
935940
}
936941
}
937942

0 commit comments

Comments
 (0)