diff --git a/include/aws/s3/private/s3_meta_request_impl.h b/include/aws/s3/private/s3_meta_request_impl.h index 00520d98..3e9374b2 100644 --- a/include/aws/s3/private/s3_meta_request_impl.h +++ b/include/aws/s3/private/s3_meta_request_impl.h @@ -136,6 +136,7 @@ struct aws_s3_meta_request { void *impl; struct aws_s3_meta_request_vtable *vtable; + struct aws_input_stream *stream; /* Initial HTTP Message that this meta request is based on. */ struct aws_http_message *initial_request_message; diff --git a/samples/s3/main.c b/samples/s3/main.c index 2986bbb3..41928474 100644 --- a/samples/s3/main.c +++ b/samples/s3/main.c @@ -126,6 +126,7 @@ static void s_parse_app_ctx(int argc, char *const argv[], struct app_ctx *app_ct client_config.client_bootstrap = app_ctx->client_bootstrap; client_config.region = aws_byte_cursor_from_c_str(app_ctx->region); client_config.signing_config = &app_ctx->signing_config; + client_config.tls_mode = AWS_MR_TLS_DISABLED; app_ctx->client = aws_s3_client_new(app_ctx->allocator, &client_config); } diff --git a/samples/s3/s3-cp.c b/samples/s3/s3-cp.c index ddb506fb..9520eb02 100644 --- a/samples/s3/s3-cp.c +++ b/samples/s3/s3-cp.c @@ -542,6 +542,10 @@ static int s_kickoff_put_object( .name = aws_byte_cursor_from_c_str("content-length"), .value = aws_byte_cursor_from_c_str(content_length), }; + // struct aws_http_header transfer_encoding_header = { + // .name = aws_byte_cursor_from_c_str("transfer-encoding"), + // .value = aws_byte_cursor_from_c_str("chunked"), + // }; request_options.message = aws_http_message_new_request(cp_app_ctx->app_ctx->allocator); aws_http_message_add_header(request_options.message, host_header); @@ -708,10 +712,16 @@ static int s_kickoff_get_object( .value = aws_byte_cursor_from_c_str("AWS common runtime command-line client"), }; + struct aws_http_header if_match_header = { + .name = aws_byte_cursor_from_c_str("if-match"), + .value = aws_byte_cursor_from_c_str("123"), + }; + request_options.message = aws_http_message_new_request(cp_app_ctx->app_ctx->allocator); aws_http_message_add_header(request_options.message, host_header); aws_http_message_add_header(request_options.message, accept_header); aws_http_message_add_header(request_options.message, user_agent_header); + aws_http_message_add_header(request_options.message, if_match_header); aws_http_message_set_request_method(request_options.message, aws_http_method_get); struct aws_byte_buf path_buf; diff --git a/source/s3_default_meta_request.c b/source/s3_default_meta_request.c index 4e576d43..9967d7ec 100644 --- a/source/s3_default_meta_request.c +++ b/source/s3_default_meta_request.c @@ -347,7 +347,15 @@ static void s_s3_default_prepare_request_finish( struct aws_http_headers *headers = aws_http_message_get_headers(message); aws_http_headers_set(headers, g_request_validation_mode, g_enabled); } - aws_s3_message_util_assign_body( + + struct aws_http_headers *headers = aws_http_message_get_headers(message); + struct aws_http_header transfer_encoding_header = { + .name = aws_byte_cursor_from_c_str("transfer-encoding"), + .value = aws_byte_cursor_from_c_str("chunked"), + }; + aws_http_headers_erase(headers, aws_byte_cursor_from_c_str("content-length")); + aws_http_headers_add_header(headers, &transfer_encoding_header); + meta_request->stream = aws_s3_message_util_assign_body( meta_request->allocator, &request->request_body, message, diff --git a/source/s3_meta_request.c b/source/s3_meta_request.c index 22ba46f5..713d2204 100644 --- a/source/s3_meta_request.c +++ b/source/s3_meta_request.c @@ -1100,6 +1100,13 @@ static void s_s3_meta_request_request_on_signed( s_s3_prepare_request_payload_callback_and_destroy(payload, error_code); } +static void s_destroy_stream_on_complete(struct aws_http_stream *stream, int error_code, void *user_data) { + (void)stream; + (void)error_code; + struct aws_input_stream *data_stream = user_data; + aws_input_stream_release(data_stream); +} + void aws_s3_meta_request_send_request(struct aws_s3_meta_request *meta_request, struct aws_s3_connection *connection) { AWS_PRECONDITION(meta_request); AWS_PRECONDITION(connection); @@ -1179,6 +1186,21 @@ void aws_s3_meta_request_send_request(struct aws_s3_meta_request *meta_request, goto error_finish; } } + int64_t length = 0; + aws_input_stream_get_length(meta_request->stream, &length); + struct aws_http1_chunk_options chunk_options; + AWS_ZERO_STRUCT(chunk_options); + chunk_options.chunk_data = meta_request->stream; + chunk_options.chunk_data_size = length; + chunk_options.on_complete = s_destroy_stream_on_complete; + chunk_options.user_data = meta_request->stream; + aws_http1_stream_write_chunk(stream, &chunk_options); + static const struct aws_byte_cursor empty_str = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(""); + struct aws_input_stream *termination_marker = aws_input_stream_new_from_cursor(meta_request->allocator, &empty_str); + chunk_options.chunk_data = termination_marker; + chunk_options.chunk_data_size = empty_str.len; + chunk_options.user_data = termination_marker; + aws_http1_stream_write_chunk(stream, &chunk_options); return; error_finish: diff --git a/source/s3_request_messages.c b/source/s3_request_messages.c index 3df03816..7f166380 100644 --- a/source/s3_request_messages.c +++ b/source/s3_request_messages.c @@ -979,13 +979,13 @@ struct aws_input_stream *aws_s3_message_util_assign_body( snprintf(content_length_buffer, sizeof(content_length_buffer), "%" PRIu64, (uint64_t)stream_length); struct aws_byte_cursor content_length_cursor = aws_byte_cursor_from_array(content_length_buffer, strlen(content_length_buffer)); - if (aws_http_headers_set(headers, g_content_length_header_name, content_length_cursor)) { - goto error_clean_up; - } + // if (aws_http_headers_set(headers, g_content_length_header_name, content_length_cursor)) { + // goto error_clean_up; + // } - aws_http_message_set_body_stream(out_message, input_stream); + // aws_http_message_set_body_stream(out_message, input_stream); /* Let the message take the full ownership */ - aws_input_stream_release(input_stream); + // aws_input_stream_release(input_stream); aws_byte_buf_clean_up(&content_encoding_header_buf); return input_stream;