Skip to content

Commit a6b040e

Browse files
committed
refactor out chunk framing
squash 083ea7a # refactor out chunk framing
1 parent 6bedf17 commit a6b040e

File tree

12 files changed

+96
-68
lines changed

12 files changed

+96
-68
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ 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")
54+
file(GLOB HTTP_INTERCEPTOR_HEADERS "include/aws/core/http/interceptor/*.h")
5555
file(GLOB CONFIG_HEADERS "include/aws/core/config/*.h")
5656
file(GLOB CONFIG_DEFAULTS_HEADERS "include/aws/core/config/defaults/*.h")
5757
file(GLOB ENDPOINT_HEADERS "include/aws/core/endpoint/*.h")
@@ -470,7 +470,6 @@ if(MSVC)
470470
source_group("Source Files\\net\\windows" FILES ${NET_SOURCE})
471471
source_group("Source Files\\http" FILES ${HTTP_SOURCE})
472472
source_group("Source Files\\http\\standard" FILES ${HTTP_STANDARD_SOURCE})
473-
474473
source_group("Source Files\\http\\interceptor" FILES ${HTTP_INTERCEPTOR_SOURCE})
475474
source_group("Source Files\\config" FILES ${CONFIG_SOURCE})
476475
source_group("Source Files\\config\\defaults" FILES ${CONFIG_DEFAULTS_SOURCE})

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/include/aws/core/http/windows/WinHttpSyncHttpClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ namespace Aws
5151
bool DoReceiveResponse(void* httpRequest) const override;
5252
bool DoQueryHeaders(void* httpRequest, std::shared_ptr<Aws::Http::HttpResponse>& response, Aws::StringStream& ss, uint64_t& read) const override;
5353
bool DoSendRequest(void* httpRequest) const override;
54-
bool DoSendRequest(void* httpRequest, const std::shared_ptr<HttpRequest>& request) const;
5554
bool DoQueryDataAvailable(void* hHttpRequest, uint64_t& available) const override;
5655
bool DoReadData(void* hHttpRequest, char* body, uint64_t size, uint64_t& read) const override;
5756
void* GetClientModule() const override;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ namespace Aws
4949
bool DoReceiveResponse(void* hHttpRequest) const override;
5050
bool DoQueryHeaders(void* hHttpRequest, std::shared_ptr<Aws::Http::HttpResponse>& response, Aws::StringStream& ss, uint64_t& read) const override;
5151
bool DoSendRequest(void* hHttpRequest) const override;
52-
bool DoSendRequest(void* hHttpRequest, const std::shared_ptr<HttpRequest>& request) const override;
5352
bool DoQueryDataAvailable(void* hHttpRequest, uint64_t& available) const override;
5453
bool DoReadData(void* hHttpRequest, char* body, uint64_t size, uint64_t& read) const override;
5554
void* GetClientModule() const override;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <aws/core/auth/AWSAuthSigner.h>
1212
#include <aws/core/http/HttpClient.h>
1313
#include <aws/core/http/standard/StandardHttpResponse.h>
14-
#include <aws/core/utils/UnreferencedParam.h>
1514

1615
namespace Aws
1716
{
@@ -93,10 +92,6 @@ namespace Aws
9392
virtual bool DoReceiveResponse(void* hHttpRequest) const = 0;
9493
virtual bool DoQueryHeaders(void* hHttpRequest, std::shared_ptr<Aws::Http::HttpResponse>& response, Aws::StringStream& ss, uint64_t& read) const = 0;
9594
virtual bool DoSendRequest(void* hHttpRequest) const = 0;
96-
virtual bool DoSendRequest(void* hHttpRequest, const std::shared_ptr<HttpRequest>& request) const {
97-
AWS_UNREFERENCED_PARAM(request);
98-
return DoSendRequest(hHttpRequest);
99-
}
10095
virtual bool DoQueryDataAvailable(void* hHttpRequest, uint64_t& available) const = 0;
10196
virtual bool DoReadData(void* hHttpRequest, char* body, uint64_t size, uint64_t& read) const = 0;
10297
virtual void* GetClientModule() const = 0;

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,13 @@ 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-
// Only add aws-chunked if it's not already present to avoid duplication
233-
if (request.HasContentEncoding()) {
234-
const auto& currentEncoding = request.GetContentEncoding();
232+
if (!request.HasContentEncoding()) {
233+
request.SetContentEncoding(Http::AWS_CHUNKED_VALUE);
234+
} else {
235+
Aws::String currentEncoding = request.GetContentEncoding();
235236
if (currentEncoding.find(Http::AWS_CHUNKED_VALUE) == Aws::String::npos) {
236237
request.SetContentEncoding(Aws::String{Http::AWS_CHUNKED_VALUE} + "," + currentEncoding);
237238
}
238-
} else {
239-
request.SetContentEncoding(Http::AWS_CHUNKED_VALUE);
240239
}
241240

242241
if (request.HasHeader(Http::CONTENT_LENGTH_HEADER)) {

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

Lines changed: 9 additions & 0 deletions
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

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

Lines changed: 9 additions & 2 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
}
@@ -65,8 +70,10 @@ ChunkingInterceptor::ModifyRequestOutcome ChunkingInterceptor::ModifyBeforeSigni
6570

6671
request->AddContentBody(chunkedBody);
6772

68-
// Set Transfer-Encoding: chunked for aws-chunked requests
69-
request->SetTransferEncoding("chunked");
73+
// Set Transfer-Encoding: chunked for aws-chunked requests (only if not already set)
74+
if (!request->HasTransferEncoding()) {
75+
request->SetTransferEncoding("chunked");
76+
}
7077

7178
// Move Content-Length to x-amz-decoded-content-length and remove Content-Length
7279
if (request->HasHeader("Content-Length")) {

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -735,25 +735,6 @@ bool WinHttpSyncHttpClient::DoSendRequest(void* hHttpRequest) const
735735
return success;
736736
}
737737

738-
bool WinHttpSyncHttpClient::DoSendRequest(void* hHttpRequest, const std::shared_ptr<HttpRequest>& request) const
739-
{
740-
// Check if this is a Transfer-Encoding: chunked request
741-
if (request->HasTransferEncoding() && request->GetTransferEncoding().find("chunked") != Aws::String::npos) {
742-
// For chunked requests, use WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH
743-
bool success = WinHttpSendRequest(hHttpRequest, NULL, 0, NULL, 0, 0xFFFFFFFF, 0) != 0;
744-
if (!success)
745-
{
746-
DWORD lastError = GetLastError();
747-
AWS_LOGSTREAM_ERROR(GetLogTag(), "WinHttpSendRequest failed for chunked request. Error: " << lastError << " (0x" << std::hex << lastError << std::dec << ")");
748-
AzWinHttpLogLastError("WinHttpSendRequest");
749-
}
750-
return success;
751-
} else {
752-
// For regular requests, use the original method
753-
return DoSendRequest(hHttpRequest);
754-
}
755-
}
756-
757738
bool WinHttpSyncHttpClient::DoQueryDataAvailable(void* hHttpRequest, uint64_t& available) const
758739
{
759740
return (WinHttpQueryDataAvailable(hHttpRequest, (LPDWORD)&available) != 0);

0 commit comments

Comments
 (0)