Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Content-Length: 0' header on multipart upload creation #428

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion source/s3_request_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ struct aws_http_message *aws_s3_ranged_get_object_message_new(
return message;
}

/* Creates a create-multipart-upload request from a given put objet request. */
/* Creates a create-multipart-upload request from a given put object request. */
struct aws_http_message *aws_s3_create_multipart_upload_message_new(
struct aws_allocator *allocator,
struct aws_http_message *base_message,
Expand Down Expand Up @@ -291,6 +291,11 @@ struct aws_http_message *aws_s3_create_multipart_upload_message_new(
}
}

struct aws_byte_cursor content_length_cursor = aws_byte_cursor_from_c_str("0");
if (aws_http_headers_set(headers, g_content_length_header_name, content_length_cursor)) {
goto error_clean_up;
}

aws_http_message_set_request_method(message, g_post_method);
aws_http_message_set_body_stream(message, NULL);

Expand Down
8 changes: 6 additions & 2 deletions tests/s3_request_messages_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,18 @@ static int s_test_s3_create_multipart_upload_message_new(struct aws_allocator *a

ASSERT_SUCCESS(s_test_http_message_request_method(create_multipart_upload_message, "POST"));
ASSERT_SUCCESS(s_test_http_message_request_path(create_multipart_upload_message, &expected_create_path));

const struct aws_byte_cursor header_exclude_exceptions[] = {
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Length"),
};
ASSERT_SUCCESS(s_test_http_headers_match(
allocator,
original_message,
create_multipart_upload_message,
g_s3_create_multipart_upload_excluded_headers,
g_s3_create_multipart_upload_excluded_headers_count,
NULL,
0));
header_exclude_exceptions,
AWS_ARRAY_SIZE(header_exclude_exceptions)));

aws_http_message_release(create_multipart_upload_message);
aws_http_message_release(original_message);
Expand Down