Skip to content

Commit 146f643

Browse files
authored
fix a bug I forgot (#336)
*Issue #, if available:* - if proxy env turned on and no env found, don't fail *Description of changes:* - Connect without proxy in that case. - Add testing for that case
1 parent 69edc65 commit 146f643

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

source/proxy_connection.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ static int s_connect_proxy_via_env_variable(const struct aws_http_client_connect
11901190
proxy_options.connection_type = options->proxy_ev_settings->connection_type;
11911191
if (proxy_options.connection_type == AWS_HPCT_HTTP_LEGACY) {
11921192
if (options->tls_options) {
1193-
/* Use Tunneling when main connection use TLS. */
1193+
/* Use tunneling when main connection use TLS. */
11941194
proxy_options.connection_type = AWS_HPCT_HTTP_TUNNEL;
11951195
} else {
11961196
/* 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
12121212
};
12131213
proxy_options.proxy_strategy = aws_http_proxy_strategy_new_basic_auth(options->allocator, &config);
12141214
}
1215+
} else {
1216+
success = true;
1217+
goto done;
12151218
}
12161219
struct aws_http_client_connection_options copied_options = *options;
12171220
copied_options.proxy_options = &proxy_options;
@@ -1223,6 +1226,10 @@ static int s_connect_proxy_via_env_variable(const struct aws_http_client_connect
12231226
aws_tls_connection_options_clean_up(&default_tls_connection_options);
12241227
aws_http_proxy_strategy_release(proxy_options.proxy_strategy);
12251228
aws_uri_clean_up(&proxy_uri);
1229+
if (success && !found) {
1230+
/* Successfully, but no envrionment variable found. Connect without proxy */
1231+
return aws_http_client_connect_internal(options, NULL);
1232+
}
12261233
return success ? AWS_OP_SUCCESS : AWS_OP_ERR;
12271234
}
12281235

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ add_test_case(h2_client_get_remote_settings)
442442
add_test_case(server_new_destroy)
443443
add_test_case(connection_setup_shutdown)
444444
add_test_case(connection_setup_shutdown_tls)
445+
add_test_case(connection_setup_shutdown_proxy_setting_on_ev_not_found)
445446
add_test_case(connection_h2_prior_knowledge)
446447
add_test_case(connection_h2_prior_knowledge_not_work_with_tls)
447448
add_test_case(connection_customized_alpn)

tests/test_connection.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,43 @@ static int s_test_connection_setup_shutdown_tls(struct aws_allocator *allocator,
471471
}
472472
AWS_TEST_CASE(connection_setup_shutdown_tls, s_test_connection_setup_shutdown_tls);
473473

474+
static int s_test_connection_setup_shutdown_proxy_setting_on_ev_not_found(struct aws_allocator *allocator, void *ctx) {
475+
(void)ctx;
476+
struct tester_options options = {
477+
.alloc = allocator,
478+
.no_connection = true,
479+
};
480+
struct tester tester;
481+
ASSERT_SUCCESS(s_tester_init(&tester, &options));
482+
struct aws_http_client_connection_options client_options = AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT;
483+
struct proxy_env_var_settings proxy_ev_settings;
484+
AWS_ZERO_STRUCT(proxy_ev_settings);
485+
proxy_ev_settings.env_var_type = AWS_HPEV_ENABLE;
486+
client_options.proxy_ev_settings = &proxy_ev_settings;
487+
488+
s_client_connection_options_init_tester(&client_options, &tester);
489+
tester.client_options = client_options;
490+
491+
tester.server_connection_num = 0;
492+
tester.client_connection_num = 0;
493+
ASSERT_SUCCESS(aws_http_client_connect(&tester.client_options));
494+
495+
/* Wait for server & client connections to finish setup */
496+
tester.wait_client_connection_num = 1;
497+
tester.wait_server_connection_num = 1;
498+
ASSERT_SUCCESS(s_tester_wait(&tester, s_tester_connection_setup_pred));
499+
500+
release_all_client_connections(&tester);
501+
release_all_server_connections(&tester);
502+
ASSERT_SUCCESS(s_tester_wait(&tester, s_tester_connection_shutdown_pred));
503+
504+
ASSERT_SUCCESS(s_tester_clean_up(&tester));
505+
return AWS_OP_SUCCESS;
506+
}
507+
AWS_TEST_CASE(
508+
connection_setup_shutdown_proxy_setting_on_ev_not_found,
509+
s_test_connection_setup_shutdown_proxy_setting_on_ev_not_found);
510+
474511
static int s_test_connection_h2_prior_knowledge(struct aws_allocator *allocator, void *ctx) {
475512
(void)ctx;
476513
struct tester_options options = {

0 commit comments

Comments
 (0)