diff --git a/source/proxy_connection.c b/source/proxy_connection.c index 1ab165ca9..22ff452c3 100644 --- a/source/proxy_connection.c +++ b/source/proxy_connection.c @@ -1190,7 +1190,7 @@ static int s_connect_proxy_via_env_variable(const struct aws_http_client_connect proxy_options.connection_type = options->proxy_ev_settings->connection_type; if (proxy_options.connection_type == AWS_HPCT_HTTP_LEGACY) { if (options->tls_options) { - /* Use Tunneling when main connection use TLS. */ + /* Use tunneling when main connection use TLS. */ proxy_options.connection_type = AWS_HPCT_HTTP_TUNNEL; } else { /* Use forwarding proxy when main connection use clear text. */ @@ -1212,6 +1212,9 @@ static int s_connect_proxy_via_env_variable(const struct aws_http_client_connect }; proxy_options.proxy_strategy = aws_http_proxy_strategy_new_basic_auth(options->allocator, &config); } + } else { + success = true; + goto done; } struct aws_http_client_connection_options copied_options = *options; copied_options.proxy_options = &proxy_options; @@ -1223,6 +1226,10 @@ static int s_connect_proxy_via_env_variable(const struct aws_http_client_connect aws_tls_connection_options_clean_up(&default_tls_connection_options); aws_http_proxy_strategy_release(proxy_options.proxy_strategy); aws_uri_clean_up(&proxy_uri); + if (success && !found) { + /* Successfully, but no envrionment variable found. Connect without proxy */ + return aws_http_client_connect_internal(options, NULL); + } return success ? AWS_OP_SUCCESS : AWS_OP_ERR; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 67fa14de5..a0e646d7a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -442,6 +442,7 @@ add_test_case(h2_client_get_remote_settings) add_test_case(server_new_destroy) add_test_case(connection_setup_shutdown) add_test_case(connection_setup_shutdown_tls) +add_test_case(connection_setup_shutdown_proxy_setting_on_ev_not_found) add_test_case(connection_h2_prior_knowledge) add_test_case(connection_h2_prior_knowledge_not_work_with_tls) add_test_case(connection_customized_alpn) diff --git a/tests/test_connection.c b/tests/test_connection.c index 42b8cbf7d..a7d78d5cb 100644 --- a/tests/test_connection.c +++ b/tests/test_connection.c @@ -471,6 +471,43 @@ static int s_test_connection_setup_shutdown_tls(struct aws_allocator *allocator, } AWS_TEST_CASE(connection_setup_shutdown_tls, s_test_connection_setup_shutdown_tls); +static int s_test_connection_setup_shutdown_proxy_setting_on_ev_not_found(struct aws_allocator *allocator, void *ctx) { + (void)ctx; + struct tester_options options = { + .alloc = allocator, + .no_connection = true, + }; + struct tester tester; + ASSERT_SUCCESS(s_tester_init(&tester, &options)); + struct aws_http_client_connection_options client_options = AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT; + struct proxy_env_var_settings proxy_ev_settings; + AWS_ZERO_STRUCT(proxy_ev_settings); + proxy_ev_settings.env_var_type = AWS_HPEV_ENABLE; + client_options.proxy_ev_settings = &proxy_ev_settings; + + s_client_connection_options_init_tester(&client_options, &tester); + tester.client_options = client_options; + + tester.server_connection_num = 0; + tester.client_connection_num = 0; + ASSERT_SUCCESS(aws_http_client_connect(&tester.client_options)); + + /* Wait for server & client connections to finish setup */ + tester.wait_client_connection_num = 1; + tester.wait_server_connection_num = 1; + ASSERT_SUCCESS(s_tester_wait(&tester, s_tester_connection_setup_pred)); + + release_all_client_connections(&tester); + release_all_server_connections(&tester); + ASSERT_SUCCESS(s_tester_wait(&tester, s_tester_connection_shutdown_pred)); + + ASSERT_SUCCESS(s_tester_clean_up(&tester)); + return AWS_OP_SUCCESS; +} +AWS_TEST_CASE( + connection_setup_shutdown_proxy_setting_on_ev_not_found, + s_test_connection_setup_shutdown_proxy_setting_on_ev_not_found); + static int s_test_connection_h2_prior_knowledge(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct tester_options options = {