Skip to content

Commit 183d505

Browse files
authored
check the return code first, in case the connection is null (#278)
Co-authored-by: Dengke Tang <[email protected]>
1 parent 79579f6 commit 183d505

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

bin/elasticurl/main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,6 @@ static void s_on_signing_complete(struct aws_http_message *request, int error_co
451451

452452
static void s_on_client_connection_setup(struct aws_http_connection *connection, int error_code, void *user_data) {
453453
struct elasticurl_ctx *app_ctx = user_data;
454-
if (app_ctx->required_http_version) {
455-
if (aws_http_connection_get_version(connection) != app_ctx->required_http_version) {
456-
fprintf(stderr, "Error. The requested HTTP version, %s, is not supported by the peer.", app_ctx->alpn);
457-
exit(1);
458-
}
459-
}
460454

461455
if (error_code) {
462456
fprintf(stderr, "Connection failed with error %s\n", aws_error_debug_str(error_code));
@@ -467,6 +461,13 @@ static void s_on_client_connection_setup(struct aws_http_connection *connection,
467461
return;
468462
}
469463

464+
if (app_ctx->required_http_version) {
465+
if (aws_http_connection_get_version(connection) != app_ctx->required_http_version) {
466+
fprintf(stderr, "Error. The requested HTTP version, %s, is not supported by the peer.", app_ctx->alpn);
467+
exit(1);
468+
}
469+
}
470+
470471
app_ctx->connection = connection;
471472
app_ctx->request = s_build_http_request(app_ctx);
472473

0 commit comments

Comments
 (0)