Skip to content

Commit 2f425ed

Browse files
committed
added logic to detect custom http client
1 parent 0349a5e commit 2f425ed

File tree

8 files changed

+33
-11
lines changed

8 files changed

+33
-11
lines changed

src/aws-cpp-sdk-core/include/aws/core/http/HttpClient.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ namespace Aws
4848
*/
4949
virtual bool SupportsChunkedTransferEncoding() const { return true; }
5050

51+
/**
52+
* Returns true if this is a default AWS SDK HTTP client implementation.
53+
*/
54+
virtual bool IsDefaultAwsHttpClient() const { return false; }
55+
5156
/**
5257
* Stops all requests in progress and prevents any others from initiating.
5358
*/

src/aws-cpp-sdk-core/include/aws/core/http/crt/CRTHttpClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ namespace Aws
5252
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter,
5353
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter) const override;
5454

55+
bool IsDefaultAwsHttpClient() const override { return true; }
56+
5557
private:
5658
// Yeah, I know, but someone made MakeRequest() const and didn't think about the fact that
5759
// making an HTTP request most certainly mutates state. It was me. I'm the person that did that, and

src/aws-cpp-sdk-core/include/aws/core/http/curl/CurlHttpClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class AWS_CORE_API CurlHttpClient: public HttpClient
3737
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
3838
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const override;
3939

40+
bool IsDefaultAwsHttpClient() const override { return true; }
41+
4042
static void InitGlobalState();
4143
static void CleanupGlobalState();
4244

src/aws-cpp-sdk-core/include/aws/core/http/windows/IXmlHttpRequest2HttpClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ namespace Aws
5454
*/
5555
virtual bool SupportsChunkedTransferEncoding() const override { return false; }
5656

57+
bool IsDefaultAwsHttpClient() const override { return true; }
58+
5759
protected:
5860
/**
5961
* Override any configuration on request handle.

src/aws-cpp-sdk-core/include/aws/core/http/windows/WinHttpSyncHttpClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ namespace Aws
4242
*/
4343
const char* GetLogTag() const override { return "WinHttpSyncHttpClient"; }
4444

45+
bool IsDefaultAwsHttpClient() const override { return true; }
46+
4547
private:
4648
// WinHttp specific implementations
4749
void* OpenRequest(const std::shared_ptr<HttpRequest>& request, void* connection, const Aws::StringStream& ss) const override;

src/aws-cpp-sdk-core/include/aws/core/http/windows/WinINetSyncHttpClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace Aws
3939
* Gets log tag for use in logging in the base class.
4040
*/
4141
const char* GetLogTag() const override { return "WinInetSyncHttpClient"; }
42+
43+
bool IsDefaultAwsHttpClient() const override { return true; }
4244
private:
4345

4446
// WinHttp specific implementations

src/aws-cpp-sdk-core/include/smithy/client/features/ChunkingInterceptor.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AwsChunkedStreamBuf : public std::streambuf {
2929
AwsChunkedStreamBuf(Aws::Http::HttpRequest* request,
3030
const std::shared_ptr<Aws::IOStream>& stream,
3131
size_t bufferSize = DataBufferSize)
32-
: m_chunkingStream(Aws::MakeShared<Aws::StringStream>("AwsChunkedStream")),
32+
: m_chunkingStream(Aws::MakeShared<Aws::StringStream>(ALLOCATION_TAG)),
3333
m_request(request),
3434
m_stream(stream),
3535
m_data(bufferSize)
@@ -191,20 +191,18 @@ class ChunkingInterceptor : public smithy::interceptor::Interceptor {
191191

192192
private:
193193
bool ShouldApplyChunking(const std::shared_ptr<Aws::Http::HttpRequest>& request) const {
194-
if (!request || !request->GetContentBody()) {
194+
// Use configuration setting to determine chunking behavior
195+
if (m_httpClientChunkedMode != Aws::Client::HttpClientChunkedMode::DEFAULT) {
195196
return false;
196197
}
197198

198-
// Check if request has checksum requirements
199-
const auto& hashPair = request->GetRequestHash();
200-
bool hasChecksum = hashPair.second != nullptr;
201-
202-
if (!hasChecksum) {
199+
if (!request || !request->GetContentBody()) {
203200
return false;
204201
}
205202

206-
// Use configuration setting to determine chunking behavior
207-
return m_httpClientChunkedMode == Aws::Client::HttpClientChunkedMode::DEFAULT;
203+
// Check if request has checksum requirements
204+
const auto& hashPair = request->GetRequestHash();
205+
return hashPair.second != nullptr;
208206
}
209207

210208
Aws::Client::HttpClientChunkedMode m_httpClientChunkedMode;

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ struct RequestInfo
118118
}
119119
};
120120

121+
static ClientConfiguration GetChunkingConfig(const ClientConfiguration& config, const std::shared_ptr<HttpClient>& httpClient)
122+
{
123+
ClientConfiguration chunkingConfig(config);
124+
if (!httpClient->IsDefaultAwsHttpClient()) {
125+
chunkingConfig.httpClientChunkedMode = HttpClientChunkedMode::CLIENT_IMPLEMENTATION;
126+
}
127+
return chunkingConfig;
128+
}
129+
121130
AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
122131
const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer,
123132
const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) :
@@ -140,7 +149,7 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
140149
m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment),
141150
m_requestCompressionConfig(configuration.requestCompressionConfig),
142151
m_userAgentInterceptor{Aws::MakeShared<smithy::client::UserAgentInterceptor>(AWS_CLIENT_LOG_TAG, configuration, m_retryStrategy->GetStrategyName(), m_serviceName)},
143-
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG), Aws::MakeShared<smithy::client::features::ChunkingInterceptor>(AWS_CLIENT_LOG_TAG, configuration), m_userAgentInterceptor}
152+
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG), Aws::MakeShared<smithy::client::features::ChunkingInterceptor>(AWS_CLIENT_LOG_TAG, GetChunkingConfig(configuration, m_httpClient)), m_userAgentInterceptor}
144153
{
145154
}
146155

@@ -166,7 +175,7 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
166175
m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment),
167176
m_requestCompressionConfig(configuration.requestCompressionConfig),
168177
m_userAgentInterceptor{Aws::MakeShared<smithy::client::UserAgentInterceptor>(AWS_CLIENT_LOG_TAG, configuration, m_retryStrategy->GetStrategyName(), m_serviceName)},
169-
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG, configuration), Aws::MakeShared<smithy::client::features::ChunkingInterceptor>(AWS_CLIENT_LOG_TAG, configuration), m_userAgentInterceptor}
178+
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG, configuration), Aws::MakeShared<smithy::client::features::ChunkingInterceptor>(AWS_CLIENT_LOG_TAG, GetChunkingConfig(configuration, m_httpClient)), m_userAgentInterceptor}
170179
{
171180
}
172181

0 commit comments

Comments
 (0)