Skip to content

CURL client: GetResponseCode always returns -1 (REQUEST_NOT_MADE) in HeadersReceivedEventHandler #3234

@bytechunk

Description

@bytechunk

Describe the bug

When using HeadersReceivedEventHandler (request.SetHeadersReceivedEventHandler), the response object passed on handler invocation is not fully set according to HTTP header section content.

In my case, response->GetResponseCode ( ) always returns -1 (REQUEST_NOT_MADE) whatever the HTTP status code returned by the server in its header section.

I did not check values returned by other methods of the response object (I only had a kick look at GetContentType) at that time but it seems they may return the expected values because they rely on HTTP header keys/values appended while getting header data.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The response code should be set according to HTTP status code returned by the server before calling the HeadersReceivedEventHandler.

Current Behavior

calling response->GetResponseCode () in HeadersReceivedEventHandler always returns -1

Reproduction Steps

bool AwsDoc::S3::getObject(const Aws::String &objectKey,
                           const Aws::String &fromBucket,
                           const Aws::S3::S3ClientConfiguration &clientConfig) {
    Aws::S3::S3Client client(clientConfig);

    Aws::S3::Model::GetObjectRequest request;
    request.SetBucket(fromBucket);
    request.SetKey("one_object_that_does_not_exist_in_the_bucket"); // <== we should get 404 when calling GetResponseCode

    request.SetHeadersReceivedEventHandler (
      [] (
        const Aws::Http::HttpRequest * request,
        Aws::Http::HttpResponse * response
      ) {
        ::std::cout <<  "response headers received: "
            << response->GetResponseCode ( )
           << ::std::endl; // <== current implementation is always "response headers received: -1"
      }
    );

    Aws::S3::Model::GetObjectOutcome outcome =
            client.GetObject(request);

    if (!outcome.IsSuccess()) {
        const Aws::S3::S3Error &err = outcome.GetError();
        std::cerr << "Error: getObject: " <<
                  err.GetExceptionName() << ": " << err.GetMessage() << std::endl;
    } else {
        std::cout << "Successfully retrieved '" << objectKey << "' from '"
                  << fromBucket << "'." << std::endl;
    }

    return outcome.IsSuccess();
}

Possible Solution

call SetResponseCode before calling HeadersReceivedEventHandler

Additional Information/Context

Client: CURL
OS: linux / debian
aws-sdk-cpp: main branch

I assume this bug is applicable to all S3 actions (not only GetObject) since the bug is in the low level HTTP client implementation (CURL based).

I have a fix to propose if it can help.

AWS CPP SDK version used

1.11.476

Compiler and Version used

c++ (Debian 12.2.0-14) 12.2.0

Operating System and version

debian 12.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions