Skip to content

Commit e06513f

Browse files
committed
refactor out chunk framing
1 parent 6a3876a commit e06513f

File tree

6 files changed

+57
-10
lines changed

6 files changed

+57
-10
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ namespace Aws
7878
WHEN_REQUIRED,
7979
};
8080

81+
/**
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
85+
*/
86+
enum class UseAwsChunkedEncoding {
87+
ENABLE,
88+
DISABLE,
89+
};
90+
8191
struct RequestCompressionConfig {
8292
UseRequestCompression useRequestCompression=UseRequestCompression::ENABLE;
8393
size_t requestMinCompressionSizeBytes = 10240;
@@ -493,6 +503,12 @@ namespace Aws
493503
* https://docs.aws.amazon.com/sdkref/latest/guide/feature-account-endpoints.html
494504
*/
495505
Aws::String accountIdEndpointMode = "preferred";
506+
507+
/**
508+
* Control whether ChunkingInterceptor applies aws-chunked encoding.
509+
* Default ENABLE for backward compatibility.
510+
*/
511+
UseAwsChunkedEncoding useAwsChunkedEncoding = UseAwsChunkedEncoding::ENABLE;
496512
/**
497513
* Configuration structure for credential providers in the AWS SDK.
498514
* This structure allows passing configuration options to credential providers

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ namespace Aws
1919
*/
2020
class ChunkingInterceptor : public smithy::interceptor::Interceptor {
2121
public:
22-
ChunkingInterceptor() = default;
22+
explicit ChunkingInterceptor(Aws::Client::UseAwsChunkedEncoding useAwsChunkedEncoding = Aws::Client::UseAwsChunkedEncoding::ENABLE)
23+
: m_useAwsChunkedEncoding(useAwsChunkedEncoding) {}
2324
~ChunkingInterceptor() override = default;
2425

2526
ModifyRequestOutcome ModifyBeforeSigning(smithy::interceptor::InterceptorContext& context) override;
2627
ModifyResponseOutcome ModifyBeforeDeserialization(smithy::interceptor::InterceptorContext& context) override;
2728

2829
private:
2930
bool ShouldApplyAwsChunking(const std::shared_ptr<Aws::Http::HttpRequest>& request) const;
31+
Aws::Client::UseAwsChunkedEncoding m_useAwsChunkedEncoding;
3032
};
3133

3234
} // namespace Http

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,14 @@ bool AWSAuthV4Signer::SignRequestWithCreds(Aws::Http::HttpRequest& request, cons
229229
request.DeleteHeader(checksumHeaderValue.c_str());
230230
request.SetHeaderValue(Http::AWS_TRAILER_HEADER, checksumHeaderValue);
231231
request.SetTransferEncoding(CHUNKED_VALUE);
232-
request.HasContentEncoding()
233-
? request.SetContentEncoding(Aws::String{Http::AWS_CHUNKED_VALUE} + "," + request.GetContentEncoding())
234-
: request.SetContentEncoding(Http::AWS_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+
}
235240

236241
if (request.HasHeader(Http::CONTENT_LENGTH_HEADER)) {
237242
request.SetHeaderValue(Http::DECODED_CONTENT_LENGTH_HEADER, request.GetHeaderValue(Http::CONTENT_LENGTH_HEADER));

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ Aws::String UserAgent::SerializeWithFeatures(const Aws::Set<UserAgentFeature>& f
182182
SerializeMetadata(METADATA, m_compilerMetadata);
183183
}
184184

185+
// Add HTTP client metadata
186+
#if AWS_SDK_USE_CRT_HTTP
187+
SerializeMetadata(METADATA, "http#crt");
188+
#elif ENABLE_CURL_CLIENT
189+
SerializeMetadata(METADATA, "http#curl");
190+
#elif ENABLE_WINDOWS_CLIENT
191+
SerializeMetadata(METADATA, "http#winhttp");
192+
#endif
193+
185194
// metrics
186195
Aws::Vector<Aws::String> encodedMetrics{};
187196

@@ -217,7 +226,9 @@ Aws::String UserAgent::SerializeWithFeatures(const Aws::Set<UserAgentFeature>& f
217226
});
218227
}
219228

220-
return userAgentValue.str();
229+
auto finalUserAgent = userAgentValue.str();
230+
AWS_LOGSTREAM_DEBUG(LOG_TAG, "Generated User-Agent: " << finalUserAgent);
231+
return finalUserAgent;
221232
}
222233

223234
namespace {

src/aws-cpp-sdk-core/source/http/interceptor/ChunkingInterceptor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class AwsChunkedIOStream : public Aws::IOStream {
5151
ChunkingInterceptor::ModifyRequestOutcome ChunkingInterceptor::ModifyBeforeSigning(
5252
smithy::interceptor::InterceptorContext& context) {
5353
auto request = context.GetTransmitRequest();
54+
55+
if (m_useAwsChunkedEncoding == Aws::Client::UseAwsChunkedEncoding::DISABLE) {
56+
return request;
57+
}
58+
5459
if (!ShouldApplyAwsChunking(request)) {
5560
return request;
5661
}

src/aws-cpp-sdk-core/source/http/windows/WinSyncHttpClient.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,23 @@ bool WinSyncHttpClient::StreamPayloadToRequest(const std::shared_ptr<HttpRequest
141141
success = success && ContinueRequest(*request) && IsRequestProcessingEnabled();
142142
}
143143

144+
if (success && isChunked)
145+
{
146+
bytesWritten = FinalizeWriteData(hHttpRequest);
147+
if (!bytesWritten)
148+
{
149+
success = false;
150+
}
151+
else if (writeLimiter)
152+
{
153+
writeLimiter->ApplyAndPayForCost(bytesWritten);
154+
}
155+
}
156+
144157
payloadStream->clear();
145158
payloadStream->seekg(startingPos, payloadStream->beg);
146159
}
147160

148-
if (success && isChunked)
149-
{
150-
FinalizeWriteData(hHttpRequest);
151-
}
152-
153161
if(success)
154162
{
155163
success = DoReceiveResponse(hHttpRequest);

0 commit comments

Comments
 (0)