Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions source/proxy_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,23 @@ static enum aws_http_proxy_connection_type s_determine_proxy_connection_type(
}
}

static struct aws_string *s_get_proxy_environment_value(
struct aws_allocator *allocator,
const struct aws_string *env_name) {
struct aws_string *out_string = NULL;
if (aws_get_environment_value(allocator, env_name, &out_string) == AWS_OP_SUCCESS && out_string != NULL &&
out_string->len > 0) {
AWS_LOGF_DEBUG(
AWS_LS_HTTP_CONNECTION,
"%s environment found, %s",
aws_string_c_str(env_name),
aws_string_c_str(out_string));
return out_string;
}
aws_string_destroy(out_string);
return NULL;
}

static int s_proxy_uri_init_from_env_variable(
struct aws_allocator *allocator,
const struct aws_http_client_connection_options *options,
Expand All @@ -1148,25 +1165,19 @@ static int s_proxy_uri_init_from_env_variable(
struct aws_string *proxy_uri_string = NULL;
*found = false;
if (options->tls_options) {
if (aws_get_environment_value(allocator, s_https_proxy_env_var_low, &proxy_uri_string) == AWS_OP_SUCCESS &&
proxy_uri_string != NULL) {
AWS_LOGF_DEBUG(AWS_LS_HTTP_CONNECTION, "https_proxy environment found");
} else if (
aws_get_environment_value(allocator, s_https_proxy_env_var, &proxy_uri_string) == AWS_OP_SUCCESS &&
proxy_uri_string != NULL) {
AWS_LOGF_DEBUG(AWS_LS_HTTP_CONNECTION, "HTTPS_PROXY environment found");
} else {
proxy_uri_string = s_get_proxy_environment_value(allocator, s_https_proxy_env_var_low);
if (proxy_uri_string == NULL) {
proxy_uri_string = s_get_proxy_environment_value(allocator, s_https_proxy_env_var);
}
if (proxy_uri_string == NULL) {
return AWS_OP_SUCCESS;
}
} else {
if (aws_get_environment_value(allocator, s_http_proxy_env_var_low, &proxy_uri_string) == AWS_OP_SUCCESS &&
proxy_uri_string != NULL) {
AWS_LOGF_DEBUG(AWS_LS_HTTP_CONNECTION, "http_proxy environment found");
} else if (
aws_get_environment_value(allocator, s_http_proxy_env_var, &proxy_uri_string) == AWS_OP_SUCCESS &&
proxy_uri_string != NULL) {
AWS_LOGF_DEBUG(AWS_LS_HTTP_CONNECTION, "HTTP_PROXY environment found");
} else {
proxy_uri_string = s_get_proxy_environment_value(allocator, s_http_proxy_env_var_low);
if (proxy_uri_string == NULL) {
proxy_uri_string = s_get_proxy_environment_value(allocator, s_http_proxy_env_var);
}
if (proxy_uri_string == NULL) {
return AWS_OP_SUCCESS;
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ add_net_test_case(test_connection_manager_idle_culling_refcount)

# tests where we establish real connections
add_net_test_case(test_connection_manager_single_connection)
add_net_test_case(test_connection_manager_proxy_envrionment_empty_string)
add_net_test_case(test_connection_manager_single_http2_connection)
add_net_test_case(test_connection_manager_single_http2_connection_failed)
add_net_test_case(test_connection_manager_single_http2_connection_with_settings)
Expand Down
43 changes: 43 additions & 0 deletions tests/test_connection_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#endif

AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_env_var, "HTTP_PROXY");
AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_env_var_low, "http_proxy");
AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_env_var, "HTTPS_PROXY");
AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_env_var_low, "https_proxy");

enum new_connection_result_type {
AWS_NCRT_SUCCESS,
Expand Down Expand Up @@ -465,13 +467,47 @@ static int s_test_connection_manager_single_connection(struct aws_allocator *all
ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));

ASSERT_SUCCESS(s_release_connections(1, false));
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);

ASSERT_SUCCESS(s_cm_tester_clean_up());

return AWS_OP_SUCCESS;
}
AWS_TEST_CASE(test_connection_manager_single_connection, s_test_connection_manager_single_connection);

static int s_test_connection_manager_proxy_envrionment_empty_string(struct aws_allocator *allocator, void *ctx) {
(void)ctx;
/* Set proxy related envrionment variables to empty string and make sure we just skip proxy */
struct aws_string *empty = aws_string_new_from_c_str(allocator, "");
ASSERT_SUCCESS(aws_set_environment_value(s_http_proxy_env_var, empty));
ASSERT_SUCCESS(aws_set_environment_value(s_http_proxy_env_var_low, empty));
ASSERT_SUCCESS(aws_set_environment_value(s_https_proxy_env_var, empty));
ASSERT_SUCCESS(aws_set_environment_value(s_https_proxy_env_var_low, empty));

struct cm_tester_options options = {
.allocator = allocator,
.max_connections = 5,
.use_proxy_env = true,
};

ASSERT_SUCCESS(s_cm_tester_init(&options));

s_acquire_connections(1);

ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));

ASSERT_SUCCESS(s_release_connections(1, false));
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);

ASSERT_SUCCESS(s_cm_tester_clean_up());
aws_string_destroy(empty);

return AWS_OP_SUCCESS;
}
AWS_TEST_CASE(
test_connection_manager_proxy_envrionment_empty_string,
s_test_connection_manager_proxy_envrionment_empty_string);

static int s_test_connection_manager_single_http2_connection(struct aws_allocator *allocator, void *ctx) {
(void)ctx;

Expand Down Expand Up @@ -513,6 +549,7 @@ static int s_test_connection_manager_single_http2_connection_failed(struct aws_a
ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));

ASSERT_SUCCESS(s_release_connections(1, false));
ASSERT_UINT_EQUALS(1, s_tester.connection_errors);

ASSERT_SUCCESS(s_cm_tester_clean_up());

Expand Down Expand Up @@ -543,6 +580,7 @@ static int s_test_connection_manager_single_http2_connection_with_settings(struc
ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));

ASSERT_SUCCESS(s_release_connections(1, false));
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);

ASSERT_SUCCESS(s_cm_tester_clean_up());

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

ASSERT_SUCCESS(s_release_connections(20, false));
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);

ASSERT_SUCCESS(s_cm_tester_clean_up());

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

ASSERT_SUCCESS(s_release_connections(20, false));
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);

ASSERT_SUCCESS(s_cm_tester_clean_up());

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

ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
}
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);

ASSERT_SUCCESS(s_cm_tester_clean_up());

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

ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
}
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);

ASSERT_SUCCESS(s_cm_tester_clean_up());

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

ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
}
ASSERT_UINT_EQUALS(0, s_tester.connection_errors);

ASSERT_SUCCESS(s_cm_tester_clean_up());

Expand Down