Skip to content

Commit

Permalink
Add 'Content-Length: 0' header on multipart upload creation (#428)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathon Belotti <[email protected]>
  • Loading branch information
waahm7 and thundergolfer authored May 7, 2024
1 parent db78654 commit cc06c41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit cc06c41

Please sign in to comment.