Skip to content

Commit f800427

Browse files
authored
skip empty string for proxy env var (#446)
1 parent 27efc27 commit f800427

File tree

3 files changed

+71
-16
lines changed

3 files changed

+71
-16
lines changed

source/proxy_connection.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,23 @@ static enum aws_http_proxy_connection_type s_determine_proxy_connection_type(
11401140
}
11411141
}
11421142

1143+
static struct aws_string *s_get_proxy_environment_value(
1144+
struct aws_allocator *allocator,
1145+
const struct aws_string *env_name) {
1146+
struct aws_string *out_string = NULL;
1147+
if (aws_get_environment_value(allocator, env_name, &out_string) == AWS_OP_SUCCESS && out_string != NULL &&
1148+
out_string->len > 0) {
1149+
AWS_LOGF_DEBUG(
1150+
AWS_LS_HTTP_CONNECTION,
1151+
"%s environment found, %s",
1152+
aws_string_c_str(env_name),
1153+
aws_string_c_str(out_string));
1154+
return out_string;
1155+
}
1156+
aws_string_destroy(out_string);
1157+
return NULL;
1158+
}
1159+
11431160
static int s_proxy_uri_init_from_env_variable(
11441161
struct aws_allocator *allocator,
11451162
const struct aws_http_client_connection_options *options,
@@ -1148,25 +1165,19 @@ static int s_proxy_uri_init_from_env_variable(
11481165
struct aws_string *proxy_uri_string = NULL;
11491166
*found = false;
11501167
if (options->tls_options) {
1151-
if (aws_get_environment_value(allocator, s_https_proxy_env_var_low, &proxy_uri_string) == AWS_OP_SUCCESS &&
1152-
proxy_uri_string != NULL) {
1153-
AWS_LOGF_DEBUG(AWS_LS_HTTP_CONNECTION, "https_proxy environment found");
1154-
} else if (
1155-
aws_get_environment_value(allocator, s_https_proxy_env_var, &proxy_uri_string) == AWS_OP_SUCCESS &&
1156-
proxy_uri_string != NULL) {
1157-
AWS_LOGF_DEBUG(AWS_LS_HTTP_CONNECTION, "HTTPS_PROXY environment found");
1158-
} else {
1168+
proxy_uri_string = s_get_proxy_environment_value(allocator, s_https_proxy_env_var_low);
1169+
if (proxy_uri_string == NULL) {
1170+
proxy_uri_string = s_get_proxy_environment_value(allocator, s_https_proxy_env_var);
1171+
}
1172+
if (proxy_uri_string == NULL) {
11591173
return AWS_OP_SUCCESS;
11601174
}
11611175
} else {
1162-
if (aws_get_environment_value(allocator, s_http_proxy_env_var_low, &proxy_uri_string) == AWS_OP_SUCCESS &&
1163-
proxy_uri_string != NULL) {
1164-
AWS_LOGF_DEBUG(AWS_LS_HTTP_CONNECTION, "http_proxy environment found");
1165-
} else if (
1166-
aws_get_environment_value(allocator, s_http_proxy_env_var, &proxy_uri_string) == AWS_OP_SUCCESS &&
1167-
proxy_uri_string != NULL) {
1168-
AWS_LOGF_DEBUG(AWS_LS_HTTP_CONNECTION, "HTTP_PROXY environment found");
1169-
} else {
1176+
proxy_uri_string = s_get_proxy_environment_value(allocator, s_http_proxy_env_var_low);
1177+
if (proxy_uri_string == NULL) {
1178+
proxy_uri_string = s_get_proxy_environment_value(allocator, s_http_proxy_env_var);
1179+
}
1180+
if (proxy_uri_string == NULL) {
11701181
return AWS_OP_SUCCESS;
11711182
}
11721183
}

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ add_net_test_case(test_connection_manager_idle_culling_refcount)
522522

523523
# tests where we establish real connections
524524
add_net_test_case(test_connection_manager_single_connection)
525+
add_net_test_case(test_connection_manager_proxy_envrionment_empty_string)
525526
add_net_test_case(test_connection_manager_single_http2_connection)
526527
add_net_test_case(test_connection_manager_single_http2_connection_failed)
527528
add_net_test_case(test_connection_manager_single_http2_connection_with_settings)

tests/test_connection_manager.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#endif
3030

3131
AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_env_var, "HTTP_PROXY");
32+
AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_env_var_low, "http_proxy");
3233
AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_env_var, "HTTPS_PROXY");
34+
AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_env_var_low, "https_proxy");
3335

3436
enum new_connection_result_type {
3537
AWS_NCRT_SUCCESS,
@@ -465,13 +467,47 @@ static int s_test_connection_manager_single_connection(struct aws_allocator *all
465467
ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
466468

467469
ASSERT_SUCCESS(s_release_connections(1, false));
470+
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
468471

469472
ASSERT_SUCCESS(s_cm_tester_clean_up());
470473

471474
return AWS_OP_SUCCESS;
472475
}
473476
AWS_TEST_CASE(test_connection_manager_single_connection, s_test_connection_manager_single_connection);
474477

478+
static int s_test_connection_manager_proxy_envrionment_empty_string(struct aws_allocator *allocator, void *ctx) {
479+
(void)ctx;
480+
/* Set proxy related envrionment variables to empty string and make sure we just skip proxy */
481+
struct aws_string *empty = aws_string_new_from_c_str(allocator, "");
482+
ASSERT_SUCCESS(aws_set_environment_value(s_http_proxy_env_var, empty));
483+
ASSERT_SUCCESS(aws_set_environment_value(s_http_proxy_env_var_low, empty));
484+
ASSERT_SUCCESS(aws_set_environment_value(s_https_proxy_env_var, empty));
485+
ASSERT_SUCCESS(aws_set_environment_value(s_https_proxy_env_var_low, empty));
486+
487+
struct cm_tester_options options = {
488+
.allocator = allocator,
489+
.max_connections = 5,
490+
.use_proxy_env = true,
491+
};
492+
493+
ASSERT_SUCCESS(s_cm_tester_init(&options));
494+
495+
s_acquire_connections(1);
496+
497+
ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
498+
499+
ASSERT_SUCCESS(s_release_connections(1, false));
500+
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
501+
502+
ASSERT_SUCCESS(s_cm_tester_clean_up());
503+
aws_string_destroy(empty);
504+
505+
return AWS_OP_SUCCESS;
506+
}
507+
AWS_TEST_CASE(
508+
test_connection_manager_proxy_envrionment_empty_string,
509+
s_test_connection_manager_proxy_envrionment_empty_string);
510+
475511
static int s_test_connection_manager_single_http2_connection(struct aws_allocator *allocator, void *ctx) {
476512
(void)ctx;
477513

@@ -513,6 +549,7 @@ static int s_test_connection_manager_single_http2_connection_failed(struct aws_a
513549
ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
514550

515551
ASSERT_SUCCESS(s_release_connections(1, false));
552+
ASSERT_UINT_EQUALS(1, s_tester.connection_errors);
516553

517554
ASSERT_SUCCESS(s_cm_tester_clean_up());
518555

@@ -543,6 +580,7 @@ static int s_test_connection_manager_single_http2_connection_with_settings(struc
543580
ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
544581

545582
ASSERT_SUCCESS(s_release_connections(1, false));
583+
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
546584

547585
ASSERT_SUCCESS(s_cm_tester_clean_up());
548586

@@ -567,6 +605,7 @@ static int s_test_connection_manager_many_connections(struct aws_allocator *allo
567605
ASSERT_SUCCESS(s_wait_on_connection_reply_count(20));
568606

569607
ASSERT_SUCCESS(s_release_connections(20, false));
608+
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
570609

571610
ASSERT_SUCCESS(s_cm_tester_clean_up());
572611

@@ -591,6 +630,7 @@ static int s_test_connection_manager_many_http2_connections(struct aws_allocator
591630
ASSERT_SUCCESS(s_wait_on_connection_reply_count(20));
592631

593632
ASSERT_SUCCESS(s_release_connections(20, false));
633+
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
594634

595635
ASSERT_SUCCESS(s_cm_tester_clean_up());
596636

@@ -617,6 +657,7 @@ static int s_test_connection_manager_acquire_release(struct aws_allocator *alloc
617657

618658
ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
619659
}
660+
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
620661

621662
ASSERT_SUCCESS(s_cm_tester_clean_up());
622663

@@ -643,6 +684,7 @@ static int s_test_connection_manager_close_and_release(struct aws_allocator *all
643684

644685
ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
645686
}
687+
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
646688

647689
ASSERT_SUCCESS(s_cm_tester_clean_up());
648690

@@ -675,6 +717,7 @@ static int s_test_connection_manager_acquire_release_mix(struct aws_allocator *a
675717

676718
ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
677719
}
720+
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
678721

679722
ASSERT_SUCCESS(s_cm_tester_clean_up());
680723

0 commit comments

Comments
 (0)