Describe the bug
The HeadersReceivedEventHandler is invoked in the WriteData callback, and therefore it is only invoked if the response body bytes > 0. This is incorrect, and the CrtHttpClient fires the callback regardless of response body size.
// CurlHttpClient.cpp line 197-200
auto& headersHandler = context->m_request->GetHeadersReceivedEventHandler();
if (context->m_numBytesResponseReceived == 0 && headersHandler)
{
headersHandler(context->m_request, context->m_response);
}
Regression Issue
Expected Behavior
The HeadersReceivedEventHandler is invoked regardless of body size
Current Behavior
The HeadersReceivedEventHandler is invoked only if response body size > 0
Reproduction Steps
bool doPutObject(const char* label) {
std::cout << "\n=== " << label << " ===\n";
Aws::Client::ClientConfiguration config;
config.region = REGION;
Aws::S3::S3Client client(config);
Aws::S3::Model::PutObjectRequest request;
request.SetBucket(BUCKET);
request.SetKey(KEY);
auto body = Aws::MakeShared<Aws::StringStream>("PutBody");
*body << "hello";
request.SetBody(body);
std::atomic<bool> handlerFired{false};
request.SetHeadersReceivedEventHandler(
[&handlerFired](const Aws::Http::HttpRequest*, Aws::Http::HttpResponse* response) {
handlerFired = true;
std::cout << " [HeadersReceivedEventHandler FIRED]\n";
for (const auto& h : response->GetHeaders()) {
std::cout << " " << h.first << ": " << h.second << "\n";
}
});
auto outcome = client.PutObject(request);
if (outcome.IsSuccess()) {
std::cout << " PutObject succeeded. ETag: " << outcome.GetResult().GetETag() << "\n";
} else {
std::cout << " PutObject FAILED: " << outcome.GetError().GetMessage() << "\n";
}
std::cout << " Handler fired: " << (handlerFired.load() ? "YES" : "NO") << "\n";
return handlerFired.load();
}
Possible Solution
Move to WriteHeader callback
Additional Information/Context
No response
AWS CPP SDK version used
latest (built from source)
Compiler and Version used
clang version 17.0.0
Operating System and version
MacOS
Describe the bug
The
HeadersReceivedEventHandleris invoked in theWriteDatacallback, and therefore it is only invoked if the response body bytes > 0. This is incorrect, and theCrtHttpClientfires the callback regardless of response body size.Regression Issue
Expected Behavior
The
HeadersReceivedEventHandleris invoked regardless of body sizeCurrent Behavior
The
HeadersReceivedEventHandleris invoked only if response body size > 0Reproduction Steps
Possible Solution
Move to
WriteHeadercallbackAdditional Information/Context
No response
AWS CPP SDK version used
latest (built from source)
Compiler and Version used
clang version 17.0.0
Operating System and version
MacOS