Mercurial > hg > nginx-tests
annotate h2_http2.t @ 1905:f35824e75b66
Tests: fixed reading QUIC streams on Perl < 5.24.
The parse_stream() routine has had a missing explicit return if there were no
streams received. In Perl < 5.24 this used to return no value, or an empty
array in the list context. In modern Perl this returns an empty value, or an
array of 1 element, which made the check for last index of the returned array
work rather by accident.
The fix is to return explicitly and to check the array size in callers instead.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 06 Jun 2023 18:50:07 +0400 |
parents | c560f5da581e |
children | 034c9121b9d1 |
rev | line source |
---|---|
1902
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for HTTP/2 protocol, http2 directive. |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::HTTP2; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 socket_ssl_alpn/) |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 ->has_daemon('openssl'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 http { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 ssl_certificate_key localhost.key; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 ssl_certificate localhost.crt; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 listen 127.0.0.1:8443 ssl; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server_name default; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 http2 on; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 listen 127.0.0.1:8443; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 server_name http2; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 http2 on; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 listen 127.0.0.1:8443; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 server_name disabled; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 http2 off; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 listen 127.0.0.1:8444 ssl; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 server_name default; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 listen 127.0.0.1:8444; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 server_name http2; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 http2 on; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 listen 127.0.0.1:8080; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 server_name localhost; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 http2 on; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 server { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 listen 127.0.0.1:8081 http2; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 server_name localhost; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 EOF |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 $t->write_file('openssl.conf', <<EOF); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 [ req ] |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 default_bits = 2048 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 encrypt_key = no |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 distinguished_name = req_distinguished_name |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 [ req_distinguished_name ] |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 EOF |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 my $d = $t->testdir(); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 foreach my $name ('localhost') { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 system('openssl req -x509 -new ' |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 . "-config $d/openssl.conf -subj /CN=$name/ " |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 . "-out $d/$name.crt -keyout $d/$name.key " |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 . ">>$d/openssl.out 2>&1") == 0 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 or die "Can't create certificate for $name: $!\n"; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 $t->write_file('index.html', ''); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 $t->try_run('no http2')->plan(11); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 ############################################################################### |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 # make sure HTTP/2 can be disabled selectively on virtual servers |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 ok(get_ssl_socket(8443), 'default to enabled'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 ok(!get_ssl_socket(8443, 'disabled'), 'sni to disabled'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 is(get_https(8443, 'http2'), 200, 'host to enabled'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 is(get_https(8443, 'disabled', 'http2'), 421, 'host to disabled'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 # make sure HTTP/2 can be enabled selectively on virtual servers |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 ok(!get_ssl_socket(8444), 'default to disabled'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 is(get_https(8444, 'http2'), 200, 'sni to enabled'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 # http2 detection on plain tcp socket by connection preface |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 like(http_get('/'), qr/200 OK/, 'non-ssl http'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 is(get_http(8080), 200, 'non-ssl http2'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 like(http_get('/', socket => IO::Socket::INET->new('127.0.0.1:' . port(8081))), |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 qr/200 OK/, 'non-ssl http deprecated'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 is(get_http(8081), 200, 'non-ssl http2 deprecated'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 my $sock = http("PRI * HTTP/2.0\r\n\r\n", start => 1); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 select undef, undef, undef, 0.2; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 is(get_http(8080, 'localhost', $sock, "SM\r\n\r\n"), 200, |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 'preface with multiple packets'); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 ############################################################################### |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 sub get_http { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 my ($port, $host, $sock, $preface) = @_; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 my $s = Test::Nginx::HTTP2->new(port($port), |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 socket => $sock, preface => $preface); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 my $sid = $s->new_stream({ host => $host }); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 return $frame->{headers}->{':status'}; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 sub get_https { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 my ($port, $host, $sni, $alpn) = @_; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 my $sock = get_ssl_socket($port, $sni || $host, $alpn); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 return get_http($port, $host, $sock); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 sub get_ssl_socket { |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 my ($port, $sni, $alpn) = @_; |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 return http('', PeerAddr => '127.0.0.1:' . port($port), start => 1, |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 SSL => 1, |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 SSL_hostname => $sni, |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 SSL_alpn_protocols => $alpn || ['h2']); |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 } |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 |
c560f5da581e
Tests: http2 directive tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 ############################################################################### |