Skip to content

Commit 7d2d4b3

Browse files
authored
default request without body (#516)
1 parent 5eac79f commit 7d2d4b3

4 files changed

Lines changed: 87 additions & 14 deletions

File tree

source/s3_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ static struct aws_s3_meta_request *s_s3_client_meta_request_factory_default(
12361236
client->allocator,
12371237
client,
12381238
AWS_S3_REQUEST_TYPE_GET_OBJECT,
1239-
content_length,
1239+
0, /* Content length for request */
12401240
false /*should_compute_content_md5*/,
12411241
options);
12421242
}

source/s3_default_meta_request.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ static void s_s3_default_prepare_request_finish(
329329

330330
struct aws_s3_request *request = request_prep->request;
331331
struct aws_s3_meta_request *meta_request = request->meta_request;
332+
struct aws_s3_meta_request_default *meta_request_default = meta_request->impl;
332333

333334
if (error_code != AWS_ERROR_SUCCESS) {
334335
goto finish;
@@ -347,13 +348,17 @@ static void s_s3_default_prepare_request_finish(
347348
struct aws_http_headers *headers = aws_http_message_get_headers(message);
348349
aws_http_headers_set(headers, g_request_validation_mode, g_enabled);
349350
}
350-
aws_s3_message_util_assign_body(
351-
meta_request->allocator,
352-
&request->request_body,
353-
message,
354-
&meta_request->checksum_config,
355-
NULL /* out_checksum */);
356-
351+
if (meta_request_default->request_type == AWS_S3_REQUEST_TYPE_PUT_OBJECT ||
352+
meta_request_default->request_type == AWS_S3_REQUEST_TYPE_UPLOAD_PART || request->request_body.len > 0) {
353+
/* Only PUT Object and Upload part support trailing checksum, that needs the special encoding even if the body
354+
* has 0 length. */
355+
aws_s3_message_util_assign_body(
356+
meta_request->allocator,
357+
&request->request_body,
358+
message,
359+
&meta_request->checksum_config,
360+
NULL /* out_checksum */);
361+
}
357362
aws_s3_request_setup_send_data(request, message);
358363

359364
aws_http_message_release(message);

tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ add_net_test_case(test_s3_round_trip)
176176
add_net_test_case(test_s3_round_trip_default_get)
177177
add_net_test_case(test_s3_round_trip_multipart_get_fc)
178178
add_net_test_case(test_s3_round_trip_default_get_fc)
179+
add_net_test_case(test_s3_round_trip_empty_fc)
179180
add_net_test_case(test_s3_round_trip_mpu_multipart_get_fc)
180181
add_net_test_case(test_s3_round_trip_mpu_multipart_get_with_list_algorithm_fc)
181182
add_net_test_case(test_s3_round_trip_mpu_default_get_fc)
@@ -401,6 +402,8 @@ add_net_test_case(client_update_upload_part_timeout)
401402
add_net_test_case(client_meta_request_override_part_size)
402403
add_net_test_case(client_meta_request_override_multipart_upload_threshold)
403404

405+
add_net_test_case(test_s3_default_get_without_content_length)
406+
404407
set(TEST_BINARY_NAME ${PROJECT_NAME}-tests)
405408
generate_test_driver(${TEST_BINARY_NAME})
406409

tests/s3_data_plane_tests.c

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3922,6 +3922,7 @@ static int s_test_s3_round_trip_default_get_fc_helper(
39223922
struct aws_allocator *allocator,
39233923
void *ctx,
39243924
bool via_header,
3925+
uint32_t object_size_mb,
39253926
enum aws_s3_tester_full_object_checksum full_object_checksum) {
39263927
(void)ctx;
39273928

@@ -3943,8 +3944,9 @@ static int s_test_s3_round_trip_default_get_fc_helper(
39433944
snprintf(
39443945
object_path_sprintf_buffer,
39453946
sizeof(object_path_sprintf_buffer),
3946-
"/prefix/round_trip/test_default_fc_%d.txt",
3947-
algorithm);
3947+
"/prefix/round_trip/test_default_fc_%d_%d.txt",
3948+
algorithm,
3949+
object_size_mb);
39483950

39493951
ASSERT_SUCCESS(aws_s3_tester_upload_file_path_init(
39503952
allocator, &path_buf, aws_byte_cursor_from_c_str(object_path_sprintf_buffer)));
@@ -3960,7 +3962,7 @@ static int s_test_s3_round_trip_default_get_fc_helper(
39603962
.checksum_via_header = via_header,
39613963
.put_options =
39623964
{
3963-
.object_size_mb = 1,
3965+
.object_size_mb = object_size_mb,
39643966
.object_path_override = object_path,
39653967
},
39663968
};
@@ -4000,18 +4002,22 @@ static int s_test_s3_round_trip_default_get_fc_helper(
40004002

40014003
AWS_TEST_CASE(test_s3_round_trip_default_get_fc, s_test_s3_round_trip_default_get_fc)
40024004
static int s_test_s3_round_trip_default_get_fc(struct aws_allocator *allocator, void *ctx) {
4003-
return s_test_s3_round_trip_default_get_fc_helper(allocator, ctx, false, AWS_TEST_FOC_NONE);
4005+
return s_test_s3_round_trip_default_get_fc_helper(allocator, ctx, false, 1 /*object_size_mb*/, AWS_TEST_FOC_NONE);
4006+
}
4007+
AWS_TEST_CASE(test_s3_round_trip_empty_fc, s_test_s3_round_trip_empty_fc)
4008+
static int s_test_s3_round_trip_empty_fc(struct aws_allocator *allocator, void *ctx) {
4009+
return s_test_s3_round_trip_default_get_fc_helper(allocator, ctx, false, 0, AWS_TEST_FOC_NONE);
40044010
}
40054011

40064012
AWS_TEST_CASE(test_s3_round_trip_default_get_fc_header, s_test_s3_round_trip_default_get_fc_header)
40074013
static int s_test_s3_round_trip_default_get_fc_header(struct aws_allocator *allocator, void *ctx) {
4008-
return s_test_s3_round_trip_default_get_fc_helper(allocator, ctx, true, AWS_TEST_FOC_NONE);
4014+
return s_test_s3_round_trip_default_get_fc_helper(allocator, ctx, true, 1, AWS_TEST_FOC_NONE);
40094015
}
40104016
AWS_TEST_CASE(
40114017
test_s3_round_trip_default_get_full_object_checksum_fc,
40124018
s_test_s3_round_trip_default_get_full_object_checksum_fc)
40134019
static int s_test_s3_round_trip_default_get_full_object_checksum_fc(struct aws_allocator *allocator, void *ctx) {
4014-
return s_test_s3_round_trip_default_get_fc_helper(allocator, ctx, false, AWS_TEST_FOC_HEADER);
4020+
return s_test_s3_round_trip_default_get_fc_helper(allocator, ctx, false, 1, AWS_TEST_FOC_HEADER);
40154021
}
40164022

40174023
static int s_test_s3_round_trip_multipart_get_fc_helper(struct aws_allocator *allocator, void *ctx, bool via_header) {
@@ -8049,3 +8055,62 @@ static int s_test_s3_upload_review_checksum_location_none_async_noop_part(struct
80498055
aws_s3_tester_clean_up(&tester);
80508056
return 0;
80518057
}
8058+
8059+
static struct aws_http_stream *s_http_connection_make_request_patch(
8060+
struct aws_http_connection *client_connection,
8061+
const struct aws_http_make_request_options *options) {
8062+
8063+
struct aws_http_message *message = options->request;
8064+
struct aws_http_headers *headers = aws_http_message_get_headers(message);
8065+
struct aws_byte_cursor out_value;
8066+
int e = aws_http_headers_get(headers, aws_byte_cursor_from_c_str("Content-Length"), &out_value);
8067+
AWS_FATAL_ASSERT(e == AWS_OP_ERR); // Assert that the header is not present
8068+
AWS_FATAL_ASSERT(aws_last_error() == AWS_ERROR_HTTP_HEADER_NOT_FOUND);
8069+
8070+
return aws_http_connection_make_request(client_connection, options);
8071+
}
8072+
8073+
AWS_TEST_CASE(test_s3_default_get_without_content_length, s_test_s3_default_get_without_content_length)
8074+
static int s_test_s3_default_get_without_content_length(struct aws_allocator *allocator, void *ctx) {
8075+
(void)ctx;
8076+
8077+
struct aws_s3_tester tester;
8078+
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
8079+
8080+
struct aws_s3_client *client = NULL;
8081+
struct aws_s3_tester_client_options client_options;
8082+
AWS_ZERO_STRUCT(client_options);
8083+
8084+
ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
8085+
struct aws_s3_client_vtable *patched_client_vtable = aws_s3_tester_patch_client_vtable(&tester, client, NULL);
8086+
patched_client_vtable->http_connection_make_request = s_http_connection_make_request_patch;
8087+
8088+
struct aws_s3_meta_request_test_results meta_request_test_results;
8089+
aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator);
8090+
8091+
struct aws_string *host_name =
8092+
aws_s3_tester_build_endpoint_string(allocator, &g_test_public_bucket_name, &g_test_s3_region);
8093+
8094+
/* Put together a simple S3 Get Object request. */
8095+
struct aws_http_message *message = aws_s3_test_get_object_request_new(
8096+
allocator, aws_byte_cursor_from_string(host_name), g_pre_existing_object_1MB);
8097+
8098+
struct aws_s3_meta_request_options options;
8099+
AWS_ZERO_STRUCT(options);
8100+
/* Send default type */
8101+
options.type = AWS_S3_META_REQUEST_TYPE_DEFAULT;
8102+
options.message = message;
8103+
options.operation_name = aws_byte_cursor_from_c_str("GetObject");
8104+
8105+
ASSERT_SUCCESS(aws_s3_tester_send_meta_request(
8106+
&tester, client, &options, &meta_request_test_results, AWS_S3_TESTER_SEND_META_REQUEST_EXPECT_SUCCESS));
8107+
ASSERT_SUCCESS(aws_s3_tester_validate_get_object_results(&meta_request_test_results, 0));
8108+
8109+
aws_s3_meta_request_test_results_clean_up(&meta_request_test_results);
8110+
aws_string_destroy(host_name);
8111+
aws_http_message_release(message);
8112+
aws_s3_client_release(client);
8113+
aws_s3_tester_clean_up(&tester);
8114+
8115+
return AWS_OP_SUCCESS;
8116+
}

0 commit comments

Comments
 (0)