From d0b5b027d5e62e393fbb3c678bc9050ce6864b47 Mon Sep 17 00:00:00 2001 From: wenqiang3 Date: Sat, 23 Sep 2017 09:14:35 +0800 Subject: [PATCH 1/3] add feature test http2 upport sni --- lib/Test/Nginx/Socket.pm | 9 ++++++++- lib/Test/Nginx/Util.pm | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index a03ce17b..272928b8 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -2121,8 +2121,11 @@ sub gen_curl_cmd_from_req ($$) { push @args, '-sS'; } - if (use_http2($block)) { + my $isHttp2 = use_http2($block); + if ($isHttp2 && $isHttp2 == 1) { push @args, '--http2', '--http2-prior-knowledge'; + } elsif ($isHttp2 && $isHttp2 == 2) { + push @args, '-k', '--http2', '--http2-prior-knowledge', '--resolve', "$ServerName:$ServerPortForClient:$ServerAddr", } if ($meth eq 'HEAD') { @@ -2193,6 +2196,10 @@ sub gen_curl_cmd_from_req ($$) { $link = "http://$server:$port$uri"; } + if (use_http2($block) == 2) { + $link = "https://$ServerName:$ServerPortForClient$uri"; + } + push @args, $link; return \@args; diff --git a/lib/Test/Nginx/Util.pm b/lib/Test/Nginx/Util.pm index 5d684378..2ee9a1de 100644 --- a/lib/Test/Nginx/Util.pm +++ b/lib/Test/Nginx/Util.pm @@ -942,8 +942,11 @@ _EOC_ my $listen_opts = ''; - if (use_http2($block)) { + my $isHttp2 = use_http2($block); + if ($isHttp2 && $isHttp2 == 1) { $listen_opts .= " http2"; + } elsif ($isHttp2 && $isHttp2 == 2) { + $listen_opts .= " ssl http2"; } print $out <<_EOC_; @@ -2499,6 +2502,11 @@ sub use_http2 ($) { bail_out("cannot use --- http2 with --- pipelined_requests"); } + if (defined $block->sni) { + $block->set_value("test_nginx_enabled_http2_sni", 1); + return 2; + } + $block->set_value("test_nginx_enabled_http2", 1); return 1; } @@ -2527,6 +2535,11 @@ sub use_http2 ($) { return undef; } + if ($block->sni) { + $block->set_value("test_nginx_enabled_http2_sni", 1); + return 2; + } + $block->set_value("test_nginx_enabled_http2", 1); return 1; } From e6a2495dbd046ec88898cdc06509b620dab8d55c Mon Sep 17 00:00:00 2001 From: wenqiang3 Date: Sat, 23 Sep 2017 10:38:47 +0800 Subject: [PATCH 2/3] add instructions for SNI --- lib/Test/Nginx/Socket.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index 272928b8..954ee3ec 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -3984,7 +3984,7 @@ starts. The following environment variables are supported by this module: =head2 TEST_NGINX_USE_HTTP2 Enables the "http2" test mode by enforcing using the (plain text) HTTP/2 protocol to send the -test request. +test request. Also, you can set sni section using the TLS HTTP/2 protocol and SNI(Server Name Indication). Under the hood, the test scaffold uses the `curl` command-line utility to do the wire communication with the NGINX server. The `curl` utility must be recent enough to support both the C<--http2> @@ -3998,6 +3998,10 @@ One can enable HTTP/2 mode for an individual test block by specifying the L section, as in + + --- sni + =head2 TEST_NGINX_VERBOSE Controls whether to output verbose debugging messages in Test::Nginx. Default to empty. From abad78632de9f64fe8f51707b86950572011ce71 Mon Sep 17 00:00:00 2001 From: wenqiang3 Date: Sat, 23 Sep 2017 17:31:19 +0800 Subject: [PATCH 3/3] fix style --- lib/Test/Nginx/Socket.pm | 25 ++++++++++++++----------- lib/Test/Nginx/Util.pm | 19 +++++-------------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index 954ee3ec..2befa7f4 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -2121,11 +2121,13 @@ sub gen_curl_cmd_from_req ($$) { push @args, '-sS'; } - my $isHttp2 = use_http2($block); - if ($isHttp2 && $isHttp2 == 1) { + if (use_http2($block)) { push @args, '--http2', '--http2-prior-knowledge'; - } elsif ($isHttp2 && $isHttp2 == 2) { - push @args, '-k', '--http2', '--http2-prior-knowledge', '--resolve', "$ServerName:$ServerPortForClient:$ServerAddr", + } + + if (use_http2($block) && defined $block->tls) { + my $resolve = "$ServerName:$ServerPortForClient:$ServerAddr"; + push @args, '-k', '--resolve', $resolve; } if ($meth eq 'HEAD') { @@ -2194,10 +2196,10 @@ sub gen_curl_cmd_from_req ($$) { my $server = $ServerAddr; my $port = $ServerPortForClient; $link = "http://$server:$port$uri"; - } - - if (use_http2($block) == 2) { - $link = "https://$ServerName:$ServerPortForClient$uri"; + if (use_http2($block) && defined $block->tls) { + my $server_name = $ServerName; + $link = "https://$server_name:$port$uri"; + } } push @args, $link; @@ -2871,6 +2873,7 @@ The following sections are supported: =head2 http2 Enforces the test scaffold to use the HTTP/2 wire protocol to send the test request. +Also, you can set tls section using the HTTP/2 over TLS protocol and SNI(Server Name Indication). Under the hood, the test scaffold uses the `curl` command-line utility to do the wire communication with the NGINX server. The `curl` utility must be recent enough to support both the C<--http2> @@ -3984,7 +3987,7 @@ starts. The following environment variables are supported by this module: =head2 TEST_NGINX_USE_HTTP2 Enables the "http2" test mode by enforcing using the (plain text) HTTP/2 protocol to send the -test request. Also, you can set sni section using the TLS HTTP/2 protocol and SNI(Server Name Indication). +test request. Under the hood, the test scaffold uses the `curl` command-line utility to do the wire communication with the NGINX server. The `curl` utility must be recent enough to support both the C<--http2> @@ -3998,9 +4001,9 @@ One can enable HTTP/2 mode for an individual test block by specifying the L section, as in +Enable HTTP/2 over TLS mode for an individual test block by specifying the L section, as in - --- sni + --- tls =head2 TEST_NGINX_VERBOSE diff --git a/lib/Test/Nginx/Util.pm b/lib/Test/Nginx/Util.pm index 2ee9a1de..88a67da1 100644 --- a/lib/Test/Nginx/Util.pm +++ b/lib/Test/Nginx/Util.pm @@ -942,11 +942,12 @@ _EOC_ my $listen_opts = ''; - my $isHttp2 = use_http2($block); - if ($isHttp2 && $isHttp2 == 1) { + if (use_http2($block) && defined $block->tls) { + $listen_opts .= " ssl"; + } + + if (use_http2($block)) { $listen_opts .= " http2"; - } elsif ($isHttp2 && $isHttp2 == 2) { - $listen_opts .= " ssl http2"; } print $out <<_EOC_; @@ -2502,11 +2503,6 @@ sub use_http2 ($) { bail_out("cannot use --- http2 with --- pipelined_requests"); } - if (defined $block->sni) { - $block->set_value("test_nginx_enabled_http2_sni", 1); - return 2; - } - $block->set_value("test_nginx_enabled_http2", 1); return 1; } @@ -2535,11 +2531,6 @@ sub use_http2 ($) { return undef; } - if ($block->sni) { - $block->set_value("test_nginx_enabled_http2_sni", 1); - return 2; - } - $block->set_value("test_nginx_enabled_http2", 1); return 1; }