Skip to content

Commit f8ffac1

Browse files
committed
piping the headers
1 parent 8feda6e commit f8ffac1

7 files changed

+40
-7
lines changed

Diff for: include/aws/s3/private/s3_request_messages.h

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ extern const size_t g_s3_complete_multipart_upload_excluded_headers_count;
167167
AWS_S3_API
168168
extern const struct aws_byte_cursor g_s3_abort_multipart_upload_excluded_headers[];
169169

170+
AWS_S3_API
171+
extern const struct aws_byte_cursor g_s3_create_session_allowed_headers[];
172+
170173
AWS_S3_API
171174
extern const size_t g_s3_abort_multipart_upload_excluded_headers_count;
172175

Diff for: include/aws/s3/private/s3express_credentials_provider_impl.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ struct aws_s3express_session {
2626
/* The region and host of the session */
2727
struct aws_string *region;
2828
struct aws_string *host;
29+
30+
struct aws_http_headers *headers;
2931
bool inactive;
3032

3133
/* Only used for mock tests */
@@ -112,7 +114,8 @@ AWS_S3_API
112114
struct aws_string *aws_encode_s3express_hash_key_new(
113115
struct aws_allocator *allocator,
114116
const struct aws_credentials *original_credentials,
115-
struct aws_byte_cursor host_value);
117+
struct aws_byte_cursor host_value,
118+
struct aws_http_headers *headers);
116119

117120
AWS_EXTERN_C_END
118121
#endif /* AWS_S3EXPRESS_CREDENTIALS_PROVIDER_IMPL_H */

Diff for: include/aws/s3/s3express_credentials_provider.h

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ struct aws_credentials_properties_s3express {
2727
* If empty, the region of the S3 client will be used.
2828
*/
2929
struct aws_byte_cursor region;
30+
31+
32+
struct aws_http_headers *headers;
3033
};
3134

3235
struct aws_s3express_credentials_provider_vtable {

Diff for: source/s3_meta_request.c

+1
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ void aws_s3_meta_request_sign_request_default_impl(
968968
context->user_data = user_data;
969969
context->properties.host = aws_byte_cursor_from_string(meta_request->s3express_session_host);
970970
context->properties.region = signing_config.region;
971+
context->properties.headers = aws_http_message_get_headers(meta_request->initial_request_message);
971972

972973
if (signing_config.credentials) {
973974
context->original_credentials = signing_config.credentials;

Diff for: source/s3_request_messages.c

+11
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ const struct aws_byte_cursor g_s3_abort_multipart_upload_excluded_headers[] = {
229229
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("if-none-match"),
230230
};
231231

232+
const struct aws_byte_cursor g_s3_create_session_allowed_headers[] = {
233+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption"),
234+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-aws-kms-key-id"),
235+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-context"),
236+
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-bucket-key-enabled"),
237+
238+
};
239+
240+
const size_t g_s3_create_session_allowed_headers_count =
241+
AWS_ARRAY_SIZE(g_s3_create_session_allowed_headers);
242+
232243
static const struct aws_byte_cursor s_x_amz_meta_prefix = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-meta-");
233244

234245
static const struct aws_byte_cursor s_checksum_type_header =

Diff for: source/s3express_credentials_provider.c

+17-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct aws_s3express_session_creator {
4848
/* The region and host of the session we are creating */
4949
struct aws_string *region;
5050
struct aws_string *host;
51+
struct aws_http_headers *headers;
5152

5253
struct {
5354
/* Protected by the impl lock */
@@ -66,6 +67,7 @@ static struct aws_s3express_session *s_aws_s3express_session_new(
6667
const struct aws_string *hash_key,
6768
const struct aws_string *region,
6869
const struct aws_string *host,
70+
struct aws_http_headers *headers,
6971
struct aws_credentials *credentials) {
7072

7173
struct aws_s3express_session *session =
@@ -74,6 +76,8 @@ static struct aws_s3express_session *s_aws_s3express_session_new(
7476
session->impl = provider->impl;
7577
session->hash_key = aws_string_new_from_string(provider->allocator, hash_key);
7678
session->host = aws_string_new_from_string(provider->allocator, host);
79+
aws_http_headers_acquire(headers);
80+
session->headers = headers;
7781
if (region) {
7882
session->region = aws_string_new_from_string(provider->allocator, region);
7983
}
@@ -94,6 +98,7 @@ static void s_aws_s3express_session_destroy(struct aws_s3express_session *sessio
9498
aws_string_destroy(session->hash_key);
9599
aws_string_destroy(session->region);
96100
aws_string_destroy(session->host);
101+
aws_http_headers_release(session->headers);
97102
aws_credentials_release(session->s3express_credentials);
98103
aws_mem_release(session->allocator, session);
99104
}
@@ -368,6 +373,7 @@ static void s_on_request_finished(
368373
session_creator->hash_key,
369374
session_creator->region,
370375
session_creator->host,
376+
session_creator->headers,
371377
credentials);
372378
aws_cache_put(impl->synced_data.cache, session->hash_key, session);
373379
}
@@ -434,6 +440,7 @@ static struct aws_s3express_session_creator *s_aws_s3express_session_creator_des
434440
aws_string_destroy(session_creator->hash_key);
435441
aws_string_destroy(session_creator->region);
436442
aws_string_destroy(session_creator->host);
443+
aws_http_headers_release(session_creator->headers);
437444

438445
aws_byte_buf_clean_up(&session_creator->response_buf);
439446
aws_mem_release(session_creator->allocator, session_creator);
@@ -447,8 +454,9 @@ static struct aws_s3express_session_creator *s_aws_s3express_session_creator_des
447454
struct aws_string *aws_encode_s3express_hash_key_new(
448455
struct aws_allocator *allocator,
449456
const struct aws_credentials *original_credentials,
450-
struct aws_byte_cursor host_value) {
451-
457+
struct aws_byte_cursor host_value,
458+
struct aws_http_headers *headers) {
459+
(void)headers;
452460
struct aws_byte_buf combine_key_buf;
453461

454462
/* 1. Combine access_key and secret_access_key into one buffer */
@@ -500,6 +508,8 @@ static struct aws_s3express_session_creator *s_session_creator_new(
500508
session_creator->provider = provider;
501509
session_creator->host = aws_string_new_from_cursor(session_creator->allocator, &s3express_properties->host);
502510
session_creator->region = aws_string_new_from_cursor(session_creator->allocator, &s3express_properties->region);
511+
aws_http_headers_acquire(s3express_properties->headers);
512+
session_creator->headers = s3express_properties->headers;
503513

504514
struct aws_signing_config_aws s3express_signing_config = {
505515
.credentials = original_credentials,
@@ -556,8 +566,8 @@ static int s_s3express_get_creds(
556566

557567
uint64_t current_stamp = UINT64_MAX;
558568
aws_sys_clock_get_ticks(&current_stamp);
559-
struct aws_string *hash_key =
560-
aws_encode_s3express_hash_key_new(provider->allocator, original_credentials, s3express_properties->host);
569+
struct aws_string *hash_key = aws_encode_s3express_hash_key_new(
570+
provider->allocator, original_credentials, s3express_properties->host, s3express_properties->headers);
561571
uint64_t now_seconds = aws_timestamp_convert(current_stamp, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, NULL);
562572

563573
s_credentials_provider_s3express_impl_lock_synced_data(impl);
@@ -764,7 +774,8 @@ static void s_refresh_session_list(
764774
struct aws_string *current_creds_hash = aws_encode_s3express_hash_key_new(
765775
provider->allocator,
766776
current_original_credentials,
767-
aws_byte_cursor_from_string(session->host));
777+
aws_byte_cursor_from_string(session->host),
778+
session->headers);
768779
bool creds_match = aws_string_eq(current_creds_hash, hash_key);
769780
aws_string_destroy(current_creds_hash);
770781
if (!creds_match) {
@@ -784,6 +795,7 @@ static void s_refresh_session_list(
784795

785796
struct aws_credentials_properties_s3express s3express_properties = {
786797
.host = aws_byte_cursor_from_string(session->host),
798+
.headers = session->headers,
787799
};
788800
if (session->region) {
789801
s3express_properties.region = aws_byte_cursor_from_string(session->region);

Diff for: tests/s3_mock_server_s3express_provider_test.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static size_t s_get_index_from_s3express_cache(
446446
node = aws_linked_list_next(node);
447447
struct aws_s3express_session *session = table_node->value;
448448
struct aws_string *hash_key =
449-
aws_encode_s3express_hash_key_new(s_s3express_tester.allocator, original_credentials, host_value);
449+
aws_encode_s3express_hash_key_new(s_s3express_tester.allocator, original_credentials, host_value, session->headers);
450450
if (aws_string_eq(session->hash_key, hash_key)) {
451451
aws_string_destroy(hash_key);
452452
aws_mutex_unlock(&impl->synced_data.lock);

0 commit comments

Comments
 (0)