@@ -72,6 +72,7 @@ struct elasticurl_ctx {
72
72
FILE * output ;
73
73
const char * trace_file ;
74
74
enum aws_log_level log_level ;
75
+ enum aws_http_version required_http_version ;
75
76
bool exchange_completed ;
76
77
bool bootstrap_shutdown_completed ;
77
78
};
@@ -104,7 +105,8 @@ static void s_usage(int exit_code) {
104
105
fprintf (stderr , " -t, --trace FILE: dumps logs to FILE instead of stderr.\n" );
105
106
fprintf (stderr , " -v, --verbose: ERROR|INFO|DEBUG|TRACE: log level to configure. Default is none.\n" );
106
107
fprintf (stderr , " --version: print the version of elasticurl.\n" );
107
- fprintf (stderr , " --http2: try to use HTTP/2" );
108
+ fprintf (stderr , " --http2: HTTP/2 connection required" );
109
+ fprintf (stderr , " --http1_1: HTTP/1.1 connection required" );
108
110
fprintf (stderr , " -h, --help\n" );
109
111
fprintf (stderr , " Display this message and quit.\n" );
110
112
exit (exit_code );
@@ -133,6 +135,7 @@ static struct aws_cli_option s_long_options[] = {
133
135
{"verbose" , AWS_CLI_OPTIONS_REQUIRED_ARGUMENT , NULL , 'v' },
134
136
{"version" , AWS_CLI_OPTIONS_NO_ARGUMENT , NULL , 'V' },
135
137
{"http2" , AWS_CLI_OPTIONS_NO_ARGUMENT , NULL , 'w' },
138
+ {"http1_1" , AWS_CLI_OPTIONS_NO_ARGUMENT , NULL , 'W' },
136
139
{"help" , AWS_CLI_OPTIONS_NO_ARGUMENT , NULL , 'h' },
137
140
/* Per getopt(3) the last element of the array has to be filled with all zeros */
138
141
{NULL , AWS_CLI_OPTIONS_NO_ARGUMENT , NULL , 0 },
@@ -169,7 +172,7 @@ static void s_parse_options(int argc, char **argv, struct elasticurl_ctx *ctx) {
169
172
while (true) {
170
173
int option_index = 0 ;
171
174
int c =
172
- aws_cli_getopt_long (argc , argv , "a:b:c:e:f:H:d:g:j:l:m:M:GPHiko:t:v:Vwh " , s_long_options , & option_index );
175
+ aws_cli_getopt_long (argc , argv , "a:b:c:e:f:H:d:g:j:l:m:M:GPHiko:t:v:VwWh " , s_long_options , & option_index );
173
176
if (c == -1 ) {
174
177
break ;
175
178
}
@@ -277,6 +280,11 @@ static void s_parse_options(int argc, char **argv, struct elasticurl_ctx *ctx) {
277
280
exit (0 );
278
281
case 'w' :
279
282
ctx -> alpn = "h2" ;
283
+ ctx -> required_http_version = AWS_HTTP_VERSION_2 ;
284
+ break ;
285
+ case 'W' :
286
+ ctx -> alpn = "http/1.1" ;
287
+ ctx -> required_http_version = AWS_HTTP_VERSION_1_1 ;
280
288
break ;
281
289
case 'h' :
282
290
s_usage (0 );
@@ -453,6 +461,12 @@ static void s_on_signing_complete(struct aws_http_message *request, int error_co
453
461
454
462
static void s_on_client_connection_setup (struct aws_http_connection * connection , int error_code , void * user_data ) {
455
463
struct elasticurl_ctx * app_ctx = user_data ;
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
+ }
456
470
457
471
if (error_code ) {
458
472
fprintf (stderr , "Connection failed with error %s\n" , aws_error_debug_str (error_code ));
@@ -560,7 +574,7 @@ int main(int argc, char **argv) {
560
574
app_ctx .connect_timeout = 3000 ;
561
575
app_ctx .output = stdout ;
562
576
app_ctx .verb = "GET" ;
563
- app_ctx .alpn = "http/1.1" ;
577
+ app_ctx .alpn = "h2; http/1.1" ;
564
578
aws_mutex_init (& app_ctx .mutex );
565
579
aws_hash_table_init (
566
580
& app_ctx .signing_context ,
@@ -675,6 +689,10 @@ int main(int argc, char **argv) {
675
689
port = app_ctx .uri .port ;
676
690
}
677
691
} else {
692
+ if (app_ctx .required_http_version == AWS_HTTP_VERSION_2 ) {
693
+ fprintf (stderr , "Error, we don't support h2c, please use TLS for HTTP2 connection" );
694
+ exit (1 );
695
+ }
678
696
port = 80 ;
679
697
if (app_ctx .uri .port ) {
680
698
port = app_ctx .uri .port ;
0 commit comments