Skip to content

Commit

Permalink
Zero unknown content length (#319)
Browse files Browse the repository at this point in the history
* support unknown content of zero length
  • Loading branch information
DmitriyMusatkin authored Jun 20, 2023
1 parent cabcef7 commit c4751fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 78 deletions.
4 changes: 3 additions & 1 deletion source/s3_auto_ranged_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,9 @@ static void s_s3_prepare_upload_part_on_read_done(void *user_data) {

/* Reading succeeded. */
bool is_body_stream_at_end = aws_future_bool_get_result(part_prep->asyncstep2_read_part);
request->is_noop = request->request_body.len == 0;
request->is_noop = request->part_number >
1 && /* allow first part to have 0 length to support empty unknown content length objects. */
request->request_body.len == 0;

/* If Content-Length is defined, check that we read the expected amount */
if (has_content_length && (request->request_body.len < request->request_body.capacity)) {
Expand Down
88 changes: 11 additions & 77 deletions tests/s3_data_plane_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -2112,8 +2112,7 @@ static int s_test_s3_put_object_empty_object(struct aws_allocator *allocator, vo
return 0;
}

AWS_TEST_CASE(test_s3_put_object_no_content_length, s_test_s3_put_object_no_content_length)
static int s_test_s3_put_object_no_content_length(struct aws_allocator *allocator, void *ctx) {
static int s3_no_content_length_test_helper(struct aws_allocator *allocator, void *ctx, uint32_t object_size_in_mb) {
(void)ctx;

struct aws_s3_tester tester;
Expand All @@ -2136,7 +2135,7 @@ static int s_test_s3_put_object_no_content_length(struct aws_allocator *allocato
.client = client,
.put_options =
{
.object_size_mb = 19,
.object_size_mb = object_size_in_mb,
.skip_content_length = true,
},
};
Expand All @@ -2153,88 +2152,23 @@ static int s_test_s3_put_object_no_content_length(struct aws_allocator *allocato
return 0;
}

AWS_TEST_CASE(test_s3_put_object_single_part_no_content_length, s_test_s3_put_object_single_part_no_content_length)
static int s_test_s3_put_object_single_part_no_content_length(struct aws_allocator *allocator, void *ctx) {
(void)ctx;

struct aws_s3_tester tester;
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));

struct aws_s3_client_config client_config = {
.part_size = MB_TO_BYTES(8),
};

ASSERT_SUCCESS(aws_s3_tester_bind_client(
&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION | AWS_S3_TESTER_BIND_CLIENT_SIGNING));

struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config);

ASSERT_TRUE(client != NULL);

struct aws_s3_tester_meta_request_options put_options = {
.allocator = allocator,
.meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
.client = client,
.put_options =
{
.object_size_mb = 5,
.skip_content_length = true,
},
};
struct aws_s3_meta_request_test_results meta_request_test_results;
aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator);

ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &meta_request_test_results));
aws_s3_meta_request_test_results_clean_up(&meta_request_test_results);
AWS_TEST_CASE(test_s3_put_object_no_content_length, s_test_s3_put_object_no_content_length)
static int s_test_s3_put_object_no_content_length(struct aws_allocator *allocator, void *ctx) {
ASSERT_SUCCESS(s3_no_content_length_test_helper(allocator, ctx, 19));

aws_s3_client_release(client);
return 0;
}

aws_s3_tester_clean_up(&tester);
AWS_TEST_CASE(test_s3_put_object_single_part_no_content_length, s_test_s3_put_object_single_part_no_content_length)
static int s_test_s3_put_object_single_part_no_content_length(struct aws_allocator *allocator, void *ctx) {
ASSERT_SUCCESS(s3_no_content_length_test_helper(allocator, ctx, 5));

return 0;
}

AWS_TEST_CASE(test_s3_put_object_zero_size_no_content_length, s_test_s3_put_object_zero_size_no_content_length)
static int s_test_s3_put_object_zero_size_no_content_length(struct aws_allocator *allocator, void *ctx) {
(void)ctx;

struct aws_s3_tester tester;
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));

struct aws_s3_client_config client_config = {
.part_size = MB_TO_BYTES(8),
};

ASSERT_SUCCESS(aws_s3_tester_bind_client(
&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION | AWS_S3_TESTER_BIND_CLIENT_SIGNING));

struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config);

ASSERT_TRUE(client != NULL);

struct aws_s3_tester_meta_request_options put_options = {
.allocator = allocator,
.meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
.client = client,
.validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
.put_options =
{
.object_size_mb = 0,
.skip_content_length = true,
},
};
struct aws_s3_meta_request_test_results meta_request_test_results;
aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator);

ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &meta_request_test_results));

ASSERT_INT_EQUALS(AWS_ERROR_UNSUPPORTED_OPERATION, meta_request_test_results.finished_error_code);

aws_s3_meta_request_test_results_clean_up(&meta_request_test_results);

aws_s3_client_release(client);

aws_s3_tester_clean_up(&tester);
ASSERT_SUCCESS(s3_no_content_length_test_helper(allocator, ctx, 0));

return 0;
}
Expand Down

0 comments on commit c4751fd

Please sign in to comment.