Skip to content

Commit eb59649

Browse files
committed
fix reviews
1 parent dc742a7 commit eb59649

File tree

10 files changed

+165
-183
lines changed

10 files changed

+165
-183
lines changed

src/aws-cpp-sdk-core/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ file(GLOB AWS_INTERNAL_HEADERS "include/aws/core/internal/*.h")
5151
file(GLOB NET_HEADERS "include/aws/core/net/*.h")
5252
file(GLOB HTTP_HEADERS "include/aws/core/http/*.h")
5353
file(GLOB HTTP_STANDARD_HEADERS "include/aws/core/http/standard/*.h")
54-
file(GLOB HTTP_INTERCEPTOR_HEADERS "include/aws/core/http/interceptor/*.h")
5554
file(GLOB CONFIG_HEADERS "include/aws/core/config/*.h")
5655
file(GLOB CONFIG_DEFAULTS_HEADERS "include/aws/core/config/defaults/*.h")
5756
file(GLOB ENDPOINT_HEADERS "include/aws/core/endpoint/*.h")
@@ -107,7 +106,6 @@ file(GLOB AWS_INTERNAL_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/internal/*.cpp
107106
file(GLOB AWS_MODEL_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/aws/model/*.cpp")
108107
file(GLOB HTTP_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/http/*.cpp")
109108
file(GLOB HTTP_STANDARD_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/http/standard/*.cpp")
110-
file(GLOB HTTP_INTERCEPTOR_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/http/interceptor/*.cpp")
111109
file(GLOB CONFIG_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/config/*.cpp")
112110
file(GLOB CONFIG_DEFAULTS_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/config/defaults/*.cpp")
113111
file(GLOB ENDPOINT_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/endpoint/*.cpp")
@@ -227,7 +225,6 @@ file(GLOB AWS_NATIVE_SDK_COMMON_SRC
227225
${AWS_AUTH_BEARER_TOKEN_PROVIDER_SOURCE}
228226
${AWS_CLIENT_SOURCE}
229227
${HTTP_STANDARD_SOURCE}
230-
${HTTP_INTERCEPTOR_SOURCE}
231228
${HTTP_CLIENT_SOURCE}
232229
${CRT_HTTP_SOURCE}
233230
${CONFIG_SOURCE}
@@ -261,7 +258,6 @@ file(GLOB AWS_NATIVE_SDK_COMMON_HEADERS
261258
${NET_HEADERS}
262259
${HTTP_HEADERS}
263260
${HTTP_STANDARD_HEADERS}
264-
${HTTP_INTERCEPTOR_HEADERS}
265261
${CONFIG_HEADERS}
266262
${CONFIG_DEFAULTS_HEADERS}
267263
${ENDPOINT_HEADERS}
@@ -401,7 +397,6 @@ if(MSVC)
401397
source_group("Header Files\\aws\\core\\net" FILES ${NET_HEADERS})
402398
source_group("Header Files\\aws\\core\\http" FILES ${HTTP_HEADERS})
403399
source_group("Header Files\\aws\\core\\http\\standard" FILES ${HTTP_STANDARD_HEADERS})
404-
source_group("Header Files\\aws\\core\\http\\interceptor" FILES ${HTTP_INTERCEPTOR_HEADERS})
405400
source_group("Header Files\\aws\\core\\config" FILES ${CONFIG_HEADERS})
406401
source_group("Header Files\\aws\\core\\config\\defaults" FILES ${CONFIG_DEFAULTS_HEADERS})
407402
source_group("Header Files\\aws\\core\\endpoint" FILES ${ENDPOINT_HEADERS})
@@ -470,7 +465,6 @@ if(MSVC)
470465
source_group("Source Files\\net\\windows" FILES ${NET_SOURCE})
471466
source_group("Source Files\\http" FILES ${HTTP_SOURCE})
472467
source_group("Source Files\\http\\standard" FILES ${HTTP_STANDARD_SOURCE})
473-
source_group("Source Files\\http\\interceptor" FILES ${HTTP_INTERCEPTOR_SOURCE})
474468
source_group("Source Files\\config" FILES ${CONFIG_SOURCE})
475469
source_group("Source Files\\config\\defaults" FILES ${CONFIG_DEFAULTS_SOURCE})
476470
source_group("Source Files\\endpoint" FILES ${ENDPOINT_SOURCE})
@@ -685,7 +679,6 @@ install (FILES ${AWS_INTERNAL_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core
685679
install (FILES ${NET_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/net)
686680
install (FILES ${HTTP_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/http)
687681
install (FILES ${HTTP_STANDARD_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/http/standard)
688-
install (FILES ${HTTP_INTERCEPTOR_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/http/interceptor)
689682
install (FILES ${CONFIG_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/config/)
690683
install (FILES ${CONFIG_DEFAULTS_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/config/defaults)
691684
install (FILES ${ENDPOINT_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/endpoint)

src/aws-cpp-sdk-core/include/aws/core/client/ClientConfiguration.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ namespace Aws
7979
};
8080

8181
/**
82-
* Control whether ChunkingInterceptor applies aws-chunked encoding.
83-
* ENABLE: Apply aws-chunked encoding for requests with checksums (default)
84-
* DISABLE: Skip ChunkingInterceptor, rely on signer for chunking
82+
* Control HTTP client chunking implementation mode.
83+
* DEFAULT: Use SDK's ChunkingInterceptor for aws-chunked encoding
84+
* CLIENT_IMPLEMENTATION: Rely on HTTP client's native chunking (default for custom clients)
8585
*/
86-
enum class UseAwsChunkedEncoding {
87-
ENABLE,
88-
DISABLE,
86+
enum class HttpClientChunkedMode {
87+
DEFAULT,
88+
CLIENT_IMPLEMENTATION,
8989
};
9090

9191
struct RequestCompressionConfig {
@@ -505,10 +505,10 @@ namespace Aws
505505
Aws::String accountIdEndpointMode = "preferred";
506506

507507
/**
508-
* Control whether ChunkingInterceptor applies aws-chunked encoding.
509-
* Default ENABLE for backward compatibility.
508+
* Control HTTP client chunking implementation mode.
509+
* Default is set automatically: CLIENT_IMPLEMENTATION for custom clients, DEFAULT for AWS clients.
510510
*/
511-
UseAwsChunkedEncoding useAwsChunkedEncoding = UseAwsChunkedEncoding::ENABLE;
511+
HttpClientChunkedMode httpClientChunkedMode = HttpClientChunkedMode::CLIENT_IMPLEMENTATION;
512512
/**
513513
* Configuration structure for credential providers in the AWS SDK.
514514
* This structure allows passing configuration options to credential providers

src/aws-cpp-sdk-core/include/aws/core/http/interceptor/ChunkingInterceptor.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <smithy/tracing/TelemetryProvider.h>
1010
#include <smithy/interceptor/Interceptor.h>
1111
#include <smithy/client/features/ChecksumInterceptor.h>
12+
#include <smithy/client/features/ChunkingInterceptor.h>
1213
#include <smithy/client/features/UserAgentInterceptor.h>
1314

1415
#include <aws/crt/Variant.h>
@@ -101,6 +102,9 @@ namespace client
101102
m_errorMarshaller(std::move(errorMarshaller)),
102103
m_interceptors{Aws::MakeShared<ChecksumInterceptor>("AwsSmithyClientBase", *m_clientConfig)}
103104
{
105+
if (m_clientConfig->httpClientChunkedMode == Aws::Client::HttpClientChunkedMode::DEFAULT) {
106+
m_interceptors.emplace_back(Aws::MakeShared<features::ChunkingInterceptor>("AwsSmithyClientBase", *m_clientConfig));
107+
}
104108
baseInit();
105109
}
106110

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#pragma once
7+
8+
#include <aws/core/Core_EXPORTS.h>
9+
#include <aws/core/client/ClientConfiguration.h>
10+
#include <aws/core/utils/stream/AwsChunkedStream.h>
11+
#include <smithy/interceptor/Interceptor.h>
12+
#include <smithy/client/common/AwsSmithyClientUtils.h>
13+
14+
namespace smithy {
15+
namespace client {
16+
namespace features {
17+
18+
namespace {
19+
20+
class AwsChunkedStreamBuf : public std::streambuf {
21+
public:
22+
AwsChunkedStreamBuf(Aws::Http::HttpRequest* request, const std::shared_ptr<Aws::IOStream>& originalBody)
23+
: m_chunkStream(request, originalBody) {
24+
setg(nullptr, nullptr, nullptr);
25+
}
26+
27+
protected:
28+
int_type underflow() override {
29+
if (gptr() < egptr()) {
30+
return traits_type::to_int_type(*gptr());
31+
}
32+
33+
size_t bytesRead = m_chunkStream.BufferedRead(m_buffer, sizeof(m_buffer));
34+
if (bytesRead == 0) {
35+
return traits_type::eof();
36+
}
37+
38+
setg(m_buffer, m_buffer, m_buffer + bytesRead);
39+
return traits_type::to_int_type(*gptr());
40+
}
41+
42+
std::streamsize showmanyc() override {
43+
return egptr() - gptr();
44+
}
45+
46+
private:
47+
Aws::Utils::Stream::AwsChunkedStream<> m_chunkStream;
48+
char m_buffer[8192];
49+
};
50+
51+
} // anonymous namespace
52+
53+
/**
54+
* Interceptor that handles chunked encoding for streaming requests with checksums.
55+
* Wraps request body with chunked stream and sets appropriate headers.
56+
*/
57+
class AWS_CORE_API ChunkingInterceptor : public smithy::interceptor::Interceptor {
58+
public:
59+
ChunkingInterceptor() : m_httpClientChunkedMode(Aws::Client::HttpClientChunkedMode::DEFAULT) {}
60+
explicit ChunkingInterceptor(const Aws::Client::ClientConfiguration& config)
61+
: m_httpClientChunkedMode(config.httpClientChunkedMode) {}
62+
~ChunkingInterceptor() override = default;
63+
64+
ModifyRequestOutcome ModifyBeforeSigning(smithy::interceptor::InterceptorContext& context) override {
65+
auto request = context.GetTransmitRequest();
66+
67+
if (!ShouldApplyChunking(request)) {
68+
return request;
69+
}
70+
71+
auto originalBody = request->GetContentBody();
72+
if (!originalBody) {
73+
return request;
74+
}
75+
76+
// Set up chunked encoding headers for checksum calculation
77+
const auto& hashPair = request->GetRequestHash();
78+
if (hashPair.second != nullptr) {
79+
Aws::String checksumHeaderValue = Aws::String("x-amz-checksum-") + hashPair.first;
80+
request->DeleteHeader(checksumHeaderValue.c_str());
81+
request->SetHeaderValue(Aws::Http::AWS_TRAILER_HEADER, checksumHeaderValue);
82+
request->SetTransferEncoding(Aws::Http::CHUNKED_VALUE);
83+
84+
if (!request->HasContentEncoding()) {
85+
request->SetContentEncoding(Aws::Http::AWS_CHUNKED_VALUE);
86+
} else {
87+
Aws::String currentEncoding = request->GetContentEncoding();
88+
if (currentEncoding.find(Aws::Http::AWS_CHUNKED_VALUE) == Aws::String::npos) {
89+
request->SetContentEncoding(Aws::String{Aws::Http::AWS_CHUNKED_VALUE} + "," + currentEncoding);
90+
}
91+
}
92+
93+
if (request->HasHeader(Aws::Http::CONTENT_LENGTH_HEADER)) {
94+
request->SetHeaderValue(Aws::Http::DECODED_CONTENT_LENGTH_HEADER, request->GetHeaderValue(Aws::Http::CONTENT_LENGTH_HEADER));
95+
request->DeleteHeader(Aws::Http::CONTENT_LENGTH_HEADER);
96+
}
97+
}
98+
99+
auto chunkedBuf = Aws::MakeUnique<AwsChunkedStreamBuf>(
100+
"ChunkingInterceptor", request.get(), originalBody);
101+
auto chunkedBody = std::shared_ptr<Aws::IOStream>(
102+
new Aws::IOStream(chunkedBuf.release()));
103+
104+
request->AddContentBody(chunkedBody);
105+
return request;
106+
}
107+
108+
ModifyResponseOutcome ModifyBeforeDeserialization(smithy::interceptor::InterceptorContext& context) override {
109+
return context.GetTransmitResponse();
110+
}
111+
112+
private:
113+
bool ShouldApplyChunking(const std::shared_ptr<Aws::Http::HttpRequest>& request) const {
114+
if (!request || !request->GetContentBody()) {
115+
return false;
116+
}
117+
118+
// Check if request has checksum requirements
119+
const auto& hashPair = request->GetRequestHash();
120+
bool hasChecksum = hashPair.second != nullptr;
121+
122+
if (!hasChecksum) {
123+
return false;
124+
}
125+
126+
// Use configuration setting to determine chunking behavior
127+
return m_httpClientChunkedMode == Aws::Client::HttpClientChunkedMode::DEFAULT;
128+
}
129+
130+
Aws::Client::HttpClientChunkedMode m_httpClientChunkedMode;
131+
};
132+
133+
} // namespace features
134+
} // namespace client
135+
} // namespace smithy

src/aws-cpp-sdk-core/source/auth/signer/AWSAuthV4Signer.cpp

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -218,31 +218,10 @@ bool AWSAuthV4Signer::SignRequestWithCreds(Aws::Http::HttpRequest& request, cons
218218
request.SetAwsSessionToken(credentials.GetSessionToken());
219219
}
220220

221-
// If the request checksum, set the signer to use a unsigned
222-
// trailing payload. otherwise use it in the header
223-
if (request.GetRequestHash().second != nullptr && !request.GetRequestHash().first.empty() && request.GetContentBody() != nullptr) {
224-
AWS_LOGSTREAM_DEBUG(v4LogTag, "Note: Http payloads are not being signed. signPayloads="
225-
<< signBody << " http scheme=" << Http::SchemeMapper::ToString(request.GetUri().GetScheme()));
226-
if (request.GetRequestHash().second != nullptr) {
221+
// If the request has checksum and chunking was applied by interceptor, use streaming payload
222+
if (request.GetRequestHash().second != nullptr && !request.GetRequestHash().first.empty() &&
223+
request.GetContentBody() != nullptr && request.HasHeader(Http::AWS_TRAILER_HEADER)) {
227224
payloadHash = STREAMING_UNSIGNED_PAYLOAD_TRAILER;
228-
Aws::String checksumHeaderValue = Aws::String("x-amz-checksum-") + request.GetRequestHash().first;
229-
request.DeleteHeader(checksumHeaderValue.c_str());
230-
request.SetHeaderValue(Http::AWS_TRAILER_HEADER, checksumHeaderValue);
231-
request.SetTransferEncoding(CHUNKED_VALUE);
232-
if (!request.HasContentEncoding()) {
233-
request.SetContentEncoding(Http::AWS_CHUNKED_VALUE);
234-
} else {
235-
Aws::String currentEncoding = request.GetContentEncoding();
236-
if (currentEncoding.find(Http::AWS_CHUNKED_VALUE) == Aws::String::npos) {
237-
request.SetContentEncoding(Aws::String{Http::AWS_CHUNKED_VALUE} + "," + currentEncoding);
238-
}
239-
}
240-
241-
if (request.HasHeader(Http::CONTENT_LENGTH_HEADER)) {
242-
request.SetHeaderValue(Http::DECODED_CONTENT_LENGTH_HEADER, request.GetHeaderValue(Http::CONTENT_LENGTH_HEADER));
243-
request.DeleteHeader(Http::CONTENT_LENGTH_HEADER);
244-
}
245-
}
246225
} else {
247226
payloadHash = ComputePayloadHash(request);
248227
if (payloadHash.empty()) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
#include <smithy/tracing/TracingUtils.h>
4848
#include <smithy/client/features/ChecksumInterceptor.h>
49-
#include <aws/core/http/interceptor/ChunkingInterceptor.h>
49+
#include <smithy/client/features/ChunkingInterceptor.h>
5050

5151
#include <cstring>
5252
#include <cassert>
@@ -140,7 +140,7 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
140140
m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment),
141141
m_requestCompressionConfig(configuration.requestCompressionConfig),
142142
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<Aws::Http::ChunkingInterceptor>(AWS_CLIENT_LOG_TAG), m_userAgentInterceptor}
143+
m_interceptors{Aws::MakeShared<smithy::client::ChecksumInterceptor>(AWS_CLIENT_LOG_TAG), Aws::MakeShared<smithy::client::features::ChunkingInterceptor>(AWS_CLIENT_LOG_TAG), m_userAgentInterceptor}
144144
{
145145
}
146146

@@ -166,7 +166,7 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration,
166166
m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment),
167167
m_requestCompressionConfig(configuration.requestCompressionConfig),
168168
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<Aws::Http::ChunkingInterceptor>(AWS_CLIENT_LOG_TAG), m_userAgentInterceptor}
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}
170170
{
171171
}
172172

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ void setLegacyClientConfigurationParameters(ClientConfiguration& clientConfig)
220220
clientConfig.writeRateLimiter = nullptr;
221221
clientConfig.readRateLimiter = nullptr;
222222
clientConfig.httpLibOverride = Aws::Http::TransferLibType::DEFAULT_CLIENT;
223+
224+
// Set chunking mode based on HTTP client type
225+
// AWS built-in clients should use SDK's ChunkingInterceptor (DEFAULT mode)
226+
// Custom clients should handle chunking themselves (CLIENT_IMPLEMENTATION mode)
227+
clientConfig.httpClientChunkedMode = HttpClientChunkedMode::DEFAULT;
228+
223229
clientConfig.followRedirects = FollowRedirectsPolicy::DEFAULT;
224230
clientConfig.disableExpectHeader = false;
225231
clientConfig.enableClockSkewAdjustment = true;

0 commit comments

Comments
 (0)