Skip to content

Commit

Permalink
Invoke headers callback when CopyObject request is bypassed (#180)
Browse files Browse the repository at this point in the history
* Invoke headers callback when CopyObject request is bypassed

Prior to this fix the headers callback was invoked only
when the Copy meta request performed a multi-part copy, but not
when the object was small and resulted in a bypassed CopyObject request.

This commit fixes the issue, invoking the headers callback
in both cases.
  • Loading branch information
Cesar Mello authored Feb 21, 2022
1 parent d8b72f5 commit 8af5489
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
25 changes: 25 additions & 0 deletions source/s3_copy_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,32 @@ static void s_s3_copy_object_request_finished(
break;
}

/* The S3 object is not large enough for multi-part copy. A copy of the original CopyObject request
* was bypassed to S3 and is now finished. */
case AWS_S3_COPY_OBJECT_REQUEST_TAG_BYPASS: {

/* Invoke headers callback if it was requested for this meta request */
if (meta_request->headers_callback != NULL) {
struct aws_http_headers *final_response_headers = aws_http_headers_new(meta_request->allocator);

/* Copy all the response headers from this request. */
copy_http_headers(request->send_data.response_headers, final_response_headers);

/* Notify the user of the headers. */
if (meta_request->headers_callback(
meta_request,
final_response_headers,
request->send_data.response_status,
meta_request->user_data)) {

error_code = aws_last_error_or_unknown();
}
meta_request->headers_callback = NULL;

aws_http_headers_release(final_response_headers);
}

/* Signals completion of the meta request */
if (error_code == AWS_ERROR_SUCCESS) {
copy_object->synced_data.copy_request_bypass_completed = true;
} else {
Expand Down Expand Up @@ -744,6 +768,7 @@ static void s_s3_copy_object_request_finished(

error_code = aws_last_error_or_unknown();
}
meta_request->headers_callback = NULL;

aws_http_headers_release(final_response_headers);
}
Expand Down
25 changes: 24 additions & 1 deletion tests/s3_data_plane_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -3498,6 +3498,7 @@ struct copy_object_test_data {
struct aws_mutex mutex;
struct aws_condition_variable c_var;
bool execution_completed;
bool headers_callback_was_invoked;
int meta_request_error_code;
int response_status_code;
};
Expand Down Expand Up @@ -3528,6 +3529,25 @@ static void s_copy_object_meta_request_finish(
aws_condition_variable_notify_one(&test_data->c_var);
}

static int s_copy_object_meta_request_headers_callback(
struct aws_s3_meta_request *meta_request,
const struct aws_http_headers *headers,
int response_status,
void *user_data) {

(void)meta_request;
(void)headers;
(void)response_status;

struct copy_object_test_data *test_data = user_data;

aws_mutex_lock(&test_data->mutex);
test_data->headers_callback_was_invoked = true;
aws_mutex_unlock(&test_data->mutex);

return AWS_OP_SUCCESS;
}

static bool s_copy_test_completion_predicate(void *arg) {
struct copy_object_test_data *test_data = arg;
return test_data->execution_completed;
Expand Down Expand Up @@ -3578,7 +3598,7 @@ static int s_test_s3_copy_object_from_x_amz_copy_source(
.body_callback = NULL,
.signing_config = client_config.signing_config,
.finish_callback = s_copy_object_meta_request_finish,
.headers_callback = NULL,
.headers_callback = s_copy_object_meta_request_headers_callback,
.message = message,
.shutdown_callback = NULL,
.type = AWS_S3_META_REQUEST_TYPE_COPY_OBJECT,
Expand All @@ -3596,6 +3616,9 @@ static int s_test_s3_copy_object_from_x_amz_copy_source(
ASSERT_INT_EQUALS(expected_error_code, test_data.meta_request_error_code);
ASSERT_INT_EQUALS(expected_response_status, test_data.response_status_code);

/* assert headers callback was invoked */
ASSERT_TRUE(test_data.headers_callback_was_invoked);

aws_s3_meta_request_release(meta_request);
aws_mutex_clean_up(&test_data.mutex);
aws_http_message_destroy(message);
Expand Down

0 comments on commit 8af5489

Please sign in to comment.