Mercurial > hg > nginx-tests
annotate h2.t @ 714:ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 25 Sep 2015 23:30:39 +0300 |
parents | 649af6069976 |
children | 9ee52e137f3d |
rev | line source |
---|---|
646 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 protocol [RFC7540]. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 use IO::Select; | |
16 use Socket qw/ CRLF /; | |
17 | |
18 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
19 | |
20 use lib 'lib'; | |
21 use Test::Nginx; | |
22 | |
23 ############################################################################### | |
24 | |
25 select STDERR; $| = 1; | |
26 select STDOUT; $| = 1; | |
27 | |
650
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
28 eval { require IO::Socket::SSL; }; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
29 plan(skip_all => 'IO::Socket::SSL not installed') if $@; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
31 plan(skip_all => 'IO::Socket::SSL too old') if $@; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
32 |
646 | 33 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/) |
650
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
34 ->has(qw/limit_conn rewrite realip shmem/) |
714
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
35 ->has_daemon('openssl')->plan(202); |
704
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
36 |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
37 # FreeBSD has a bug in not treating zero iovcnt as EINVAL |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
38 |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
39 $t->todo_alerts() unless $^O eq 'freebsd'; |
646 | 40 |
41 $t->write_file_expand('nginx.conf', <<'EOF'); | |
42 | |
43 %%TEST_GLOBALS%% | |
44 | |
45 daemon off; | |
46 | |
47 events { | |
48 } | |
49 | |
50 http { | |
51 %%TEST_GLOBALS_HTTP%% | |
52 | |
53 proxy_cache_path %%TESTDIR%%/cache keys_zone=NAME:1m; | |
54 limit_conn_zone $binary_remote_addr zone=conn:1m; | |
55 | |
56 server { | |
57 listen 127.0.0.1:8080 http2; | |
58 listen 127.0.0.1:8081; | |
59 listen 127.0.0.1:8082 proxy_protocol http2; | |
60 listen 127.0.0.1:8084 http2 ssl; | |
61 server_name localhost; | |
62 | |
63 ssl_certificate_key localhost.key; | |
64 ssl_certificate localhost.crt; | |
696
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
65 http2_max_field_size 128k; |
698
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
66 http2_max_header_size 128k; |
646 | 67 |
68 location / { | |
69 add_header X-Header X-Foo; | |
70 add_header X-Sent-Foo $http_x_foo; | |
71 add_header X-Referer $http_referer; | |
72 return 200 'body'; | |
73 } | |
74 location /t { | |
75 } | |
76 location /t3.html { | |
77 limit_conn conn 1; | |
78 } | |
79 location /gzip.html { | |
80 gzip on; | |
81 gzip_min_length 0; | |
82 alias %%TESTDIR%%/t2.html; | |
83 } | |
680
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
84 location /frame_size { |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
85 http2_chunk_size 64k; |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
86 alias %%TESTDIR%%/t1.html; |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
87 output_buffers 2 1m; |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
88 } |
696
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
89 location /continuation { |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
90 add_header X-LongHeader $arg_h; |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
91 add_header X-LongHeader $arg_h; |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
92 add_header X-LongHeader $arg_h; |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
93 return 200 body; |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
94 |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
95 location /continuation/204 { |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
96 return 204; |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
97 } |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
98 } |
646 | 99 location /pp { |
100 set_real_ip_from 127.0.0.1/32; | |
101 real_ip_header proxy_protocol; | |
102 alias %%TESTDIR%%/t2.html; | |
103 add_header X-PP $remote_addr; | |
104 } | |
650
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
105 location /h2 { |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
106 return 200 $http2; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
107 } |
651
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
108 location /chunk_size { |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
109 http2_chunk_size 1; |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
110 return 200 'body'; |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
111 } |
646 | 112 location /redirect { |
113 error_page 405 /; | |
114 return 405; | |
115 } | |
116 location /return301 { | |
117 return 301; | |
118 } | |
119 location /return301_absolute { | |
120 return 301 text; | |
121 } | |
122 location /return301_relative { | |
123 return 301 /; | |
124 } | |
125 location /proxy/ { | |
126 add_header X-UC-a $upstream_cookie_a; | |
127 add_header X-UC-c $upstream_cookie_c; | |
128 proxy_pass http://127.0.0.1:8083/; | |
129 proxy_cache NAME; | |
130 proxy_cache_valid 1m; | |
652
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
131 proxy_set_header X-Cookie-a $cookie_a; |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
132 proxy_set_header X-Cookie-c $cookie_c; |
646 | 133 } |
134 location /proxy2/ { | |
135 add_header X-Body "$request_body"; | |
136 proxy_pass http://127.0.0.1:8081/; | |
137 proxy_cache NAME; | |
138 proxy_cache_valid 1m; | |
139 } | |
140 location /proxy_buffering_off { | |
141 proxy_pass http://127.0.0.1:8081/; | |
142 proxy_cache NAME; | |
143 proxy_cache_valid 1m; | |
144 proxy_buffering off; | |
145 } | |
146 location /set-cookie { | |
147 add_header Set-Cookie a=b; | |
148 add_header Set-Cookie c=d; | |
149 return 200; | |
150 } | |
151 location /cookie { | |
152 add_header X-Cookie $http_cookie; | |
153 add_header X-Cookie-a $cookie_a; | |
154 add_header X-Cookie-c $cookie_c; | |
155 return 200; | |
156 } | |
157 } | |
158 | |
159 server { | |
160 listen 127.0.0.1:8085 http2; | |
161 server_name localhost; | |
162 return 200 first; | |
163 } | |
164 | |
165 server { | |
166 listen 127.0.0.1:8085 http2; | |
167 server_name localhost2; | |
168 return 200 second; | |
169 } | |
654
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
170 |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
171 server { |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
172 listen 127.0.0.1:8086 http2; |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
173 server_name localhost; |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
174 |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
175 http2_max_concurrent_streams 1; |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
176 } |
684
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
177 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
178 server { |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
179 listen 127.0.0.1:8087 http2; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
180 server_name localhost; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
181 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
182 http2_max_field_size 32; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
183 } |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
184 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
185 server { |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
186 listen 127.0.0.1:8088 http2; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
187 server_name localhost; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
188 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
189 http2_max_header_size 64; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
190 } |
714
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
191 |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
192 server { |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
193 listen 127.0.0.1:8089 http2; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
194 server_name localhost; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
195 |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
196 http2_recv_timeout 1s; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
197 } |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
198 |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
199 server { |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
200 listen 127.0.0.1:8090 http2; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
201 server_name localhost; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
202 |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
203 http2_idle_timeout 1s; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
204 } |
646 | 205 } |
206 | |
207 EOF | |
208 | |
209 $t->write_file('openssl.conf', <<EOF); | |
210 [ req ] | |
211 default_bits = 2048 | |
212 encrypt_key = no | |
213 distinguished_name = req_distinguished_name | |
214 [ req_distinguished_name ] | |
215 EOF | |
216 | |
217 my $d = $t->testdir(); | |
218 | |
219 foreach my $name ('localhost') { | |
220 system('openssl req -x509 -new ' | |
221 . "-config '$d/openssl.conf' -subj '/CN=$name/' " | |
222 . "-out '$d/$name.crt' -keyout '$d/$name.key' " | |
223 . ">>$d/openssl.out 2>&1") == 0 | |
224 or die "Can't create certificate for $name: $!\n"; | |
225 } | |
226 | |
227 $t->run_daemon(\&http_daemon); | |
228 $t->run()->waitforsocket('127.0.0.1:8083'); | |
229 | |
230 # file size is slightly beyond initial window size: 2**16 + 80 bytes | |
231 | |
232 $t->write_file('t1.html', | |
233 join('', map { sprintf "X%04dXXX", $_ } (1 .. 8202))); | |
234 $t->write_file('tbig.html', | |
704
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
235 join('', map { sprintf "XX%06dXX", $_ } (1 .. 100000))); |
646 | 236 |
237 $t->write_file('t2.html', 'SEE-THIS'); | |
238 $t->write_file('t3.html', 'SEE-THIS'); | |
239 | |
240 my %cframe = ( | |
241 0 => { name => 'DATA', value => \&data }, | |
242 1 => { name => 'HEADERS', value => \&headers }, | |
243 # 2 => { name => 'PRIORITY', value => \&priority }, | |
244 3 => { name => 'RST_STREAM', value => \&rst_stream }, | |
245 4 => { name => 'SETTINGS', value => \&settings }, | |
246 # 5 => { name => 'PUSH_PROIMSE', value => \&push_promise }, | |
247 6 => { name => 'PING', value => \&ping }, | |
248 7 => { name => 'GOAWAY', value => \&goaway }, | |
249 8 => { name => 'WINDOW_UPDATE', value => \&window_update }, | |
696
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
250 9 => { name => 'CONTINUATION', value => \&headers }, |
646 | 251 ); |
252 | |
253 ############################################################################### | |
254 | |
255 # SETTINGS | |
256 | |
257 my $sess = new_session(); | |
258 my $frames = h2_read($sess, all => [ | |
259 { type => 'WINDOW_UPDATE' }, | |
260 { type => 'SETTINGS'} | |
261 ]); | |
262 | |
263 my ($frame) = grep { $_->{type} eq 'WINDOW_UPDATE' } @$frames; | |
264 ok($frame, 'WINDOW_UPDATE frame'); | |
265 is($frame->{flags}, 0, 'WINDOW_UPDATE zero flags'); | |
266 is($frame->{sid}, 0, 'WINDOW_UPDATE zero sid'); | |
267 is($frame->{length}, 4, 'WINDOW_UPDATE fixed length'); | |
268 | |
269 ($frame) = grep { $_->{type} eq 'SETTINGS' } @$frames; | |
270 ok($frame, 'SETTINGS frame'); | |
271 is($frame->{flags}, 0, 'SETTINGS flags'); | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
272 is($frame->{sid}, 0, 'SETTINGS stream'); |
646 | 273 |
274 h2_settings($sess, 1); | |
275 h2_settings($sess, 0); | |
276 | |
277 $frames = h2_read($sess, all => [{ type => 'SETTINGS' }]); | |
278 | |
279 ($frame) = grep { $_->{type} eq 'SETTINGS' } @$frames; | |
280 ok($frame, 'SETTINGS frame ack'); | |
281 is($frame->{flags}, 1, 'SETTINGS flags ack'); | |
282 | |
283 # PING | |
284 | |
285 h2_ping($sess, 'SEE-THIS'); | |
286 $frames = h2_read($sess, all => [{ type => 'PING' }]); | |
287 | |
288 ($frame) = grep { $_->{type} eq "PING" } @$frames; | |
289 ok($frame, 'PING frame'); | |
290 is($frame->{value}, 'SEE-THIS', 'PING payload'); | |
291 is($frame->{flags}, 1, 'PING flags ack'); | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
292 is($frame->{sid}, 0, 'PING stream'); |
646 | 293 |
714
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
294 # timeouts |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
295 |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
296 push my @sess, new_session(8089); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
297 push @sess, new_session(8089); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
298 h2_ping($sess[-1], 'SEE-THIS'); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
299 push @sess, new_session(8090); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
300 push @sess, new_session(8090); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
301 h2_ping($sess[-1], 'SEE-THIS'); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
302 |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
303 select undef, undef, undef, 2.1; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
304 |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
305 $frames = h2_read(shift @sess, all => [{ type => "GOAWAY" }]); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
306 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
307 ok($frame, 'recv timeout - new connection GOAWAY'); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
308 is($frame->{code}, 1, 'recv timeout - new connection code'); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
309 |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
310 $frames = h2_read(shift @sess, all => [{ type => "GOAWAY" }]); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
311 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
312 is($frame, undef, 'recv timeout - idle connection GOAWAY'); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
313 |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
314 $frames = h2_read(shift @sess, all => [{ type => "GOAWAY" }]); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
315 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
316 is($frame, undef, 'idle timeout - new connection GOAWAY'); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
317 |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
318 $frames = h2_read(shift @sess, all => [{ type => "GOAWAY" }]); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
319 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
320 ok($frame, 'idle timeout - idle connection GOAWAY'); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
321 is($frame->{code}, 0, 'idle timeout - idle connection code'); |
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
322 |
646 | 323 # GET |
324 | |
714
ccc9f389e1f8
Tests: HTTP/2 connection timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
712
diff
changeset
|
325 $sess = new_session(); |
646 | 326 my $sid = new_stream($sess); |
327 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
328 | |
329 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
330 ok($frame, 'HEADERS frame'); | |
331 is($frame->{sid}, $sid, 'HEADERS stream'); | |
332 is($frame->{headers}->{':status'}, 200, 'HEADERS status'); | |
333 is($frame->{headers}->{'x-header'}, 'X-Foo', 'HEADERS header'); | |
334 | |
335 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
336 ok($frame, 'DATA frame'); | |
337 is($frame->{length}, length 'body', 'DATA length'); | |
338 is($frame->{data}, 'body', 'DATA payload'); | |
339 | |
340 # GET in the new stream on same connection | |
341 | |
342 $sid = new_stream($sess); | |
343 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
344 | |
345 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
346 is($frame->{sid}, $sid, 'HEADERS stream 2'); | |
347 is($frame->{headers}->{':status'}, 200, 'HEADERS status 2'); | |
348 is($frame->{headers}->{'x-header'}, 'X-Foo', 'HEADERS header 2'); | |
349 | |
350 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
351 ok($frame, 'DATA frame 2'); | |
352 is($frame->{sid}, $sid, 'HEADERS stream 2'); | |
353 is($frame->{length}, length 'body', 'DATA length 2'); | |
354 is($frame->{data}, 'body', 'DATA payload 2'); | |
355 | |
356 # various HEADERS compression/encoding, see hpack() for mode details | |
357 | |
358 # 6.1. Indexed Header Field Representation | |
359 | |
360 $sid = new_stream($sess, { headers => [ | |
361 { name => ':method', value => 'GET', mode => 0 }, | |
362 { name => ':scheme', value => 'http', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
363 { name => ':path', value => '/', mode => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
364 { name => ':authority', value => 'localhost', mode => 1 }]}); |
646 | 365 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
366 | |
367 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
368 is($frame->{headers}->{':status'}, 200, 'indexed header field'); | |
369 | |
370 # 6.2.1. Literal Header Field with Incremental Indexing | |
371 | |
372 $sid = new_stream($sess, { headers => [ | |
373 { name => ':method', value => 'GET', mode => 1, huff => 0 }, | |
374 { name => ':scheme', value => 'http', mode => 1, huff => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
375 { name => ':path', value => '/', mode => 1, huff => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
376 { name => ':authority', value => 'localhost', mode => 1, huff => 0 }]}); |
646 | 377 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
378 | |
379 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
380 is($frame->{headers}->{':status'}, 200, 'literal with indexing'); | |
381 | |
382 $sid = new_stream($sess, { headers => [ | |
383 { name => ':method', value => 'GET', mode => 1, huff => 1 }, | |
384 { name => ':scheme', value => 'http', mode => 1, huff => 1 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
385 { name => ':path', value => '/', mode => 1, huff => 1 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
386 { name => ':authority', value => 'localhost', mode => 1, huff => 1 }]}); |
646 | 387 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
388 | |
389 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
390 is($frame->{headers}->{':status'}, 200, 'literal with indexing - huffman'); | |
391 | |
392 # 6.2.1. Literal Header Field with Incremental Indexing -- New Name | |
393 | |
394 $sid = new_stream($sess, { headers => [ | |
395 { name => ':method', value => 'GET', mode => 2, huff => 0 }, | |
396 { name => ':scheme', value => 'http', mode => 2, huff => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
397 { name => ':path', value => '/', mode => 2, huff => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
398 { name => ':authority', value => 'localhost', mode => 2, huff => 0 }]}); |
646 | 399 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
400 | |
401 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
402 is($frame->{headers}->{':status'}, 200, 'literal with indexing - new'); | |
403 | |
404 $sid = new_stream($sess, { headers => [ | |
405 { name => ':method', value => 'GET', mode => 2, huff => 1 }, | |
406 { name => ':scheme', value => 'http', mode => 2, huff => 1 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
407 { name => ':path', value => '/', mode => 2, huff => 1 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
408 { name => ':authority', value => 'localhost', mode => 2, huff => 1 }]}); |
646 | 409 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
410 | |
411 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
412 is($frame->{headers}->{':status'}, 200, 'literal with indexing - new huffman'); | |
413 | |
414 # 6.2.2. Literal Header Field without Indexing | |
415 | |
416 $sid = new_stream($sess, { headers => [ | |
417 { name => ':method', value => 'GET', mode => 3, huff => 0 }, | |
418 { name => ':scheme', value => 'http', mode => 3, huff => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
419 { name => ':path', value => '/', mode => 3, huff => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
420 { name => ':authority', value => 'localhost', mode => 3, huff => 0 }]}); |
646 | 421 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
422 | |
423 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
424 is($frame->{headers}->{':status'}, 200, 'literal without indexing'); | |
425 | |
426 $sid = new_stream($sess, { headers => [ | |
427 { name => ':method', value => 'GET', mode => 3, huff => 1 }, | |
428 { name => ':scheme', value => 'http', mode => 3, huff => 1 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
429 { name => ':path', value => '/', mode => 3, huff => 1 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
430 { name => ':authority', value => 'localhost', mode => 3, huff => 1 }]}); |
646 | 431 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
432 | |
433 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
434 is($frame->{headers}->{':status'}, 200, 'literal without indexing - huffman'); | |
435 | |
436 # 6.2.2. Literal Header Field without Indexing -- New Name | |
437 | |
438 $sid = new_stream($sess, { headers => [ | |
439 { name => ':method', value => 'GET', mode => 4, huff => 0 }, | |
440 { name => ':scheme', value => 'http', mode => 4, huff => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
441 { name => ':path', value => '/', mode => 4, huff => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
442 { name => ':authority', value => 'localhost', mode => 4, huff => 0 }]}); |
646 | 443 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
444 | |
445 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
446 is($frame->{headers}->{':status'}, 200, 'literal without indexing - new'); | |
447 | |
448 $sid = new_stream($sess, { headers => [ | |
449 { name => ':method', value => 'GET', mode => 4, huff => 1 }, | |
450 { name => ':scheme', value => 'http', mode => 4, huff => 1 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
451 { name => ':path', value => '/', mode => 4, huff => 1 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
452 { name => ':authority', value => 'localhost', mode => 4, huff => 1 }]}); |
646 | 453 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
454 | |
455 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
456 is($frame->{headers}->{':status'}, 200, 'literal without indexing - new huffman'); | |
457 | |
458 # 6.2.3. Literal Header Field Never Indexed | |
459 | |
460 $sid = new_stream($sess, { headers => [ | |
461 { name => ':method', value => 'GET', mode => 5, huff => 0 }, | |
462 { name => ':scheme', value => 'http', mode => 5, huff => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
463 { name => ':path', value => '/', mode => 5, huff => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
464 { name => ':authority', value => 'localhost', mode => 5, huff => 0 }]}); |
646 | 465 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
466 | |
467 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
468 is($frame->{headers}->{':status'}, 200, 'literal never indexed'); | |
469 | |
470 $sid = new_stream($sess, { headers => [ | |
471 { name => ':method', value => 'GET', mode => 5, huff => 1 }, | |
472 { name => ':scheme', value => 'http', mode => 5, huff => 1 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
473 { name => ':path', value => '/', mode => 5, huff => 1 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
474 { name => ':authority', value => 'localhost', mode => 5, huff => 1 }]}); |
646 | 475 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
476 | |
477 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
478 is($frame->{headers}->{':status'}, 200, 'literal never indexed - huffman'); | |
479 | |
480 # 6.2.2. Literal Header Field Never Indexed -- New Name | |
481 | |
482 $sid = new_stream($sess, { headers => [ | |
483 { name => ':method', value => 'GET', mode => 6, huff => 0 }, | |
484 { name => ':scheme', value => 'http', mode => 6, huff => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
485 { name => ':path', value => '/', mode => 6, huff => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
486 { name => ':authority', value => 'localhost', mode => 6, huff => 0 }]}); |
646 | 487 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
488 | |
489 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
490 is($frame->{headers}->{':status'}, 200, 'literal never indexed - new'); | |
491 | |
492 $sid = new_stream($sess, { headers => [ | |
493 { name => ':method', value => 'GET', mode => 6, huff => 1 }, | |
494 { name => ':scheme', value => 'http', mode => 6, huff => 1 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
495 { name => ':path', value => '/', mode => 6, huff => 1 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
496 { name => ':authority', value => 'localhost', mode => 6, huff => 1 }]}); |
646 | 497 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
498 | |
499 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
500 is($frame->{headers}->{':status'}, 200, 'literal never indexed - new huffman'); | |
501 | |
502 # reuse literal with indexing | |
503 | |
504 $sess = new_session(); | |
505 $sid = new_stream($sess, { headers => [ | |
506 { name => ':method', value => 'GET', mode => 0 }, | |
507 { name => ':scheme', value => 'http', mode => 0 }, | |
508 { name => ':path', value => '/', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
509 { name => ':authority', value => 'localhost', mode => 1 }, |
646 | 510 { name => 'referer', value => 'foo', mode => 1 }]}); |
511 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
512 | |
513 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
514 is($frame->{headers}->{'x-referer'}, 'foo', 'value with indexing - new'); | |
515 | |
516 $sid = new_stream($sess, { headers => [ | |
517 { name => ':method', value => 'GET', mode => 0 }, | |
518 { name => ':scheme', value => 'http', mode => 0 }, | |
519 { name => ':path', value => '/', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
520 { name => ':authority', value => 'localhost', mode => 0 }, |
646 | 521 { name => 'referer', value => 'foo', mode => 0 }]}); |
522 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
523 | |
524 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
525 is($frame->{headers}->{'x-referer'}, 'foo', 'value with indexing - indexed'); | |
526 | |
527 $sid = new_stream($sess, { headers => [ | |
528 { name => ':method', value => 'GET', mode => 0 }, | |
529 { name => ':scheme', value => 'http', mode => 0 }, | |
530 { name => ':path', value => '/', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
531 { name => ':authority', value => 'localhost', mode => 0 }, |
646 | 532 { name => 'x-foo', value => 'X-Bar', mode => 2 }]}); |
533 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
534 | |
535 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
536 is($frame->{headers}->{'x-sent-foo'}, 'X-Bar', 'name with indexing - new'); | |
537 | |
538 # reuse literal with indexing - reused name | |
539 | |
540 $sid = new_stream($sess, { headers => [ | |
541 { name => ':method', value => 'GET', mode => 0 }, | |
542 { name => ':scheme', value => 'http', mode => 0 }, | |
543 { name => ':path', value => '/', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
544 { name => ':authority', value => 'localhost', mode => 0 }, |
646 | 545 { name => 'x-foo', value => 'X-Bar', mode => 0 }]}); |
546 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
547 | |
548 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
549 is($frame->{headers}->{'x-sent-foo'}, 'X-Bar', 'name with indexing - indexed'); | |
550 | |
551 # 6.3. Dynamic Table Size Update | |
552 | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
553 # remove some indexed headers from the dynamic table |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
554 # by maintaining dynamic table space only for index 0 |
646 | 555 # 'x-foo' has index 0, and 'referer' has index 1 |
556 | |
557 $sid = new_stream($sess, { table_size => 61, headers => [ | |
558 { name => ':method', value => 'GET', mode => 0 }, | |
559 { name => ':scheme', value => 'http', mode => 0 }, | |
560 { name => ':path', value => '/', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
561 { name => 'x-foo', value => 'X-Bar', mode => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
562 { name => ':authority', value => 'localhost', mode => 1 }]}); |
646 | 563 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
564 | |
565 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
566 isnt($frame, undef, 'updated table size - remaining index'); | |
567 | |
568 $sid = new_stream($sess, { headers => [ | |
569 { name => ':method', value => 'GET', mode => 0 }, | |
570 { name => ':scheme', value => 'http', mode => 0 }, | |
571 { name => ':path', value => '/', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
572 { name => ':authority', value => 'localhost', mode => 1 }, |
646 | 573 { name => 'referer', value => 'foo', mode => 0 }]}); |
574 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
575 | |
576 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
672
66f94d6c5047
Tests: more HTTP/2 error handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
671
diff
changeset
|
577 is($frame, undef, 'invalid index'); |
646 | 578 |
579 # 5.4.1. Connection Error Handling | |
580 # An endpoint that encounters a connection error SHOULD first send a | |
581 # GOAWAY frame <..> | |
582 | |
583 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
672
66f94d6c5047
Tests: more HTTP/2 error handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
671
diff
changeset
|
584 ok($frame, 'invalid index - GOAWAY'); |
646 | 585 |
691
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
586 # RFC 7541, 2.3.3. Index Address Space |
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
587 # Indices strictly greater than the sum of the lengths of both tables |
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
588 # MUST be treated as a decoding error. |
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
589 |
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
590 # 4.3. Header Compression and Decompression |
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
591 # A decoding error in a header block MUST be treated |
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
592 # as a connection error of type COMPRESSION_ERROR. |
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
593 |
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
594 is($frame->{last_sid}, $sid, 'invalid index - GOAWAY last stream'); |
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
595 is($frame->{code}, 9, 'invalid index - GOAWAY COMPRESSION_ERROR'); |
3f4a132c6463
Tests: extended HTTP/2 tests for GOAWAY on compression error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
685
diff
changeset
|
596 |
646 | 597 # HEAD |
598 | |
599 $sess = new_session(); | |
600 $sid = new_stream($sess, { method => 'HEAD' }); | |
601 $frames = h2_read($sess, all => [{ sid => $sid, fin => 0x4 }]); | |
602 | |
603 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
604 is($frame->{sid}, $sid, 'HEAD - HEADERS'); | |
605 is($frame->{headers}->{':status'}, 200, 'HEAD - HEADERS status'); | |
606 is($frame->{headers}->{'x-header'}, 'X-Foo', 'HEAD - HEADERS header'); | |
607 | |
608 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
609 is($frame, undef, 'HEAD - no body'); | |
610 | |
611 # GET with PROXY protocol | |
612 | |
613 my $proxy = 'PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678' . CRLF; | |
614 $sess = new_session(8082, proxy => $proxy); | |
615 $sid = new_stream($sess, { path => '/pp' }); | |
616 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
617 | |
618 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
619 ok($frame, 'PROXY HEADERS frame'); | |
620 is($frame->{headers}->{'x-pp'}, '192.0.2.1', 'PROXY remote addr'); | |
621 | |
622 # range filter | |
623 | |
624 $sess = new_session(); | |
625 $sid = new_stream($sess, { headers => [ | |
626 { name => ':method', value => 'GET', mode => 0 }, | |
627 { name => ':scheme', value => 'http', mode => 0 }, | |
628 { name => ':path', value => '/t1.html', mode => 1 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
629 { name => ':authority', value => 'localhost', mode => 1 }, |
646 | 630 { name => 'range', value => 'bytes=10-19', mode => 1 }]}); |
631 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
632 | |
633 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
634 is($frame->{headers}->{':status'}, 206, 'range - HEADERS status'); | |
635 | |
636 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
637 is($frame->{length}, 10, 'range - DATA length'); | |
638 is($frame->{data}, '002XXXX000', 'range - DATA payload'); | |
639 | |
650
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
640 # $http2 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
641 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
642 $sess = new_session(); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
643 $sid = new_stream($sess, { path => '/h2' }); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
644 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
645 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
646 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
647 is($frame->{data}, 'h2c', 'http variable - h2c'); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
648 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
649 # SSL/TLS connection, NPN |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
650 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
651 SKIP: { |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
652 eval { IO::Socket::SSL->can_npn() or die; }; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
653 skip 'OpenSSL NPN support required', 1 if $@; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
654 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
655 $sess = new_session(8084, SSL => 1, npn => 'h2'); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
656 $sid = new_stream($sess, { path => '/h2' }); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
657 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
658 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
659 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
660 is($frame->{data}, 'h2', 'http variable - npn'); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
661 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
662 } |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
663 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
664 # SSL/TLS connection, ALPN |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
665 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
666 SKIP: { |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
667 eval { IO::Socket::SSL->can_alpn() or die; }; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
668 skip 'OpenSSL ALPN support required', 1 if $@; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
669 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
670 $sess = new_session(8084, SSL => 1, alpn => 'h2'); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
671 $sid = new_stream($sess, { path => '/h2' }); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
672 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
673 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
674 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
675 is($frame->{data}, 'h2', 'http variable - alpn'); |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
676 |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
677 } |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
678 |
651
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
679 # http2_chunk_size=1 |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
680 |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
681 $sess = new_session(); |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
682 $sid = new_stream($sess, { path => '/chunk_size' }); |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
683 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
684 |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
685 my @data = grep { $_->{type} eq "DATA" } @$frames; |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
686 is(@data, 4, 'chunk_size frames'); |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
687 is(join(' ', map { $_->{data} } @data), 'b o d y', 'chunk_size data'); |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
688 is(join(' ', map { $_->{flags} } @data), '0 0 0 1', 'chunk_size flags'); |
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
689 |
646 | 690 # CONTINUATION |
691 | |
650
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
692 $sess = new_session(); |
646 | 693 $sid = new_stream($sess, { continuation => 1, headers => [ |
694 { name => ':method', value => 'HEAD', mode => 1 }, | |
695 { name => ':scheme', value => 'http', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
696 { name => ':path', value => '/', mode => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
697 { name => ':authority', value => 'localhost', mode => 1 }]}); |
646 | 698 h2_continue($sess, $sid, { continuation => 1, headers => [ |
699 { name => 'x-foo', value => 'X-Bar', mode => 2 }]}); | |
700 h2_continue($sess, $sid, { headers => [ | |
701 { name => 'referer', value => 'foo', mode => 2 }]}); | |
702 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
703 | |
704 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
705 is($frame, undef, 'CONTINUATION - fragment 1'); | |
706 | |
707 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
708 is($frame->{headers}->{'x-sent-foo'}, 'X-Bar', 'CONTINUATION - fragment 2'); | |
709 is($frame->{headers}->{'x-referer'}, 'foo', 'CONTINUATION - fragment 3'); | |
710 | |
699
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
711 # CONTINUATION - in the middle of request header field |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
712 |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
713 $sess = new_session(); |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
714 $sid = new_stream($sess, { continuation => [ 2, 4, 1, 5 ], headers => [ |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
715 { name => ':method', value => 'HEAD', mode => 1 }, |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
716 { name => ':scheme', value => 'http', mode => 0 }, |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
717 { name => ':path', value => '/', mode => 0 }, |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
718 { name => ':authority', value => 'localhost', mode => 1 }]}); |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
719 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
720 |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
721 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
722 is($frame->{headers}->{':status'}, 200, 'CONTINUATION - in header field'); |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
723 |
646 | 724 # frame padding |
725 | |
726 $sess = new_session(); | |
727 $sid = new_stream($sess, { padding => 42, headers => [ | |
728 { name => ':method', value => 'GET', mode => 0 }, | |
729 { name => ':scheme', value => 'http', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
730 { name => ':path', value => '/', mode => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
731 { name => ':authority', value => 'localhost', mode => 1 }]}); |
646 | 732 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
733 | |
734 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
735 is($frame->{headers}->{':status'}, 200, 'padding - HEADERS status'); | |
736 | |
737 $sid = new_stream($sess, { headers => [ | |
738 { name => ':method', value => 'GET', mode => 0 }, | |
739 { name => ':scheme', value => 'http', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
740 { name => ':path', value => '/', mode => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
741 { name => ':authority', value => 'localhost', mode => 1 }]}); |
646 | 742 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
743 | |
744 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
745 is($frame->{headers}->{':status'}, 200, 'padding - next stream'); | |
746 | |
747 # request header field with multiple values | |
748 | |
749 # 8.1.2.5. Compressing the Cookie Header Field | |
750 # To allow for better compression efficiency, the Cookie header field | |
751 # MAY be split into separate header fields <..>. | |
752 | |
753 $sess = new_session(); | |
754 $sid = new_stream($sess, { headers => [ | |
755 { name => ':method', value => 'GET', mode => 0 }, | |
756 { name => ':scheme', value => 'http', mode => 0 }, | |
757 { name => ':path', value => '/cookie', mode => 2 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
758 { name => ':authority', value => 'localhost', mode => 1 }, |
646 | 759 { name => 'cookie', value => 'a=b', mode => 2}, |
760 { name => 'cookie', value => 'c=d', mode => 2}]}); | |
761 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
762 | |
763 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
764 is($frame->{headers}->{'x-cookie-a'}, 'b', | |
765 'multiple request header fields - cookie'); | |
766 is($frame->{headers}->{'x-cookie-c'}, 'd', | |
767 'multiple request header fields - cookie 2'); | |
768 is($frame->{headers}->{'x-cookie'}, 'a=b; c=d', | |
769 'multiple request header fields - semi-colon'); | |
770 | |
771 # request header field with multiple values to HTTP backend | |
772 | |
773 # 8.1.2.5. Compressing the Cookie Header Field | |
774 # these MUST be concatenated into a single octet string | |
775 # using the two-octet delimiter of 0x3B, 0x20 (the ASCII string "; ") | |
776 # before being passed into a non-HTTP/2 context, such as an HTTP/1.1 | |
777 # connection <..> | |
778 | |
779 $sess = new_session(); | |
780 $sid = new_stream($sess, { headers => [ | |
781 { name => ':method', value => 'GET', mode => 0 }, | |
782 { name => ':scheme', value => 'http', mode => 0 }, | |
783 { name => ':path', value => '/proxy/cookie', mode => 2 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
784 { name => ':authority', value => 'localhost', mode => 1 }, |
646 | 785 { name => 'cookie', value => 'a=b', mode => 2 }, |
786 { name => 'cookie', value => 'c=d', mode => 2 }]}); | |
787 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
788 | |
789 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
652
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
790 is($frame->{headers}->{'x-sent-cookie'}, 'a=b; c=d', |
646 | 791 'multiple request header fields proxied - semi-colon'); |
652
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
792 is($frame->{headers}->{'x-sent-cookie2'}, '', |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
793 'multiple request header fields proxied - dublicate cookie'); |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
794 is($frame->{headers}->{'x-sent-cookie-a'}, 'b', |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
795 'multiple request header fields proxied - cookie 1'); |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
796 is($frame->{headers}->{'x-sent-cookie-c'}, 'd', |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
797 'multiple request header fields proxied - cookie 2'); |
646 | 798 |
799 # response header field with multiple values | |
800 | |
801 $sess = new_session(); | |
802 $sid = new_stream($sess, { path => '/set-cookie' }); | |
803 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
804 | |
805 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
806 is($frame->{headers}->{'set-cookie'}[0], 'a=b', | |
807 'multiple response header fields - cookie'); | |
808 is($frame->{headers}->{'set-cookie'}[1], 'c=d', | |
809 'multiple response header fields - cookie 2'); | |
810 | |
811 # response header field with multiple values from HTTP backend | |
812 | |
813 $sess = new_session(); | |
814 $sid = new_stream($sess, { path => '/proxy/set-cookie' }); | |
815 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
816 | |
817 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
818 is($frame->{headers}->{'set-cookie'}[0], 'a=b', | |
819 'multiple response header proxied - cookie'); | |
820 is($frame->{headers}->{'set-cookie'}[1], 'c=d', | |
821 'multiple response header proxied - cookie 2'); | |
822 is($frame->{headers}->{'x-uc-a'}, 'b', | |
823 'multiple response header proxied - upstream cookie'); | |
824 is($frame->{headers}->{'x-uc-c'}, 'd', | |
825 'multiple response header proxied - upstream cookie 2'); | |
826 | |
827 # internal redirect | |
828 | |
829 $sess = new_session(); | |
830 $sid = new_stream($sess, { path => '/redirect' }); | |
831 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
832 | |
833 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
834 is($frame->{headers}->{':status'}, 405, 'redirect - HEADERS'); | |
835 | |
836 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
837 ok($frame, 'redirect - DATA'); | |
838 is($frame->{data}, 'body', 'redirect - DATA payload'); | |
839 | |
840 # return 301 with absolute URI | |
841 | |
842 $sess = new_session(); | |
843 $sid = new_stream($sess, { path => '/return301_absolute' }); | |
844 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
845 | |
846 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
847 is($frame->{headers}->{':status'}, 301, 'return 301 absolute - status'); | |
848 is($frame->{headers}->{'location'}, 'text', 'return 301 absolute - location'); | |
849 | |
850 # return 301 with relative URI | |
851 | |
852 $sess = new_session(); | |
853 $sid = new_stream($sess, { path => '/return301_relative' }); | |
854 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
855 | |
856 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
857 is($frame->{headers}->{':status'}, 301, 'return 301 relative - status'); | |
858 is($frame->{headers}->{'location'}, 'http://127.0.0.1:8080/', | |
859 'return 301 relative - location'); | |
860 | |
861 # return 301 with relative URI and ':authority' request header field | |
862 | |
863 $sess = new_session(); | |
864 $sid = new_stream($sess, { headers => [ | |
865 { name => ':method', value => 'GET', mode => 0 }, | |
866 { name => ':scheme', value => 'http', mode => 0 }, | |
867 { name => ':path', value => '/return301_relative', mode => 2 }, | |
868 { name => ':authority', value => 'localhost', mode => 2 }]}); | |
869 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
870 | |
871 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
872 is($frame->{headers}->{':status'}, 301, | |
873 'return 301 relative - authority - status'); | |
874 is($frame->{headers}->{'location'}, 'http://localhost:8080/', | |
875 'return 301 relative - authority - location'); | |
876 | |
877 # return 301 with relative URI and 'host' request header field | |
878 | |
879 $sess = new_session(); | |
880 $sid = new_stream($sess, { headers => [ | |
881 { name => ':method', value => 'GET', mode => 0 }, | |
882 { name => ':scheme', value => 'http', mode => 0 }, | |
883 { name => ':path', value => '/return301_relative', mode => 2 }, | |
884 { name => 'host', value => 'localhost', mode => 2 }]}); | |
885 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
886 | |
887 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
888 is($frame->{headers}->{':status'}, 301, | |
889 'return 301 relative - host - status'); | |
890 is($frame->{headers}->{'location'}, 'http://localhost:8080/', | |
891 'return 301 relative - host - location'); | |
892 | |
893 # virtual host | |
894 | |
895 $sess = new_session(8085); | |
896 $sid = new_stream($sess, { headers => [ | |
897 { name => ':method', value => 'GET', mode => 0 }, | |
898 { name => ':scheme', value => 'http', mode => 0 }, | |
899 { name => ':path', value => '/', mode => 0 }, | |
900 { name => 'host', value => 'localhost', mode => 2 }]}); | |
901 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
902 | |
903 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
904 is($frame->{headers}->{':status'}, 200, | |
905 'virtual host - host - status'); | |
906 | |
907 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
908 is($frame->{data}, 'first', 'virtual host - host - DATA'); | |
909 | |
910 $sid = new_stream($sess, { headers => [ | |
911 { name => ':method', value => 'GET', mode => 0 }, | |
912 { name => ':scheme', value => 'http', mode => 0 }, | |
913 { name => ':path', value => '/', mode => 0 }, | |
914 { name => ':authority', value => 'localhost', mode => 2 }]}); | |
915 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
916 | |
917 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
918 is($frame->{headers}->{':status'}, 200, | |
919 'virtual host - authority - status'); | |
920 | |
921 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
922 is($frame->{data}, 'first', 'virtual host - authority - DATA'); | |
923 | |
924 # virtual host - second | |
925 | |
926 $sid = new_stream($sess, { headers => [ | |
927 { name => ':method', value => 'GET', mode => 0 }, | |
928 { name => ':scheme', value => 'http', mode => 0 }, | |
929 { name => ':path', value => '/', mode => 0 }, | |
930 { name => 'host', value => 'localhost2', mode => 2 }]}); | |
931 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
932 | |
933 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
934 is($frame->{headers}->{':status'}, 200, | |
935 'virtual host 2 - host - status'); | |
936 | |
937 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
938 is($frame->{data}, 'second', 'virtual host 2 - host - DATA'); | |
939 | |
940 $sid = new_stream($sess, { headers => [ | |
941 { name => ':method', value => 'GET', mode => 0 }, | |
942 { name => ':scheme', value => 'http', mode => 0 }, | |
943 { name => ':path', value => '/', mode => 0 }, | |
944 { name => ':authority', value => 'localhost2', mode => 2 }]}); | |
945 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
946 | |
947 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
948 is($frame->{headers}->{':status'}, 200, | |
949 'virtual host 2 - authority - status'); | |
950 | |
951 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
952 is($frame->{data}, 'second', 'virtual host 2 - authority - DATA'); | |
953 | |
954 # gzip tests for internal nginx version | |
955 | |
956 $sess = new_session(); | |
957 $sid = new_stream($sess, { headers => [ | |
958 { name => ':method', value => 'GET', mode => 0 }, | |
959 { name => ':scheme', value => 'http', mode => 0 }, | |
960 { name => ':path', value => '/gzip.html' }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
961 { name => ':authority', value => 'localhost', mode => 1 }, |
646 | 962 { name => 'accept-encoding', value => 'gzip' }]}); |
963 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
964 | |
965 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
966 is($frame->{headers}->{'content-encoding'}, 'gzip', 'gzip - encoding'); | |
967 | |
968 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
647
4e36550410b3
Tests: h2.t fixes for older perl versions, and gzip test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
646
diff
changeset
|
969 gunzip_like($frame->{data}, qr/^SEE-THIS\Z/, 'gzip - DATA'); |
646 | 970 |
971 # simple proxy cache test | |
972 | |
973 $sess = new_session(); | |
974 $sid = new_stream($sess, { path => '/proxy2/t2.html?2' }); | |
975 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
976 | |
977 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
978 is($frame->{headers}->{':status'}, '200', 'proxy cache'); | |
979 | |
980 my $etag = $frame->{headers}->{'etag'}; | |
981 | |
982 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
983 is($frame->{length}, length 'SEE-THIS', 'proxy cache - DATA'); | |
984 is($frame->{data}, 'SEE-THIS', 'proxy cache - DATA payload'); | |
985 | |
986 $sid = new_stream($sess, { headers => [ | |
987 { name => ':method', value => 'GET', mode => 0 }, | |
988 { name => ':scheme', value => 'http', mode => 0 }, | |
989 { name => ':path', value => '/proxy2/t2.html?2' }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
990 { name => ':authority', value => 'localhost', mode => 1 }, |
646 | 991 { name => 'if-none-match', value => $etag }]}); |
992 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
993 | |
994 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
995 is($frame->{headers}->{':status'}, 304, 'proxy cache conditional'); | |
996 | |
997 # HEADERS could be received with fin, followed by DATA | |
998 | |
999 $sess = new_session(); | |
1000 $sid = new_stream($sess, { path => '/proxy2/t2.html', method => 'HEAD' }); | |
1001 | |
1002 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1003 push @$frames, $_ for @{h2_read($sess, all => [{ sid => $sid }])}; | |
1004 ok(!grep ({ $_->{type} eq "DATA" } @$frames), 'proxy cache HEAD - no body'); | |
1005 | |
1006 # HEAD on empty cache with proxy_buffering off | |
1007 | |
1008 $sess = new_session(); | |
1009 $sid = new_stream($sess, | |
1010 { path => '/proxy_buffering_off/t2.html?1', method => 'HEAD' }); | |
1011 | |
1012 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1013 push @$frames, $_ for @{h2_read($sess, all => [{ sid => $sid }])}; | |
1014 ok(!grep ({ $_->{type} eq "DATA" } @$frames), | |
1015 'proxy cache HEAD buffering off - no body'); | |
1016 | |
1017 # request body (uses proxied response) | |
1018 | |
1019 $sess = new_session(); | |
1020 $sid = new_stream($sess, { path => '/proxy2/t2.html', body => 'TEST' }); | |
1021 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1022 | |
1023 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1024 is($frame->{headers}->{'x-body'}, 'TEST', 'request body'); | |
1025 | |
1026 # request body with padding (uses proxied response) | |
1027 | |
1028 $sess = new_session(); | |
1029 $sid = new_stream($sess, | |
1030 { path => '/proxy2/t2.html', body => 'TEST', body_padding => 42 }); | |
1031 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1032 | |
1033 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1034 is($frame->{headers}->{'x-body'}, 'TEST', 'request body with padding'); | |
1035 | |
1036 $sid = new_stream($sess); | |
1037 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1038 | |
1039 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1040 is($frame->{headers}->{':status'}, '200', 'request body with padding - next'); | |
1041 | |
1042 # initial window size, client side | |
1043 | |
1044 # 6.9.2. Initial Flow-Control Window Size | |
1045 # When an HTTP/2 connection is first established, new streams are | |
1046 # created with an initial flow-control window size of 65,535 octets. | |
1047 # The connection flow-control window is also 65,535 octets. | |
1048 | |
1049 $sess = new_session(); | |
1050 $sid = new_stream($sess, { path => '/t1.html' }); | |
1051 $frames = h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1052 | |
1053 # with the default http2_chunk_size, data is divided into 8 data frames | |
1054 | |
651
9f66f0029dca
Tests: HTTP/2 tests for http2_chunk_size directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
650
diff
changeset
|
1055 @data = grep { $_->{type} eq "DATA" } @$frames; |
646 | 1056 my $lengths = join ' ', map { $_->{length} } @data; |
1057 is($lengths, '8192 8192 8192 8192 8192 8192 8192 8191', | |
1058 'iws - stream blocked on initial window size'); | |
1059 | |
1060 h2_ping($sess, 'SEE-THIS'); | |
1061 $frames = h2_read($sess, all => [{ type => 'PING' }]); | |
1062 | |
1063 ($frame) = grep { $_->{type} eq "PING" && $_->{flags} & 0x1 } @$frames; | |
1064 ok($frame, 'iws - PING not blocked'); | |
1065 | |
1066 h2_window($sess, 2**16, $sid); | |
1067 $frames = h2_read($sess); | |
1068 is(@$frames, 0, 'iws - updated stream window'); | |
1069 | |
1070 h2_window($sess, 2**16); | |
1071 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1072 | |
1073 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1074 my $sum = eval join '+', map { $_->{length} } @data; | |
1075 is($sum, 81, 'iws - updated connection window'); | |
1076 | |
1077 # SETTINGS (initial window size, client side) | |
1078 | |
1079 # 6.9.2. Initial Flow-Control Window Size | |
1080 # Both endpoints can adjust the initial window size for new streams by | |
1081 # including a value for SETTINGS_INITIAL_WINDOW_SIZE in the SETTINGS | |
1082 # frame that forms part of the connection preface. The connection | |
1083 # flow-control window can only be changed using WINDOW_UPDATE frames. | |
1084 | |
1085 $sess = new_session(); | |
1086 h2_settings($sess, 0, 0x4 => 2**17); | |
1087 h2_window($sess, 2**17); | |
1088 | |
1089 $sid = new_stream($sess, { path => '/t1.html' }); | |
1090 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1091 | |
1092 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1093 $sum = eval join '+', map { $_->{length} } @data; | |
1094 is($sum, 2**16 + 80, 'iws - increased'); | |
1095 | |
1096 # probe for negative available space in a flow control window | |
1097 | |
1098 # 6.9.2. Initial Flow-Control Window Size | |
1099 # A change to SETTINGS_INITIAL_WINDOW_SIZE can cause the available | |
1100 # space in a flow-control window to become negative. A sender MUST | |
1101 # track the negative flow-control window and MUST NOT send new flow- | |
1102 # controlled frames until it receives WINDOW_UPDATE frames that cause | |
1103 # the flow-control window to become positive. | |
1104 | |
1105 $sess = new_session(); | |
1106 $sid = new_stream($sess, { path => '/t1.html' }); | |
1107 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1108 | |
1109 h2_window($sess, 1); | |
1110 h2_settings($sess, 0, 0x4 => 42); | |
1111 h2_window($sess, 1024, $sid); | |
1112 | |
1113 $frames = h2_read($sess, all => [{ type => 'SETTINGS' }]); | |
1114 | |
1115 ($frame) = grep { $_->{type} eq 'SETTINGS' } @$frames; | |
1116 ok($frame, 'negative window - SETTINGS frame ack'); | |
1117 is($frame->{flags}, 1, 'negative window - SETTINGS flags ack'); | |
1118 | |
1119 ($frame) = grep { $_->{type} ne 'SETTINGS' } @$frames; | |
1120 is($frame, undef, 'negative window - no data'); | |
1121 | |
1122 # predefined window size, minus new iws settings, minus window update | |
1123 | |
1124 h2_window($sess, 2**16 - 1 - 42 - 1024, $sid); | |
1125 | |
1126 $frames = h2_read($sess); | |
1127 is(@$frames, 0, 'zero window - no data'); | |
1128 | |
1129 h2_window($sess, 1, $sid); | |
1130 | |
1131 $frames = h2_read($sess, all => [{ sid => $sid, length => 1 }]); | |
1132 is(@$frames, 1, 'positive window'); | |
712
649af6069976
Tests: skipped some HTTP/2 tests is case of a failed connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
707
diff
changeset
|
1133 |
649af6069976
Tests: skipped some HTTP/2 tests is case of a failed connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
707
diff
changeset
|
1134 SKIP: { |
649af6069976
Tests: skipped some HTTP/2 tests is case of a failed connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
707
diff
changeset
|
1135 skip 'failed connection', 2 unless @$frames; |
649af6069976
Tests: skipped some HTTP/2 tests is case of a failed connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
707
diff
changeset
|
1136 |
646 | 1137 is(@$frames[0]->{type}, 'DATA', 'positive window - data'); |
1138 is(@$frames[0]->{length}, 1, 'positive window - data length'); | |
1139 | |
712
649af6069976
Tests: skipped some HTTP/2 tests is case of a failed connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
707
diff
changeset
|
1140 } |
649af6069976
Tests: skipped some HTTP/2 tests is case of a failed connection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
707
diff
changeset
|
1141 |
704
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1142 # ask write handler in sending large response |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1143 |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1144 $sid = new_stream($sess, { path => '/tbig.html' }); |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1145 |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1146 h2_window($sess, 2**30, $sid); |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1147 h2_window($sess, 2**30); |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1148 |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1149 sleep 1; |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1150 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1151 |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1152 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1153 is($frame->{headers}->{':status'}, 200, 'large response - HEADERS'); |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1154 |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1155 @data = grep { $_->{type} eq "DATA" } @$frames; |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1156 $sum = eval join '+', map { $_->{length} } @data; |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1157 is($sum, 1000000, 'large response - DATA'); |
626bc3a0fdaa
Tests: SPDY and HTTP/2 write handler tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
702
diff
changeset
|
1158 |
680
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1159 # SETTINGS_MAX_FRAME_SIZE |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1160 |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1161 $sess = new_session(); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1162 $sid = new_stream($sess, { path => '/frame_size' }); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1163 h2_window($sess, 2**18, 1); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1164 h2_window($sess, 2**18); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1165 |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1166 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1167 @data = grep { $_->{type} eq "DATA" } @$frames; |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1168 is($data[0]->{length}, 2**14, 'max frame size - default'); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1169 |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1170 $sess = new_session(); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1171 h2_settings($sess, 0, 0x5 => 2**15); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1172 $sid = new_stream($sess, { path => '/frame_size' }); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1173 h2_window($sess, 2**18, 1); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1174 h2_window($sess, 2**18); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1175 |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1176 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1177 @data = grep { $_->{type} eq "DATA" } @$frames; |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1178 is($data[0]->{length}, 2**15, 'max frame size - custom'); |
85e368105c8b
Tests: added HTTP/2 tests for SETTINGS_MAX_FRAME_SIZE.
Sergey Kandaurov <pluknet@nginx.com>
parents:
679
diff
changeset
|
1179 |
696
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1180 # CONTINUATION in response |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1181 # put three long header fields (not less than SETTINGS_MAX_FRAME_SIZE/2) |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1182 # to break header block into separate frames, one such field per frame |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1183 |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1184 $sess = new_session(); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1185 $sid = new_stream($sess, { path => '/continuation?h=' . 'x' x 2**13 }); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1186 |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1187 $frames = h2_read($sess, all => [{ sid => $sid, fin => 0x4 }]); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1188 @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1189 is(@data, 3, 'response CONTINUATION - header block frames'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1190 is($data[0]->{type}, 'HEADERS', 'response CONTINUATION - first'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1191 is($data[0]->{flags}, 0, 'response CONTINUATION - first flags'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1192 is($data[1]->{type}, 'CONTINUATION', 'response CONTINUATION - second'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1193 is($data[1]->{flags}, 0, 'response CONTINUATION - second flags'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1194 is($data[2]->{type}, 'CONTINUATION', 'response CONTINUATION - third'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1195 is($data[2]->{flags}, 4, 'response CONTINUATION - third flags'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1196 |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1197 # same but without response DATA frames |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1198 |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1199 $sess = new_session(); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1200 $sid = new_stream($sess, { path => '/continuation/204?h=' . 'x' x 2**13 }); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1201 |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1202 $frames = h2_read($sess, all => [{ sid => $sid, fin => 0x4 }]); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1203 @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1204 is(@data, 3, 'no body CONTINUATION - header block frames'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1205 is($data[0]->{type}, 'HEADERS', 'no body CONTINUATION - first'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1206 is($data[0]->{flags}, 1, 'no body CONTINUATION - first flags'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1207 is($data[1]->{type}, 'CONTINUATION', 'no body CONTINUATION - second'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1208 is($data[1]->{flags}, 0, 'no body CONTINUATION - second flags'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1209 is($data[2]->{type}, 'CONTINUATION', 'no body CONTINUATION - third'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1210 is($data[2]->{flags}, 4, 'no body CONTINUATION - third flags'); |
beab9da9b731
Tests: added HTTP/2 tests for CONTINUATION frame in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
694
diff
changeset
|
1211 |
698
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1212 # response header block is always split by SETTINGS_MAX_FRAME_SIZE |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1213 |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1214 TODO: { |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1215 local $TODO = 'not yet'; |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1216 |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1217 $sess = new_session(); |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1218 $sid = new_stream($sess, { path => '/continuation?h=' . 'x' x 2**14 }); |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1219 |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1220 $frames = h2_read($sess, all => [{ sid => $sid, fin => 0x4 }]); |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1221 @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1222 @data = sort { $a <=> $b } map { $_->{length} } @data; |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1223 cmp_ok($data[-1], '<=', 2**14, 'response header frames limited'); |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1224 |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1225 } |
f86c8314d205
Tests: one more HTTP/2 test for max frame size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
697
diff
changeset
|
1226 |
684
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1227 # max_field_size |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1228 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1229 $sess = new_session(8087); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1230 $sid = new_stream($sess, { headers => [ |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1231 { name => ':method', value => 'GET', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1232 { name => ':scheme', value => 'http', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1233 { name => ':path', value => '/t2.html', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1234 { name => ':authority', value => 'localhost', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1235 { name => 'longname10', value => 'valu5' x 4 . 'x', mode => 2 }]}); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1236 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1237 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1238 ($frame) = grep { $_->{type} eq 'DATA' } @$frames; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1239 ok($frame, 'field size less'); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1240 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1241 $sid = new_stream($sess, { headers => [ |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1242 { name => ':method', value => 'GET', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1243 { name => ':scheme', value => 'http', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1244 { name => ':path', value => '/t2.html', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1245 { name => ':authority', value => 'localhost', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1246 { name => 'longname10', value => 'valu5' x 4 . 'x', mode => 2 }]}); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1247 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1248 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1249 ($frame) = grep { $_->{type} eq 'DATA' } @$frames; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1250 ok($frame, 'field size second'); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1251 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1252 $sess = new_session(8087); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1253 $sid = new_stream($sess, { headers => [ |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1254 { name => ':method', value => 'GET', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1255 { name => ':scheme', value => 'http', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1256 { name => ':path', value => '/t2.html', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1257 { name => ':authority', value => 'localhost', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1258 { name => 'longname10', value => 'valu5' x 4 . 'xx', mode => 2 }]}); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1259 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1260 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1261 ($frame) = grep { $_->{type} eq 'DATA' } @$frames; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1262 ok($frame, 'field size equal'); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1263 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1264 $sess = new_session(8087); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1265 $sid = new_stream($sess, { headers => [ |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1266 { name => ':method', value => 'GET', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1267 { name => ':scheme', value => 'http', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1268 { name => ':path', value => '/t2.html', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1269 { name => ':authority', value => 'localhost', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1270 { name => 'longname10', value => 'valu5' x 4 . 'xxx', mode => 2 }]}); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1271 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1272 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1273 ($frame) = grep { $_->{type} eq 'DATA' } @$frames; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1274 is($frame, undef, 'field size greater'); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1275 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1276 # max_header_size |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1277 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1278 $sess = new_session(8088); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1279 $sid = new_stream($sess, { headers => [ |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1280 { name => ':method', value => 'GET', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1281 { name => ':scheme', value => 'http', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1282 { name => ':path', value => '/t2.html', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1283 { name => ':authority', value => 'localhost', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1284 { name => 'longname9', value => 'x', mode => 2 }]}); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1285 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1286 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1287 ($frame) = grep { $_->{type} eq 'DATA' } @$frames; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1288 ok($frame, 'header size less'); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1289 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1290 $sid = new_stream($sess, { headers => [ |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1291 { name => ':method', value => 'GET', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1292 { name => ':scheme', value => 'http', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1293 { name => ':path', value => '/t2.html', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1294 { name => ':authority', value => 'localhost', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1295 { name => 'longname9', value => 'x', mode => 2 }]}); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1296 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1297 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1298 ($frame) = grep { $_->{type} eq 'DATA' } @$frames; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1299 ok($frame, 'header size second'); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1300 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1301 $sess = new_session(8088); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1302 $sid = new_stream($sess, { headers => [ |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1303 { name => ':method', value => 'GET', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1304 { name => ':scheme', value => 'http', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1305 { name => ':path', value => '/t2.html', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1306 { name => ':authority', value => 'localhost', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1307 { name => 'longname9', value => 'xx', mode => 2 }]}); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1308 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1309 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1310 ($frame) = grep { $_->{type} eq 'DATA' } @$frames; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1311 ok($frame, 'header size equal'); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1312 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1313 $sess = new_session(8088); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1314 $sid = new_stream($sess, { headers => [ |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1315 { name => ':method', value => 'GET', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1316 { name => ':scheme', value => 'http', mode => 0 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1317 { name => ':path', value => '/t2.html', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1318 { name => ':authority', value => 'localhost', mode => 1 }, |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1319 { name => 'longname9', value => 'xxx', mode => 2 }]}); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1320 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1321 |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1322 ($frame) = grep { $_->{type} eq 'DATA' } @$frames; |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1323 is($frame, undef, 'header size greater'); |
96666f621dbc
Tests: added http2_max_field_size and http2_max_header_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
680
diff
changeset
|
1324 |
646 | 1325 # stream multiplexing + WINDOW_UPDATE |
1326 | |
1327 $sess = new_session(); | |
1328 $sid = new_stream($sess, { path => '/t1.html' }); | |
1329 $frames = h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1330 | |
1331 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1332 $sum = eval join '+', map { $_->{length} } @data; | |
1333 is($sum, 2**16 - 1, 'multiple - stream1 data'); | |
1334 | |
1335 my $sid2 = new_stream($sess, { path => '/t1.html' }); | |
1336 $frames = h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); | |
1337 | |
1338 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1339 is(@data, 0, 'multiple - stream2 no data'); | |
1340 | |
1341 h2_window($sess, 2**17, $sid); | |
1342 h2_window($sess, 2**17, $sid2); | |
1343 h2_window($sess, 2**17); | |
1344 | |
1345 $frames = h2_read($sess, all => [ | |
1346 { sid => $sid, fin => 1 }, | |
1347 { sid => $sid2, fin => 1 } | |
1348 ]); | |
1349 | |
1350 @data = grep { $_->{type} eq "DATA" && $_->{sid} == $sid } @$frames; | |
1351 $sum = eval join '+', map { $_->{length} } @data; | |
1352 is($sum, 81, 'multiple - stream1 remain data'); | |
1353 | |
1354 @data = grep { $_->{type} eq "DATA" && $_->{sid} == $sid2 } @$frames; | |
1355 $sum = eval join '+', map { $_->{length} } @data; | |
1356 is($sum, 2**16 + 80, 'multiple - stream2 full data'); | |
1357 | |
1358 # stream muliplexing + PRIORITY frames | |
1359 | |
1360 $sess = new_session(); | |
1361 $sid = new_stream($sess, { path => '/t1.html' }); | |
1362 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1363 | |
1364 $sid2 = new_stream($sess, { path => '/t2.html' }); | |
1365 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); | |
1366 | |
1367 h2_priority($sess, 0, $sid); | |
1368 h2_priority($sess, 255, $sid2); | |
1369 | |
1370 h2_window($sess, 2**17, $sid); | |
1371 h2_window($sess, 2**17, $sid2); | |
1372 h2_window($sess, 2**17); | |
1373 | |
1374 $frames = h2_read($sess, all => [ | |
1375 { sid => $sid, fin => 1 }, | |
1376 { sid => $sid2, fin => 1 } | |
1377 ]); | |
1378 | |
1379 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1380 is(join(' ', map { $_->{sid} } @data), "$sid2 $sid", 'weight - PRIORITY 1'); | |
1381 | |
1382 # and vice versa | |
1383 | |
1384 $sess = new_session(); | |
1385 $sid = new_stream($sess, { path => '/t1.html' }); | |
1386 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1387 | |
1388 $sid2 = new_stream($sess, { path => '/t2.html' }); | |
1389 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); | |
1390 | |
1391 h2_priority($sess, 255, $sid); | |
1392 h2_priority($sess, 0, $sid2); | |
1393 | |
1394 h2_window($sess, 2**17, $sid); | |
1395 h2_window($sess, 2**17, $sid2); | |
1396 h2_window($sess, 2**17); | |
1397 | |
1398 $frames = h2_read($sess, all => [ | |
1399 { sid => $sid, fin => 1 }, | |
1400 { sid => $sid2, fin => 1 } | |
1401 ]); | |
1402 | |
1403 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1404 is(join(' ', map { $_->{sid} } @data), "$sid $sid2", 'weight - PRIORITY 2'); | |
1405 | |
1406 # stream muliplexing + HEADERS PRIORITY flag | |
1407 | |
1408 $sess = new_session(); | |
1409 $sid = new_stream($sess, { path => '/t1.html', prio => 0 }); | |
1410 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1411 | |
1412 $sid2 = new_stream($sess, { path => '/t2.html', prio => 255 }); | |
1413 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); | |
1414 | |
1415 h2_window($sess, 2**17, $sid); | |
1416 h2_window($sess, 2**17, $sid2); | |
1417 h2_window($sess, 2**17); | |
1418 | |
1419 $frames = h2_read($sess, all => [ | |
1420 { sid => $sid, fin => 1 }, | |
1421 { sid => $sid2, fin => 1 } | |
1422 ]); | |
1423 | |
1424 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1425 my $sids = join ' ', map { $_->{sid} } @data; | |
1426 is($sids, "$sid2 $sid", 'weight - HEADERS PRIORITY 1'); | |
1427 | |
1428 # and vice versa | |
1429 | |
1430 $sess = new_session(); | |
1431 $sid = new_stream($sess, { path => '/t1.html', prio => 255 }); | |
1432 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1433 | |
1434 $sid2 = new_stream($sess, { path => '/t2.html', prio => 0 }); | |
1435 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); | |
1436 | |
1437 h2_window($sess, 2**17, $sid); | |
1438 h2_window($sess, 2**17, $sid2); | |
1439 h2_window($sess, 2**17); | |
1440 | |
1441 $frames = h2_read($sess, all => [ | |
1442 { sid => $sid, fin => 1 }, | |
1443 { sid => $sid2, fin => 1 } | |
1444 ]); | |
1445 | |
1446 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1447 $sids = join ' ', map { $_->{sid} } @data; | |
1448 is($sids, "$sid $sid2", 'weight - HEADERS PRIORITY 2'); | |
1449 | |
1450 # 5.3.1. Stream Dependencies | |
1451 | |
1452 # PRIORITY frame | |
1453 | |
1454 $sess = new_session(); | |
1455 | |
1456 h2_priority($sess, 16, 3, 0); | |
1457 h2_priority($sess, 16, 1, 3); | |
1458 | |
1459 $sid = new_stream($sess, { path => '/t1.html' }); | |
1460 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1461 | |
1462 $sid2 = new_stream($sess, { path => '/t2.html' }); | |
1463 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); | |
1464 | |
1465 h2_window($sess, 2**17, $sid); | |
1466 h2_window($sess, 2**17, $sid2); | |
1467 h2_window($sess, 2**17); | |
1468 | |
1469 $frames = h2_read($sess, all => [ | |
1470 { sid => $sid, fin => 1 }, | |
1471 { sid => $sid2, fin => 1 }, | |
1472 ]); | |
1473 | |
1474 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1475 $sids = join ' ', map { $_->{sid} } @data; | |
1476 is($sids, "$sid2 $sid", 'dependency - PRIORITY 1'); | |
1477 | |
1478 # and vice versa | |
1479 | |
1480 $sess = new_session(); | |
1481 | |
1482 h2_priority($sess, 16, 1, 0); | |
1483 h2_priority($sess, 16, 3, 1); | |
1484 | |
1485 $sid = new_stream($sess, { path => '/t1.html' }); | |
1486 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1487 | |
1488 $sid2 = new_stream($sess, { path => '/t2.html' }); | |
1489 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); | |
1490 | |
1491 h2_window($sess, 2**17, $sid); | |
1492 h2_window($sess, 2**17, $sid2); | |
1493 h2_window($sess, 2**17); | |
1494 | |
1495 $frames = h2_read($sess, all => [ | |
1496 { sid => $sid, fin => 1 }, | |
1497 { sid => $sid2, fin => 1 }, | |
1498 ]); | |
1499 | |
1500 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1501 $sids = join ' ', map { $_->{sid} } @data; | |
1502 is($sids, "$sid $sid2", 'dependency - PRIORITY 2'); | |
1503 | |
1504 # HEADERS PRIORITY flag, reprioritize prior PRIORITY frame records | |
1505 | |
1506 $sess = new_session(); | |
1507 | |
1508 h2_priority($sess, 16, 1, 0); | |
1509 h2_priority($sess, 16, 3, 0); | |
1510 | |
1511 $sid = new_stream($sess, { path => '/t1.html', dep => 3 }); | |
1512 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1513 | |
1514 $sid2 = new_stream($sess, { path => '/t2.html' }); | |
1515 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); | |
1516 | |
1517 h2_window($sess, 2**17, $sid); | |
1518 h2_window($sess, 2**17, $sid2); | |
1519 h2_window($sess, 2**17); | |
1520 | |
1521 $frames = h2_read($sess, all => [ | |
1522 { sid => $sid, fin => 1 }, | |
1523 { sid => $sid2, fin => 1 }, | |
1524 ]); | |
1525 | |
1526 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1527 $sids = join ' ', map { $_->{sid} } @data; | |
1528 is($sids, "$sid2 $sid", 'dependency - HEADERS PRIORITY 1'); | |
1529 | |
1530 # and vice versa | |
1531 | |
1532 $sess = new_session(); | |
1533 | |
1534 h2_priority($sess, 16, 1, 0); | |
1535 h2_priority($sess, 16, 3, 0); | |
1536 | |
1537 $sid = new_stream($sess, { path => '/t1.html' }); | |
1538 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1539 | |
1540 $sid2 = new_stream($sess, { path => '/t2.html', dep => 1 }); | |
1541 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); | |
1542 | |
1543 h2_window($sess, 2**17, $sid); | |
1544 h2_window($sess, 2**17, $sid2); | |
1545 h2_window($sess, 2**17); | |
1546 | |
1547 $frames = h2_read($sess, all => [ | |
1548 { sid => $sid, fin => 1 }, | |
1549 { sid => $sid2, fin => 1 }, | |
1550 ]); | |
1551 | |
1552 @data = grep { $_->{type} eq "DATA" } @$frames; | |
1553 $sids = join ' ', map { $_->{sid} } @data; | |
1554 is($sids, "$sid $sid2", 'dependency - HEADERS PRIORITY 2'); | |
1555 | |
662
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1556 # PRIORITY frame, weighted dependencies |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1557 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1558 $sess = new_session(); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1559 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1560 h2_priority($sess, 16, 5, 0); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1561 h2_priority($sess, 255, 1, 5); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1562 h2_priority($sess, 0, 3, 5); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1563 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1564 $sid = new_stream($sess, { path => '/t1.html' }); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1565 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1566 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1567 $sid2 = new_stream($sess, { path => '/t2.html' }); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1568 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1569 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1570 my $sid3 = new_stream($sess, { path => '/t2.html' }); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1571 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1572 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1573 h2_window($sess, 2**16, 1); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1574 h2_window($sess, 2**16, 3); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1575 h2_window($sess, 2**16, 5); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1576 h2_window($sess, 2**16); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1577 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1578 $frames = h2_read($sess, all => [ |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1579 { sid => $sid, fin => 1 }, |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1580 { sid => $sid2, fin => 1 }, |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1581 { sid => $sid3, fin => 1 }, |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1582 ]); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1583 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1584 @data = grep { $_->{type} eq "DATA" } @$frames; |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1585 $sids = join ' ', map { $_->{sid} } @data; |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1586 is($sids, "$sid3 $sid $sid2", 'weighted dependency - PRIORITY 1'); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1587 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1588 # and vice versa |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1589 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1590 $sess = new_session(); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1591 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1592 h2_priority($sess, 16, 5, 0); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1593 h2_priority($sess, 0, 1, 5); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1594 h2_priority($sess, 255, 3, 5); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1595 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1596 $sid = new_stream($sess, { path => '/t1.html' }); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1597 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1598 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1599 $sid2 = new_stream($sess, { path => '/t2.html' }); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1600 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1601 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1602 $sid3 = new_stream($sess, { path => '/t2.html' }); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1603 h2_read($sess, all => [{ sid => $sid2, fin => 0x4 }]); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1604 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1605 h2_window($sess, 2**16, 1); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1606 h2_window($sess, 2**16, 3); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1607 h2_window($sess, 2**16, 5); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1608 h2_window($sess, 2**16); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1609 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1610 $frames = h2_read($sess, all => [ |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1611 { sid => $sid, fin => 1 }, |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1612 { sid => $sid2, fin => 1 }, |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1613 { sid => $sid3, fin => 1 }, |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1614 ]); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1615 |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1616 @data = grep { $_->{type} eq "DATA" } @$frames; |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1617 $sids = join ' ', map { $_->{sid} } @data; |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1618 is($sids, "$sid3 $sid2 $sid", 'weighted dependency - PRIORITY 2'); |
07de3d202eb7
Tests: more HTTP/2 tests for streams priority.
Sergey Kandaurov <pluknet@nginx.com>
parents:
661
diff
changeset
|
1619 |
646 | 1620 # limit_conn |
1621 | |
1622 $sess = new_session(); | |
1623 h2_settings($sess, 0, 0x4 => 1); | |
1624 | |
1625 $sid = new_stream($sess, { path => '/t3.html' }); | |
1626 $frames = h2_read($sess, all => [{ sid => $sid, length => 1 }]); | |
1627 | |
1628 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames; | |
1629 is($frame->{headers}->{':status'}, 200, 'limit_conn first stream'); | |
1630 | |
1631 $sid2 = new_stream($sess, { path => '/t3.html' }); | |
1632 $frames = h2_read($sess, all => [{ sid => $sid2, fin => 0 }]); | |
1633 | |
1634 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames; | |
1635 is($frame->{headers}->{':status'}, 503, 'limit_conn rejected'); | |
1636 | |
1637 h2_settings($sess, 0, 0x4 => 2**16); | |
1638 | |
1639 h2_read($sess, all => [ | |
1640 { sid => $sid, fin => 1 }, | |
1641 { sid => $sid2, fin => 1 } | |
1642 ]); | |
1643 | |
1644 # limit_conn + client's RST_STREAM | |
1645 | |
1646 $sess = new_session(); | |
1647 h2_settings($sess, 0, 0x4 => 1); | |
1648 | |
1649 $sid = new_stream($sess, { path => '/t3.html' }); | |
1650 $frames = h2_read($sess, all => [{ sid => $sid, length => 1 }]); | |
1651 h2_rst($sess, $sid, 5); | |
1652 | |
1653 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames; | |
1654 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 1'); | |
1655 | |
1656 $sid2 = new_stream($sess, { path => '/t3.html' }); | |
1657 $frames = h2_read($sess, all => [{ sid => $sid2, fin => 0 }]); | |
1658 | |
1659 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames; | |
1660 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 2'); | |
1661 | |
654
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1662 # http2_max_concurrent_streams |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1663 |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1664 $sess = new_session(8086); |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1665 $frames = h2_read($sess, all => [{ type => 'SETTINGS' }]); |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1666 |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1667 ($frame) = grep { $_->{type} eq 'SETTINGS' } @$frames; |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1668 is($frame->{3}, 1, 'http2_max_concurrent_streams SETTINGS'); |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1669 |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1670 h2_window($sess, 2**18); |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1671 |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1672 $sid = new_stream($sess, { path => '/t1.html' }); |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1673 $frames = h2_read($sess, all => [{ sid => $sid, length => 2 ** 16 - 1 }]); |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1674 |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1675 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames; |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1676 is($frame->{headers}->{':status'}, 200, 'http2_max_concurrent_streams'); |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1677 |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1678 $sid2 = new_stream($sess, { path => '/t1.html' }); |
667
0247e314e991
Tests: more HTTP/2 error handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
662
diff
changeset
|
1679 $frames = h2_read($sess, all => [{ type => 'RST_STREAM' }]); |
654
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1680 |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1681 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid2 } @$frames; |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1682 isnt($frame->{headers}->{':status'}, 200, 'http2_max_concurrent_streams 2'); |
a64fe1054fb4
Tests: HTTP/2 tests for http2_max_concurrent_streams directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
653
diff
changeset
|
1683 |
667
0247e314e991
Tests: more HTTP/2 error handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
662
diff
changeset
|
1684 ($frame) = grep { $_->{type} eq "RST_STREAM" && $_->{sid} == $sid2 } @$frames; |
0247e314e991
Tests: more HTTP/2 error handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
662
diff
changeset
|
1685 is($frame->{sid}, $sid2, 'http2_max_concurrent_streams RST_STREAM sid'); |
0247e314e991
Tests: more HTTP/2 error handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
662
diff
changeset
|
1686 is($frame->{length}, 4, 'http2_max_concurrent_streams RST_STREAM length'); |
0247e314e991
Tests: more HTTP/2 error handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
662
diff
changeset
|
1687 is($frame->{flags}, 0, 'http2_max_concurrent_streams RST_STREAM flags'); |
0247e314e991
Tests: more HTTP/2 error handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
662
diff
changeset
|
1688 is($frame->{code}, 7, 'http2_max_concurrent_streams RST_STREAM code'); |
0247e314e991
Tests: more HTTP/2 error handling tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
662
diff
changeset
|
1689 |
661
c99c30afc1c9
Tests: one more test for http2_max_concurrent_streams.
Sergey Kandaurov <pluknet@nginx.com>
parents:
660
diff
changeset
|
1690 h2_window($sess, 2**16, $sid); |
c99c30afc1c9
Tests: one more test for http2_max_concurrent_streams.
Sergey Kandaurov <pluknet@nginx.com>
parents:
660
diff
changeset
|
1691 h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
c99c30afc1c9
Tests: one more test for http2_max_concurrent_streams.
Sergey Kandaurov <pluknet@nginx.com>
parents:
660
diff
changeset
|
1692 |
c99c30afc1c9
Tests: one more test for http2_max_concurrent_streams.
Sergey Kandaurov <pluknet@nginx.com>
parents:
660
diff
changeset
|
1693 $sid = new_stream($sess, { path => '/t2.html' }); |
c99c30afc1c9
Tests: one more test for http2_max_concurrent_streams.
Sergey Kandaurov <pluknet@nginx.com>
parents:
660
diff
changeset
|
1694 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
c99c30afc1c9
Tests: one more test for http2_max_concurrent_streams.
Sergey Kandaurov <pluknet@nginx.com>
parents:
660
diff
changeset
|
1695 |
c99c30afc1c9
Tests: one more test for http2_max_concurrent_streams.
Sergey Kandaurov <pluknet@nginx.com>
parents:
660
diff
changeset
|
1696 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == $sid } @$frames; |
c99c30afc1c9
Tests: one more test for http2_max_concurrent_streams.
Sergey Kandaurov <pluknet@nginx.com>
parents:
660
diff
changeset
|
1697 is($frame->{headers}->{':status'}, 200, 'http2_max_concurrent_streams 3'); |
c99c30afc1c9
Tests: one more test for http2_max_concurrent_streams.
Sergey Kandaurov <pluknet@nginx.com>
parents:
660
diff
changeset
|
1698 |
646 | 1699 |
1700 # some invalid cases below | |
1701 | |
675
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1702 # ensure that request header field value with newline doesn't get split |
677
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1703 # |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1704 # 10.3. Intermediary Encapsulation Attacks |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1705 # Any request or response that contains a character not permitted |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1706 # in a header field value MUST be treated as malformed. |
675
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1707 |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1708 $sess = new_session(); |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1709 $sid = new_stream($sess, { headers => [ |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1710 { name => ':method', value => 'GET', mode => 0 }, |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1711 { name => ':scheme', value => 'http', mode => 0 }, |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1712 { name => ':path', value => '/proxy2/', mode => 1 }, |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1713 { name => ':authority', value => 'localhost', mode => 1 }, |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1714 { name => 'x-foo', value => "x-bar\r\nreferer:see-this", mode => 2 }]}); |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1715 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1716 |
677
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1717 # 10.3. Intermediary Encapsulation Attacks |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1718 # An intermediary therefore cannot translate an HTTP/2 request or response |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1719 # containing an invalid field name into an HTTP/1.1 message. |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1720 |
675
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1721 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1722 isnt($frame->{headers}->{'x-referer'}, 'see-this', 'newline in request header'); |
42de9efd11ee
Tests: added HTTP/2 test for request header with newline.
Sergey Kandaurov <pluknet@nginx.com>
parents:
673
diff
changeset
|
1723 |
677
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1724 # 8.1.2.6. Malformed Requests and Responses |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1725 # Malformed requests or responses that are detected MUST be treated |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1726 # as a stream error (Section 5.4.2) of type PROTOCOL_ERROR. |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1727 |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1728 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1729 is($frame->{sid}, $sid, 'newline in request header - RST_STREAM sid'); |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1730 is($frame->{length}, 4, 'newline in request header - RST_STREAM length'); |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1731 is($frame->{flags}, 0, 'newline in request header - RST_STREAM flags'); |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1732 is($frame->{code}, 1, 'newline in request header - RST_STREAM code'); |
5d258aa5ebc5
Tests: more HTTP/2 tests for newline in request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
675
diff
changeset
|
1733 |
646 | 1734 # GOAWAY on SYN_STREAM with even StreamID |
1735 | |
1736 $sess = new_session(); | |
1737 new_stream($sess, { path => '/' }, 2); | |
1738 $frames = h2_read($sess, all => [{ type => 'GOAWAY' }]); | |
1739 | |
1740 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
1741 ok($frame, 'even stream - GOAWAY frame'); | |
1742 is($frame->{code}, 1, 'even stream - error code'); | |
669
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1743 is($frame->{last_sid}, 0, 'even stream - last stream'); |
646 | 1744 |
1745 # GOAWAY on SYN_STREAM with backward StreamID | |
1746 | |
669
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1747 # 5.1.1. Stream Identifiers |
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1748 # The first use of a new stream identifier implicitly closes all |
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1749 # streams in the "idle" state <..> with a lower-valued stream identifier. |
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1750 |
646 | 1751 $sess = new_session(); |
1752 $sid = new_stream($sess, { path => '/' }, 3); | |
1753 h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1754 | |
1755 $sid2 = new_stream($sess, { path => '/' }, 1); | |
1756 $frames = h2_read($sess, all => [{ type => 'GOAWAY' }]); | |
1757 | |
1758 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
1759 ok($frame, 'backward stream - GOAWAY frame'); | |
1760 is($frame->{code}, 1, 'backward stream - error code'); | |
669
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1761 is($frame->{last_sid}, $sid, 'backward stream - last stream'); |
646 | 1762 |
669
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1763 # GOAWAY on the second SYN_STREAM with same StreamID |
646 | 1764 |
1765 $sess = new_session(); | |
1766 $sid = new_stream($sess, { path => '/' }); | |
1767 h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1768 | |
1769 $sid2 = new_stream($sess, { path => '/' }, $sid); | |
669
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1770 $frames = h2_read($sess, all => [{ type => 'GOAWAY' }]); |
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1771 |
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1772 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; |
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1773 ok($frame, 'dup stream - GOAWAY frame'); |
646 | 1774 is($frame->{code}, 1, 'dup stream - error code'); |
669
0c442e551ba1
Tests: corrected HTTP/2 tests for GOAWAY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
668
diff
changeset
|
1775 is($frame->{last_sid}, $sid, 'dup stream - last stream'); |
646 | 1776 |
1777 # missing mandatory request header ':scheme' | |
1778 | |
1779 TODO: { | |
1780 local $TODO = 'not yet'; | |
1781 | |
1782 $sess = new_session(); | |
1783 $sid = new_stream($sess, { headers => [ | |
1784 { name => ':method', value => 'GET', mode => 0 }, | |
653
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
1785 { name => ':path', value => '/', mode => 0 }, |
5ad620022234
Tests: HTTP/2 tests adapted to send ':authority' where needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
652
diff
changeset
|
1786 { name => ':authority', value => 'localhost', mode => 1 }]}); |
646 | 1787 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
1788 | |
1789 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1790 is($frame->{headers}->{':status'}, 400, 'incomplete headers'); | |
1791 | |
1792 } | |
1793 | |
673
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1794 # empty request header ':authority' |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1795 |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1796 $sess = new_session(); |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1797 $sid = new_stream($sess, { headers => [ |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1798 { name => ':method', value => 'GET', mode => 0 }, |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1799 { name => ':scheme', value => 'http', mode => 0 }, |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1800 { name => ':path', value => '/', mode => 0 }, |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1801 { name => ':authority', value => '', mode => 0 }]}); |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1802 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1803 |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1804 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1805 is($frame->{headers}->{':status'}, 400, 'empty authority'); |
9d6c865c2869
Tests: HTTP/2 regression test for empty authority request header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
672
diff
changeset
|
1806 |
697
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1807 # unknown frame type |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1808 |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1809 $sess = new_session(); |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1810 h2_unknown($sess, 'payload'); |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1811 h2_ping($sess, 'SEE-THIS'); |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1812 $frames = h2_read($sess, all => [{ type => 'PING' }]); |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1813 |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1814 ($frame) = grep { $_->{type} eq "PING" } @$frames; |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1815 is($frame->{value}, 'SEE-THIS', 'unknown frame type'); |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1816 |
646 | 1817 # GOAWAY - force closing a connection by server |
1818 | |
1819 $sid = new_stream($sess, { path => 't1.html' }); | |
1820 h2_read($sess, all => [{ sid => $sid, length => 2**16 - 1 }]); | |
1821 | |
1822 $t->stop(); | |
1823 | |
1824 $frames = h2_read($sess, all => [{ type => 'GOAWAY' }]); | |
1825 | |
1826 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
1827 ok($frame, 'GOAWAY on connection close'); | |
1828 | |
1829 ############################################################################### | |
1830 | |
1831 sub h2_ping { | |
1832 my ($sess, $payload) = @_; | |
1833 | |
1834 raw_write($sess->{socket}, pack("x2C2x5a8", 8, 0x6, $payload)); | |
1835 } | |
1836 | |
1837 sub h2_rst { | |
1838 my ($sess, $stream, $error) = @_; | |
1839 | |
1840 raw_write($sess->{socket}, pack("x2C2xNN", 4, 0x3, $stream, $error)); | |
1841 } | |
1842 | |
1843 sub h2_priority { | |
1844 my ($sess, $w, $stream, $dep) = @_; | |
1845 | |
1846 $stream = 0 unless defined $stream; | |
1847 $dep = 0 unless defined $dep; | |
1848 raw_write($sess->{socket}, pack("x2C2xNNC", 5, 0x2, $stream, $dep, $w)); | |
1849 } | |
1850 | |
1851 sub h2_window { | |
1852 my ($sess, $win, $stream) = @_; | |
1853 | |
1854 $stream = 0 unless defined $stream; | |
1855 raw_write($sess->{socket}, pack("x2C2xNN", 4, 0x8, $stream, $win)); | |
1856 } | |
1857 | |
1858 sub h2_settings { | |
1859 my ($sess, $ack, %extra) = @_; | |
1860 | |
1861 my $len = 6 * keys %extra; | |
1862 my $buf = pack_length($len) . pack "CCx4", 0x4, $ack ? 0x1 : 0x0; | |
1863 $buf .= join '', map { pack "nN", $_, $extra{$_} } keys %extra; | |
1864 raw_write($sess->{socket}, $buf); | |
1865 } | |
1866 | |
697
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1867 sub h2_unknown { |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1868 my ($sess, $payload) = @_; |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1869 |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1870 my $buf = pack_length(length($payload)) . pack("Cx5a*", 0xa, $payload); |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1871 raw_write($sess->{socket}, $buf); |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1872 } |
46f698a7e59c
Tests: added HTTP/2 test for unknown frame type.
Sergey Kandaurov <pluknet@nginx.com>
parents:
696
diff
changeset
|
1873 |
646 | 1874 sub h2_continue { |
1875 my ($ctx, $stream, $uri) = @_; | |
1876 | |
1877 $uri->{h2_continue} = 1; | |
1878 return new_stream($ctx, $uri, $stream); | |
1879 } | |
1880 | |
1881 sub new_stream { | |
1882 my ($ctx, $uri, $stream) = @_; | |
1883 my ($input, $buf); | |
1884 my ($d, $status); | |
1885 | |
1886 my $host = $uri->{host} || '127.0.0.1:8080'; | |
1887 my $method = $uri->{method} || 'GET'; | |
1888 my $scheme = $uri->{scheme} || 'http'; | |
1889 my $path = $uri->{path} || '/'; | |
1890 my $headers = $uri->{headers}; | |
1891 my $body = $uri->{body}; | |
1892 my $prio = $uri->{prio}; | |
1893 my $dep = $uri->{dep}; | |
699
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1894 my $split = ref $uri->{continuation} && $uri->{continuation} || []; |
646 | 1895 |
1896 my $pad = defined $uri->{padding} ? $uri->{padding} : 0; | |
1897 my $padlen = defined $uri->{padding} ? 1 : 0; | |
1898 my $bpad = defined $uri->{body_padding} ? $uri->{body_padding} : 0; | |
1899 my $bpadlen = defined $uri->{body_padding} ? 1 : 0; | |
1900 | |
1901 my $type = defined $uri->{h2_continue} ? 0x9 : 0x1; | |
1902 my $flags = defined $uri->{continuation} ? 0x0 : 0x4; | |
1903 $flags |= 0x1 unless defined $body; | |
1904 $flags |= 0x8 if $padlen; | |
1905 $flags |= 0x20 if defined $dep || defined $prio; | |
1906 | |
1907 if ($stream) { | |
1908 $ctx->{last_stream} = $stream; | |
1909 } else { | |
1910 $ctx->{last_stream} += 2; | |
1911 } | |
1912 | |
1913 $buf = pack("xxx"); # Length stub | |
1914 $buf .= pack("CC", $type, $flags); # END_HEADERS | |
1915 $buf .= pack("N", $ctx->{last_stream}); # Stream-ID | |
1916 | |
1917 $dep = 0 if defined $prio and not defined $dep; | |
1918 $prio = 16 if defined $dep and not defined $prio; | |
1919 | |
1920 unless ($headers) { | |
1921 $input = hpack($ctx, ":method", $method); | |
1922 $input .= hpack($ctx, ":scheme", $scheme); | |
1923 $input .= hpack($ctx, ":path", $path); | |
1924 $input .= hpack($ctx, ":authority", $host); | |
1925 $input .= hpack($ctx, "content-length", length($body)) if $body; | |
1926 | |
1927 } else { | |
1928 $input = join '', map { | |
1929 hpack($ctx, $_->{name}, $_->{value}, | |
1930 mode => $_->{mode}, huff => $_->{huff}) | |
1931 } @$headers if $headers; | |
1932 } | |
1933 | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
1934 $input = pack("B*", '001' . ipack(5, $uri->{table_size})) . $input |
646 | 1935 if defined $uri->{table_size}; |
1936 | |
702
cc2b98d028c8
Tests: fixed HTTP/2 test for CONTINUATION while in header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
700
diff
changeset
|
1937 my @input = map { substr $input, 0, $_, "" } @$split; |
699
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1938 push @input, $input; |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1939 |
646 | 1940 # set length, attach headers, padding, priority |
1941 | |
699
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1942 my $hlen = length($input[0]) + $pad + $padlen; |
646 | 1943 $hlen += 5 if $flags & 0x20; |
1944 $buf |= pack_length($hlen); | |
1945 | |
1946 $buf .= pack 'C', $pad if $padlen; # Pad Length? | |
1947 $buf .= pack 'NC', $dep, $prio if $flags & 0x20; | |
699
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1948 $buf .= $input[0]; |
646 | 1949 $buf .= (pack 'C', 0) x $pad if $padlen; # Padding |
1950 | |
699
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1951 shift @input; |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1952 |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1953 while (@input) { |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1954 $input = shift @input; |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1955 $flags = @input ? 0x0 : 0x4; |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1956 $buf .= pack_length(length($input)); |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1957 $buf .= pack("CC", 0x9, $flags); |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1958 $buf .= pack("N", $ctx->{last_stream}); |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1959 $buf .= $input; |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1960 } |
5768830f01c4
Tests: HTTP/2 test for CONTINUATION in the middle of header field.
Sergey Kandaurov <pluknet@nginx.com>
parents:
698
diff
changeset
|
1961 |
646 | 1962 if (defined $body) { |
1963 $buf .= pack_length(length($body) + $bpad + $bpadlen); | |
1964 my $flags = $bpadlen ? 0x8 : 0x0; | |
1965 $buf .= pack 'CC', 0x0, 0x1 | $flags; # DATA, END_STREAM | |
1966 $buf .= pack 'N', $ctx->{last_stream}; | |
1967 $buf .= pack 'C', $bpad if $bpadlen; # DATA Pad Length? | |
1968 $buf .= $body; | |
1969 $buf .= (pack 'C', 0) x $bpad if $bpadlen; # DATA Padding | |
1970 } | |
1971 | |
1972 raw_write($ctx->{socket}, $buf); | |
1973 return $ctx->{last_stream}; | |
1974 } | |
1975 | |
1976 sub h2_read { | |
1977 my ($sess, %extra) = @_; | |
1978 my (@got); | |
1979 my $s = $sess->{socket}; | |
1980 my $buf = ''; | |
1981 | |
1982 while (1) { | |
1983 $buf = raw_read($s, $buf, 9); | |
1984 last unless length $buf; | |
1985 | |
1986 my $length = unpack_length($buf); | |
1987 my $type = unpack('x3C', $buf); | |
1988 my $flags = unpack('x4C', $buf); | |
1989 | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
1990 my $stream = unpack "x5 B32", $buf; |
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
1991 substr($stream, 0, 1) = 0; |
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
1992 $stream = unpack("N", pack("B32", $stream)); |
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
1993 |
679
b60c1a207675
Tests: fixed HTTP/2 tests with large frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
677
diff
changeset
|
1994 $buf = raw_read($s, $buf, $length + 9); |
646 | 1995 last unless length $buf; |
1996 | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
1997 $buf = substr($buf, 9); |
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
1998 |
646 | 1999 my $frame = $cframe{$type}{value}($sess, $buf, $length); |
2000 $frame->{length} = $length; | |
2001 $frame->{type} = $cframe{$type}{name}; | |
2002 $frame->{flags} = $flags; | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2003 $frame->{sid} = $stream; |
646 | 2004 push @got, $frame; |
2005 | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2006 $buf = substr($buf, $length); |
646 | 2007 |
2008 last unless test_fin($got[-1], $extra{all}); | |
2009 }; | |
2010 return \@got; | |
2011 } | |
2012 | |
2013 sub test_fin { | |
2014 my ($frame, $all) = @_; | |
2015 my @test = @{$all}; | |
2016 | |
2017 # wait for the specified DATA length | |
2018 | |
2019 for (@test) { | |
2020 if ($_->{length} && $frame->{type} eq 'DATA') { | |
2021 # check also for StreamID if needed | |
2022 | |
2023 if (!$_->{sid} || $_->{sid} == $frame->{sid}) { | |
2024 $_->{length} -= $frame->{length}; | |
2025 } | |
2026 } | |
2027 } | |
2028 @test = grep { !(defined $_->{length} && $_->{length} == 0) } @test; | |
2029 | |
2030 # wait for the fin flag | |
2031 | |
2032 @test = grep { !(defined $_->{fin} | |
2033 && $_->{sid} == $frame->{sid} && $_->{fin} & $frame->{flags}) | |
2034 } @test if defined $frame->{flags}; | |
2035 | |
2036 # wait for the specified frame | |
2037 | |
2038 @test = grep { !($_->{type} && $_->{type} eq $frame->{type}) } @test; | |
2039 | |
2040 @{$all} = @test; | |
2041 } | |
2042 | |
2043 sub headers { | |
2044 my ($ctx, $buf, $len) = @_; | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2045 return { headers => hunpack($ctx, $buf, $len) }; |
646 | 2046 } |
2047 | |
2048 sub data { | |
2049 my ($ctx, $buf, $len) = @_; | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2050 return { data => substr($buf, 0, $len) }; |
646 | 2051 } |
2052 | |
2053 sub settings { | |
2054 my ($ctx, $buf, $len) = @_; | |
2055 my %payload; | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2056 my $skip = 0; |
646 | 2057 |
2058 for (1 .. $len / 6) { | |
2059 my $id = hex unpack "\@$skip n", $buf; $skip += 2; | |
2060 $payload{$id} = unpack "\@$skip N", $buf; $skip += 4; | |
2061 } | |
2062 return \%payload; | |
2063 } | |
2064 | |
2065 sub ping { | |
2066 my ($ctx, $buf, $len) = @_; | |
670
944b87756cab
Tests: fixed GOAWAY and PING frames parsing in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
669
diff
changeset
|
2067 return { value => unpack "A$len", $buf }; |
646 | 2068 } |
2069 | |
2070 sub rst_stream { | |
2071 my ($ctx, $buf, $len) = @_; | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2072 return { code => unpack "N", $buf }; |
646 | 2073 } |
2074 | |
2075 sub goaway { | |
2076 my ($ctx, $buf, $len) = @_; | |
2077 my %payload; | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2078 |
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2079 my $stream = unpack "B32", $buf; |
646 | 2080 substr($stream, 0, 1) = 0; |
2081 $stream = unpack("N", pack("B32", $stream)); | |
2082 $payload{last_sid} = $stream; | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2083 |
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2084 $len -= 4; |
670
944b87756cab
Tests: fixed GOAWAY and PING frames parsing in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
669
diff
changeset
|
2085 $payload{code} = unpack "x4 N", $buf; |
944b87756cab
Tests: fixed GOAWAY and PING frames parsing in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
669
diff
changeset
|
2086 $payload{debug} = unpack "x8 A$len", $buf; |
646 | 2087 return \%payload; |
2088 } | |
2089 | |
2090 sub window_update { | |
2091 my ($ctx, $buf, $len) = @_; | |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2092 my $value = unpack "B32", $buf; |
646 | 2093 substr($value, 0, 1) = 0; |
655
75ecd26b8831
Tests: HTTP/2 tests cleanup.
Sergey Kandaurov <pluknet@nginx.com>
parents:
654
diff
changeset
|
2094 return { wdelta => unpack("N", pack("B32", $value)) }; |
646 | 2095 } |
2096 | |
2097 sub pack_length { | |
2098 pack 'c3', unpack 'xc3', pack 'N', $_[0]; | |
2099 } | |
2100 | |
2101 sub unpack_length { | |
2102 unpack 'N', pack 'xc3', unpack 'c3', $_[0]; | |
2103 } | |
2104 | |
2105 sub raw_read { | |
2106 my ($s, $buf, $len) = @_; | |
2107 my $got = ''; | |
2108 | |
2109 while (length($buf) < $len && IO::Select->new($s)->can_read(1)) { | |
650
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2110 $s->sysread($got, 16384) or last; |
646 | 2111 log_in($got); |
2112 $buf .= $got; | |
2113 } | |
2114 return $buf; | |
2115 } | |
2116 | |
2117 sub raw_write { | |
2118 my ($s, $message) = @_; | |
2119 | |
2120 local $SIG{PIPE} = 'IGNORE'; | |
2121 | |
2122 while (IO::Select->new($s)->can_write(0.4)) { | |
2123 log_out($message); | |
2124 my $n = $s->syswrite($message); | |
2125 last unless $n; | |
2126 $message = substr($message, $n); | |
2127 last unless length $message; | |
2128 } | |
2129 } | |
2130 | |
2131 sub new_session { | |
2132 my ($port, %extra) = @_; | |
2133 my ($s); | |
2134 | |
650
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2135 $s = new_socket($port, %extra); |
646 | 2136 |
2137 if ($extra{proxy}) { | |
2138 raw_write($s, $extra{proxy}); | |
2139 } | |
2140 | |
2141 # preface | |
2142 | |
2143 raw_write($s, 'PRI * HTTP/2.0' . CRLF . CRLF . 'SM' . CRLF . CRLF); | |
2144 | |
2145 return { socket => $s, last_stream => -1, | |
2146 dynamic_encode => [ static_table() ], | |
2147 dynamic_decode => [ static_table() ], | |
2148 static_table_size => scalar @{[static_table()]} }; | |
2149 } | |
2150 | |
2151 sub new_socket { | |
650
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2152 my ($port, %extra) = @_; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2153 my $npn = $extra{'npn'}; |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2154 my $alpn = $extra{'alpn'}; |
646 | 2155 my $s; |
2156 | |
2157 $port = 8080 unless defined $port; | |
2158 | |
2159 eval { | |
2160 local $SIG{ALRM} = sub { die "timeout\n" }; | |
2161 local $SIG{PIPE} = sub { die "sigpipe\n" }; | |
2162 alarm(2); | |
2163 $s = IO::Socket::INET->new( | |
2164 Proto => 'tcp', | |
2165 PeerAddr => "127.0.0.1:$port", | |
2166 ); | |
650
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2167 IO::Socket::SSL->start_SSL($s, |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2168 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(), |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2169 SSL_npn_protocols => $npn ? [ $npn ] : undef, |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2170 SSL_alpn_protocols => $alpn ? [ $alpn ] : undef, |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2171 SSL_error_trap => sub { die $_[1] } |
8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
647
diff
changeset
|
2172 ) if $extra{'SSL'}; |
646 | 2173 alarm(0); |
2174 }; | |
2175 alarm(0); | |
2176 | |
2177 if ($@) { | |
2178 log_in("died: $@"); | |
2179 return undef; | |
2180 } | |
2181 | |
2182 return $s; | |
2183 } | |
2184 | |
2185 sub static_table { | |
2186 [ '', '' ], # unused | |
2187 [ ':authority', '' ], | |
2188 [ ':method', 'GET' ], | |
2189 [ ':method', 'POST' ], | |
2190 [ ':path', '/' ], | |
2191 [ ':path', '/index.html' ], | |
2192 [ ':scheme', 'http' ], | |
2193 [ ':scheme', 'https' ], | |
2194 [ ':status', '200' ], | |
2195 [ ':status', '204' ], | |
2196 [ ':status', '206' ], | |
2197 [ ':status', '304' ], | |
2198 [ ':status', '400' ], | |
2199 [ ':status', '404' ], | |
2200 [ ':status', '500' ], | |
2201 [ 'accept-charset', '' ], | |
2202 [ 'accept-encoding', 'gzip, deflate' ], | |
2203 [ 'accept-language', '' ], | |
2204 [ 'accept-ranges', '' ], | |
2205 [ 'accept', '' ], | |
2206 [ 'access-control-allow-origin', | |
2207 '' ], | |
2208 [ 'age', '' ], | |
2209 [ 'allow', '' ], | |
2210 [ 'authorization', '' ], | |
2211 [ 'cache-control', '' ], | |
2212 [ 'content-disposition', | |
2213 '' ], | |
2214 [ 'content-encoding', '' ], | |
2215 [ 'content-language', '' ], | |
2216 [ 'content-length', '' ], | |
2217 [ 'content-location', '' ], | |
2218 [ 'content-range', '' ], | |
2219 [ 'content-type', '' ], | |
2220 [ 'cookie', '' ], | |
2221 [ 'date', '' ], | |
2222 [ 'etag', '' ], | |
2223 [ 'expect', '' ], | |
2224 [ 'expires', '' ], | |
2225 [ 'from', '' ], | |
2226 [ 'host', '' ], | |
2227 [ 'if-match', '' ], | |
2228 [ 'if-modified-since', '' ], | |
2229 [ 'if-none-match', '' ], | |
2230 [ 'if-range', '' ], | |
2231 [ 'if-unmodified-since', | |
2232 '' ], | |
2233 [ 'last-modified', '' ], | |
2234 [ 'link', '' ], | |
2235 [ 'location', '' ], | |
2236 [ 'max-forwards', '' ], | |
2237 [ 'proxy-authenticate', '' ], | |
2238 [ 'proxy-authorization', | |
2239 '' ], | |
2240 [ 'range', '' ], | |
2241 [ 'referer', '' ], | |
2242 [ 'refresh', '' ], | |
2243 [ 'retry-after', '' ], | |
2244 [ 'server', '' ], | |
2245 [ 'set-cookie', '' ], | |
2246 [ 'strict-transport-security', | |
2247 '' ], | |
2248 [ 'transfer-encoding', '' ], | |
2249 [ 'user-agent', '' ], | |
2250 [ 'vary', '' ], | |
2251 [ 'via', '' ], | |
2252 [ 'www-authenticate', '' ], | |
2253 } | |
2254 | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2255 # RFC 7541, 5.1. Integer Representation |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2256 |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2257 sub ipack { |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2258 my ($base, $d) = @_; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2259 return sprintf("%.*b", $base, $d) if $d < 2**$base - 1; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2260 |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2261 my $o = sprintf("%${base}b", 2**$base - 1); |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2262 $d -= 2**$base - 1; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2263 while ($d >= 128) { |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2264 $o .= sprintf("%8b", $d % 128 + 128); |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2265 $d /= 128; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2266 } |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2267 $o .= sprintf("%08b", $d); |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2268 return $o; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2269 } |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2270 |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2271 sub iunpack { |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2272 my ($base, $b, $s) = @_; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2273 |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2274 my $len = unpack("\@$s B8", $b); $s++; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2275 my $prefix = substr($len, 0, 8 - $base); |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2276 $len = '0' x (8 - $base) . substr($len, 8 - $base); |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2277 $len = unpack("C", pack("B8", $len)); |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2278 |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2279 return ($len, $s, $prefix) if $len < 2**$base - 1; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2280 |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2281 my $m = 0; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2282 my $d; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2283 |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2284 do { |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2285 $d = unpack("\@$s C", $b); $s++; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2286 $len += ($d & 127) * 2**$m; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2287 $m += $base; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2288 } while (($d & 128) == 128); |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2289 |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2290 return ($len, $s, $prefix); |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2291 } |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2292 |
646 | 2293 sub hpack { |
2294 my ($ctx, $name, $value, %extra) = @_; | |
671
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2295 my $table = $ctx->{dynamic_encode}; |
646 | 2296 my $mode = defined $extra{mode} ? $extra{mode} : 1; |
2297 my $huff = $extra{huff}; | |
2298 | |
2299 my ($index, $buf) = 0; | |
2300 | |
2301 # 6.1. Indexed Header Field Representation | |
2302 | |
2303 if ($mode == 0) { | |
671
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2304 ++$index until $index > $#$table |
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2305 or $table->[$index][0] eq $name |
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2306 and $table->[$index][1] eq $value; |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2307 $buf = pack('B*', '1' . ipack(7, $index)); |
646 | 2308 } |
2309 | |
2310 # 6.2.1. Literal Header Field with Incremental Indexing | |
2311 | |
2312 if ($mode == 1) { | |
671
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2313 splice @$table, $ctx->{static_table_size}, 0, [ $name, $value ]; |
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2314 |
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2315 ++$index until $index > $#$table |
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2316 or $table->[$index][0] eq $name; |
646 | 2317 my $value = $huff ? huff($value) : $value; |
2318 | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2319 $buf = pack('B*', '01' . ipack(6, $index) |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2320 . ($huff ? '1' : '0') . ipack(7, length($value))); |
646 | 2321 $buf .= $value; |
2322 } | |
2323 | |
2324 # 6.2.1. Literal Header Field with Incremental Indexing -- New Name | |
2325 | |
2326 if ($mode == 2) { | |
671
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2327 splice @$table, $ctx->{static_table_size}, 0, [ $name, $value ]; |
646 | 2328 |
2329 my $name = $huff ? huff($name) : $name; | |
2330 my $value = $huff ? huff($value) : $value; | |
2331 my $hbit = ($huff ? '1' : '0'); | |
2332 | |
2333 $buf = pack('B*', '01000000'); | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2334 $buf .= pack('B*', $hbit . ipack(7, length($name))); |
646 | 2335 $buf .= $name; |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2336 $buf .= pack('B*', $hbit . ipack(7, length($value))); |
646 | 2337 $buf .= $value; |
2338 } | |
2339 | |
2340 # 6.2.2. Literal Header Field without Indexing | |
2341 | |
2342 if ($mode == 3) { | |
671
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2343 ++$index until $index > $#$table |
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2344 or $table->[$index][0] eq $name; |
646 | 2345 my $value = $huff ? huff($value) : $value; |
2346 | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2347 $buf = pack('B*', '0000' . ipack(4, $index) |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2348 . ($huff ? '1' : '0') . ipack(7, length($value))); |
646 | 2349 $buf .= $value; |
2350 } | |
2351 | |
2352 # 6.2.2. Literal Header Field without Indexing -- New Name | |
2353 | |
2354 if ($mode == 4) { | |
2355 my $name = $huff ? huff($name) : $name; | |
2356 my $value = $huff ? huff($value) : $value; | |
2357 my $hbit = ($huff ? '1' : '0'); | |
2358 | |
2359 $buf = pack('B*', '00000000'); | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2360 $buf .= pack('B*', $hbit . ipack(7, length($name))); |
646 | 2361 $buf .= $name; |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2362 $buf .= pack('B*', $hbit . ipack(7, length($value))); |
646 | 2363 $buf .= $value; |
2364 } | |
2365 | |
2366 # 6.2.3. Literal Header Field Never Indexed | |
2367 | |
2368 if ($mode == 5) { | |
671
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2369 ++$index until $index > $#$table |
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2370 or $table->[$index][0] eq $name; |
646 | 2371 my $value = $huff ? huff($value) : $value; |
2372 | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2373 $buf = pack('B*', '0001' . ipack(4, $index) |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2374 . ($huff ? '1' : '0') . ipack(7, length($value))); |
646 | 2375 $buf .= $value; |
2376 } | |
2377 | |
2378 # 6.2.3. Literal Header Field Never Indexed -- New Name | |
2379 | |
2380 if ($mode == 6) { | |
2381 my $name = $huff ? huff($name) : $name; | |
2382 my $value = $huff ? huff($value) : $value; | |
2383 my $hbit = ($huff ? '1' : '0'); | |
2384 | |
2385 $buf = pack('B*', '00010000'); | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2386 $buf .= pack('B*', $hbit . ipack(7, length($name))); |
646 | 2387 $buf .= $name; |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2388 $buf .= pack('B*', $hbit . ipack(7, length($value))); |
646 | 2389 $buf .= $value; |
2390 } | |
2391 | |
2392 return $buf; | |
2393 } | |
2394 | |
2395 sub hunpack { | |
2396 my ($ctx, $data, $length) = @_; | |
671
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2397 my $table = $ctx->{dynamic_decode}; |
646 | 2398 my %headers; |
2399 my $skip = 0; | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2400 my ($index, $name, $value); |
646 | 2401 |
2402 sub field { | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2403 my ($b) = @_; |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2404 my ($len, $s, $huff) = iunpack(7, @_); |
646 | 2405 |
2406 my $field = substr($b, $s, $len); | |
2407 $field = $huff ? dehuff($field) : $field; | |
2408 $s += $len; | |
2409 return ($field, $s); | |
2410 } | |
2411 | |
2412 sub add { | |
2413 my ($h, $n, $v) = @_; | |
2414 return $h->{$n} = $v unless exists $h->{$n}; | |
2415 $h->{$n} = [ $h->{$n} ]; | |
647
4e36550410b3
Tests: h2.t fixes for older perl versions, and gzip test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
646
diff
changeset
|
2416 push @{$h->{$n}}, $v; |
646 | 2417 } |
2418 | |
2419 while ($skip < $length) { | |
2420 my $ib = unpack("\@$skip B8", $data); | |
2421 | |
2422 if (substr($ib, 0, 1) eq '1') { | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2423 ($index, $skip) = iunpack(7, $data, $skip); |
671
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2424 add(\%headers, |
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2425 $table->[$index][0], $table->[$index][1]); |
646 | 2426 next; |
2427 } | |
2428 | |
2429 if (substr($ib, 0, 2) eq '01') { | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2430 ($index, $skip) = iunpack(6, $data, $skip); |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2431 $name = $table->[$index][0]; |
646 | 2432 |
2433 ($name, $skip) = field($data, $skip) unless $name; | |
2434 ($value, $skip) = field($data, $skip); | |
2435 | |
671
0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
Sergey Kandaurov <pluknet@nginx.com>
parents:
670
diff
changeset
|
2436 splice @$table, |
646 | 2437 $ctx->{static_table_size}, 0, [ $name, $value ]; |
2438 add(\%headers, $name, $value); | |
2439 next; | |
2440 } | |
2441 | |
2442 if (substr($ib, 0, 4) eq '0000') { | |
694
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2443 ($index, $skip) = iunpack(4, $data, $skip); |
3eba6e1b8313
Tests: finished HPACK coding in HTTP/2 tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
692
diff
changeset
|
2444 $name = $table->[$index][0]; |
646 | 2445 |
2446 ($name, $skip) = field($data, $skip) unless $name; | |
2447 ($value, $skip) = field($data, $skip); | |
2448 | |
2449 add(\%headers, $name, $value); | |
2450 next; | |
2451 } | |
2452 } | |
2453 | |
2454 return \%headers; | |
2455 } | |
2456 | |
2457 sub huff_code { scalar { | |
2458 pack('C', 0) => '1111111111000', | |
2459 pack('C', 1) => '11111111111111111011000', | |
2460 pack('C', 2) => '1111111111111111111111100010', | |
2461 pack('C', 3) => '1111111111111111111111100011', | |
2462 pack('C', 4) => '1111111111111111111111100100', | |
2463 pack('C', 5) => '1111111111111111111111100101', | |
2464 pack('C', 6) => '1111111111111111111111100110', | |
2465 pack('C', 7) => '1111111111111111111111100111', | |
2466 pack('C', 8) => '1111111111111111111111101000', | |
2467 pack('C', 9) => '111111111111111111101010', | |
2468 pack('C', 10) => '111111111111111111111111111100', | |
2469 pack('C', 11) => '1111111111111111111111101001', | |
2470 pack('C', 12) => '1111111111111111111111101010', | |
2471 pack('C', 13) => '111111111111111111111111111101', | |
2472 pack('C', 14) => '1111111111111111111111101011', | |
2473 pack('C', 15) => '1111111111111111111111101100', | |
2474 pack('C', 16) => '1111111111111111111111101101', | |
2475 pack('C', 17) => '1111111111111111111111101110', | |
2476 pack('C', 18) => '1111111111111111111111101111', | |
2477 pack('C', 19) => '1111111111111111111111110000', | |
2478 pack('C', 20) => '1111111111111111111111110001', | |
2479 pack('C', 21) => '1111111111111111111111110010', | |
2480 pack('C', 22) => '111111111111111111111111111110', | |
2481 pack('C', 23) => '1111111111111111111111110011', | |
2482 pack('C', 24) => '1111111111111111111111110100', | |
2483 pack('C', 25) => '1111111111111111111111110101', | |
2484 pack('C', 26) => '1111111111111111111111110110', | |
2485 pack('C', 27) => '1111111111111111111111110111', | |
2486 pack('C', 28) => '1111111111111111111111111000', | |
2487 pack('C', 29) => '1111111111111111111111111001', | |
2488 pack('C', 30) => '1111111111111111111111111010', | |
2489 pack('C', 31) => '1111111111111111111111111011', | |
2490 pack('C', 32) => '010100', | |
2491 pack('C', 33) => '1111111000', | |
2492 pack('C', 34) => '1111111001', | |
2493 pack('C', 35) => '111111111010', | |
2494 pack('C', 36) => '1111111111001', | |
2495 pack('C', 37) => '010101', | |
2496 pack('C', 38) => '11111000', | |
2497 pack('C', 39) => '11111111010', | |
2498 pack('C', 40) => '1111111010', | |
2499 pack('C', 41) => '1111111011', | |
2500 pack('C', 42) => '11111001', | |
2501 pack('C', 43) => '11111111011', | |
2502 pack('C', 44) => '11111010', | |
2503 pack('C', 45) => '010110', | |
2504 pack('C', 46) => '010111', | |
2505 pack('C', 47) => '011000', | |
2506 pack('C', 48) => '00000', | |
2507 pack('C', 49) => '00001', | |
2508 pack('C', 50) => '00010', | |
2509 pack('C', 51) => '011001', | |
2510 pack('C', 52) => '011010', | |
2511 pack('C', 53) => '011011', | |
2512 pack('C', 54) => '011100', | |
2513 pack('C', 55) => '011101', | |
2514 pack('C', 56) => '011110', | |
2515 pack('C', 57) => '011111', | |
2516 pack('C', 58) => '1011100', | |
2517 pack('C', 59) => '11111011', | |
2518 pack('C', 60) => '111111111111100', | |
2519 pack('C', 61) => '100000', | |
2520 pack('C', 62) => '111111111011', | |
2521 pack('C', 63) => '1111111100', | |
2522 pack('C', 64) => '1111111111010', | |
2523 pack('C', 65) => '100001', | |
2524 pack('C', 66) => '1011101', | |
2525 pack('C', 67) => '1011110', | |
2526 pack('C', 68) => '1011111', | |
2527 pack('C', 69) => '1100000', | |
2528 pack('C', 70) => '1100001', | |
2529 pack('C', 71) => '1100010', | |
2530 pack('C', 72) => '1100011', | |
2531 pack('C', 73) => '1100100', | |
2532 pack('C', 74) => '1100101', | |
2533 pack('C', 75) => '1100110', | |
2534 pack('C', 76) => '1100111', | |
2535 pack('C', 77) => '1101000', | |
2536 pack('C', 78) => '1101001', | |
2537 pack('C', 79) => '1101010', | |
2538 pack('C', 80) => '1101011', | |
2539 pack('C', 81) => '1101100', | |
2540 pack('C', 82) => '1101101', | |
2541 pack('C', 83) => '1101110', | |
2542 pack('C', 84) => '1101111', | |
2543 pack('C', 85) => '1110000', | |
2544 pack('C', 86) => '1110001', | |
2545 pack('C', 87) => '1110010', | |
2546 pack('C', 88) => '11111100', | |
2547 pack('C', 89) => '1110011', | |
2548 pack('C', 90) => '11111101', | |
2549 pack('C', 91) => '1111111111011', | |
2550 pack('C', 92) => '1111111111111110000', | |
2551 pack('C', 93) => '1111111111100', | |
2552 pack('C', 94) => '11111111111100', | |
2553 pack('C', 95) => '100010', | |
2554 pack('C', 96) => '111111111111101', | |
2555 pack('C', 97) => '00011', | |
2556 pack('C', 98) => '100011', | |
2557 pack('C', 99) => '00100', | |
2558 pack('C', 100) => '100100', | |
2559 pack('C', 101) => '00101', | |
2560 pack('C', 102) => '100101', | |
2561 pack('C', 103) => '100110', | |
2562 pack('C', 104) => '100111', | |
2563 pack('C', 105) => '00110', | |
2564 pack('C', 106) => '1110100', | |
2565 pack('C', 107) => '1110101', | |
2566 pack('C', 108) => '101000', | |
2567 pack('C', 109) => '101001', | |
2568 pack('C', 110) => '101010', | |
2569 pack('C', 111) => '00111', | |
2570 pack('C', 112) => '101011', | |
2571 pack('C', 113) => '1110110', | |
2572 pack('C', 114) => '101100', | |
2573 pack('C', 115) => '01000', | |
2574 pack('C', 116) => '01001', | |
2575 pack('C', 117) => '101101', | |
2576 pack('C', 118) => '1110111', | |
2577 pack('C', 119) => '1111000', | |
2578 pack('C', 120) => '1111001', | |
2579 pack('C', 121) => '1111010', | |
2580 pack('C', 122) => '1111011', | |
2581 pack('C', 123) => '111111111111110', | |
2582 pack('C', 124) => '11111111100', | |
2583 pack('C', 125) => '11111111111101', | |
2584 pack('C', 126) => '1111111111101', | |
2585 pack('C', 127) => '1111111111111111111111111100', | |
2586 pack('C', 128) => '11111111111111100110', | |
2587 pack('C', 129) => '1111111111111111010010', | |
2588 pack('C', 130) => '11111111111111100111', | |
2589 pack('C', 131) => '11111111111111101000', | |
2590 pack('C', 132) => '1111111111111111010011', | |
2591 pack('C', 133) => '1111111111111111010100', | |
2592 pack('C', 134) => '1111111111111111010101', | |
2593 pack('C', 135) => '11111111111111111011001', | |
2594 pack('C', 136) => '1111111111111111010110', | |
2595 pack('C', 137) => '11111111111111111011010', | |
2596 pack('C', 138) => '11111111111111111011011', | |
2597 pack('C', 139) => '11111111111111111011100', | |
2598 pack('C', 140) => '11111111111111111011101', | |
2599 pack('C', 141) => '11111111111111111011110', | |
2600 pack('C', 142) => '111111111111111111101011', | |
2601 pack('C', 143) => '11111111111111111011111', | |
2602 pack('C', 144) => '111111111111111111101100', | |
2603 pack('C', 145) => '111111111111111111101101', | |
2604 pack('C', 146) => '1111111111111111010111', | |
2605 pack('C', 147) => '11111111111111111100000', | |
2606 pack('C', 148) => '111111111111111111101110', | |
2607 pack('C', 149) => '11111111111111111100001', | |
2608 pack('C', 150) => '11111111111111111100010', | |
2609 pack('C', 151) => '11111111111111111100011', | |
2610 pack('C', 152) => '11111111111111111100100', | |
2611 pack('C', 153) => '111111111111111011100', | |
2612 pack('C', 154) => '1111111111111111011000', | |
2613 pack('C', 155) => '11111111111111111100101', | |
2614 pack('C', 156) => '1111111111111111011001', | |
2615 pack('C', 157) => '11111111111111111100110', | |
2616 pack('C', 158) => '11111111111111111100111', | |
2617 pack('C', 159) => '111111111111111111101111', | |
2618 pack('C', 160) => '1111111111111111011010', | |
2619 pack('C', 161) => '111111111111111011101', | |
2620 pack('C', 162) => '11111111111111101001', | |
2621 pack('C', 163) => '1111111111111111011011', | |
2622 pack('C', 164) => '1111111111111111011100', | |
2623 pack('C', 165) => '11111111111111111101000', | |
2624 pack('C', 166) => '11111111111111111101001', | |
2625 pack('C', 167) => '111111111111111011110', | |
2626 pack('C', 168) => '11111111111111111101010', | |
2627 pack('C', 169) => '1111111111111111011101', | |
2628 pack('C', 170) => '1111111111111111011110', | |
2629 pack('C', 171) => '111111111111111111110000', | |
2630 pack('C', 172) => '111111111111111011111', | |
2631 pack('C', 173) => '1111111111111111011111', | |
2632 pack('C', 174) => '11111111111111111101011', | |
2633 pack('C', 175) => '11111111111111111101100', | |
2634 pack('C', 176) => '111111111111111100000', | |
2635 pack('C', 177) => '111111111111111100001', | |
2636 pack('C', 178) => '1111111111111111100000', | |
2637 pack('C', 179) => '111111111111111100010', | |
2638 pack('C', 180) => '11111111111111111101101', | |
2639 pack('C', 181) => '1111111111111111100001', | |
2640 pack('C', 182) => '11111111111111111101110', | |
2641 pack('C', 183) => '11111111111111111101111', | |
2642 pack('C', 184) => '11111111111111101010', | |
2643 pack('C', 185) => '1111111111111111100010', | |
2644 pack('C', 186) => '1111111111111111100011', | |
2645 pack('C', 187) => '1111111111111111100100', | |
2646 pack('C', 188) => '11111111111111111110000', | |
2647 pack('C', 189) => '1111111111111111100101', | |
2648 pack('C', 190) => '1111111111111111100110', | |
2649 pack('C', 191) => '11111111111111111110001', | |
2650 pack('C', 192) => '11111111111111111111100000', | |
2651 pack('C', 193) => '11111111111111111111100001', | |
2652 pack('C', 194) => '11111111111111101011', | |
2653 pack('C', 195) => '1111111111111110001', | |
2654 pack('C', 196) => '1111111111111111100111', | |
2655 pack('C', 197) => '11111111111111111110010', | |
2656 pack('C', 198) => '1111111111111111101000', | |
2657 pack('C', 199) => '1111111111111111111101100', | |
2658 pack('C', 200) => '11111111111111111111100010', | |
2659 pack('C', 201) => '11111111111111111111100011', | |
2660 pack('C', 202) => '11111111111111111111100100', | |
2661 pack('C', 203) => '111111111111111111111011110', | |
2662 pack('C', 204) => '111111111111111111111011111', | |
2663 pack('C', 205) => '11111111111111111111100101', | |
2664 pack('C', 206) => '111111111111111111110001', | |
2665 pack('C', 207) => '1111111111111111111101101', | |
2666 pack('C', 208) => '1111111111111110010', | |
2667 pack('C', 209) => '111111111111111100011', | |
2668 pack('C', 210) => '11111111111111111111100110', | |
2669 pack('C', 211) => '111111111111111111111100000', | |
2670 pack('C', 212) => '111111111111111111111100001', | |
2671 pack('C', 213) => '11111111111111111111100111', | |
2672 pack('C', 214) => '111111111111111111111100010', | |
2673 pack('C', 215) => '111111111111111111110010', | |
2674 pack('C', 216) => '111111111111111100100', | |
2675 pack('C', 217) => '111111111111111100101', | |
2676 pack('C', 218) => '11111111111111111111101000', | |
2677 pack('C', 219) => '11111111111111111111101001', | |
2678 pack('C', 220) => '1111111111111111111111111101', | |
2679 pack('C', 221) => '111111111111111111111100011', | |
2680 pack('C', 222) => '111111111111111111111100100', | |
2681 pack('C', 223) => '111111111111111111111100101', | |
2682 pack('C', 224) => '11111111111111101100', | |
2683 pack('C', 225) => '111111111111111111110011', | |
2684 pack('C', 226) => '11111111111111101101', | |
2685 pack('C', 227) => '111111111111111100110', | |
2686 pack('C', 228) => '1111111111111111101001', | |
2687 pack('C', 229) => '111111111111111100111', | |
2688 pack('C', 230) => '111111111111111101000', | |
2689 pack('C', 231) => '11111111111111111110011', | |
2690 pack('C', 232) => '1111111111111111101010', | |
2691 pack('C', 233) => '1111111111111111101011', | |
2692 pack('C', 234) => '1111111111111111111101110', | |
2693 pack('C', 235) => '1111111111111111111101111', | |
2694 pack('C', 236) => '111111111111111111110100', | |
2695 pack('C', 237) => '111111111111111111110101', | |
2696 pack('C', 238) => '11111111111111111111101010', | |
2697 pack('C', 239) => '11111111111111111110100', | |
2698 pack('C', 240) => '11111111111111111111101011', | |
2699 pack('C', 241) => '111111111111111111111100110', | |
2700 pack('C', 242) => '11111111111111111111101100', | |
2701 pack('C', 243) => '11111111111111111111101101', | |
2702 pack('C', 244) => '111111111111111111111100111', | |
2703 pack('C', 245) => '111111111111111111111101000', | |
2704 pack('C', 246) => '111111111111111111111101001', | |
2705 pack('C', 247) => '111111111111111111111101010', | |
2706 pack('C', 248) => '111111111111111111111101011', | |
2707 pack('C', 249) => '1111111111111111111111111110', | |
2708 pack('C', 250) => '111111111111111111111101100', | |
2709 pack('C', 251) => '111111111111111111111101101', | |
2710 pack('C', 252) => '111111111111111111111101110', | |
2711 pack('C', 253) => '111111111111111111111101111', | |
2712 pack('C', 254) => '111111111111111111111110000', | |
2713 pack('C', 255) => '11111111111111111111101110', | |
2714 '_eos' => '111111111111111111111111111111', | |
2715 }}; | |
2716 | |
2717 sub huff { | |
2718 my ($string) = @_; | |
2719 my $code = &huff_code; | |
2720 | |
2721 my $ret = join '', map { $code->{$_} } (split //, $string); | |
2722 my $len = length($ret) + (8 - length($ret) % 8); | |
2723 $ret .= $code->{_eos}; | |
2724 | |
2725 return pack("B$len", $ret); | |
2726 } | |
2727 | |
2728 sub dehuff { | |
2729 my ($string) = @_; | |
2730 my $code = &huff_code; | |
2731 my %decode = reverse %$code; | |
2732 | |
2733 my $ret = ''; my $c = ''; | |
2734 for (split //, unpack('B*', $string)) { | |
2735 $c .= $_; | |
2736 next unless exists $decode{$c}; | |
2737 last if $decode{$c} eq '_eos'; | |
2738 | |
2739 $ret .= $decode{$c}; | |
2740 $c = ''; | |
2741 } | |
2742 | |
2743 return $ret; | |
2744 } | |
2745 | |
2746 ############################################################################### | |
2747 | |
647
4e36550410b3
Tests: h2.t fixes for older perl versions, and gzip test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
646
diff
changeset
|
2748 sub gunzip_like { |
4e36550410b3
Tests: h2.t fixes for older perl versions, and gzip test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
646
diff
changeset
|
2749 my ($in, $re, $name) = @_; |
646 | 2750 |
2751 SKIP: { | |
2752 eval { require IO::Uncompress::Gunzip; }; | |
2753 Test::More::skip( | |
2754 "IO::Uncompress::Gunzip not installed", 1) if $@; | |
2755 | |
2756 my $out; | |
2757 | |
2758 IO::Uncompress::Gunzip::gunzip(\$in => \$out); | |
2759 | |
647
4e36550410b3
Tests: h2.t fixes for older perl versions, and gzip test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
646
diff
changeset
|
2760 like($out, $re, $name); |
646 | 2761 } |
2762 } | |
2763 | |
2764 ############################################################################### | |
2765 | |
2766 # for tests with multiple header fields | |
2767 | |
2768 sub http_daemon { | |
2769 my $server = IO::Socket::INET->new( | |
2770 Proto => 'tcp', | |
2771 LocalHost => '127.0.0.1', | |
2772 LocalPort => 8083, | |
2773 Listen => 5, | |
2774 Reuse => 1 | |
2775 ) | |
2776 or die "Can't create listening socket: $!\n"; | |
2777 | |
2778 local $SIG{PIPE} = 'IGNORE'; | |
2779 | |
2780 while (my $client = $server->accept()) { | |
2781 $client->autoflush(1); | |
2782 | |
2783 my $headers = ''; | |
2784 my $uri = ''; | |
2785 | |
2786 while (<$client>) { | |
2787 $headers .= $_; | |
2788 last if (/^\x0d?\x0a?$/); | |
2789 } | |
2790 | |
2791 next if $headers eq ''; | |
2792 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | |
2793 | |
2794 if ($uri eq '/cookie') { | |
2795 | |
652
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2796 my ($cookie, $cookie2) = $headers =~ /Cookie: (.+)/ig; |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2797 $cookie2 = '' unless defined $cookie2; |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2798 |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2799 my ($cookie_a, $cookie_c) = ('', ''); |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2800 $cookie_a = $1 if $headers =~ /X-Cookie-a: (.+)/i; |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2801 $cookie_c = $1 if $headers =~ /X-Cookie-c: (.+)/i; |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2802 |
646 | 2803 print $client <<EOF; |
2804 HTTP/1.1 200 OK | |
2805 Connection: close | |
652
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2806 X-Sent-Cookie: $cookie |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2807 X-Sent-Cookie2: $cookie2 |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2808 X-Sent-Cookie-a: $cookie_a |
5a85ad9382a3
Tests: more Cookie tests for HTTP/2.
Sergey Kandaurov <pluknet@nginx.com>
parents:
651
diff
changeset
|
2809 X-Sent-Cookie-c: $cookie_c |
646 | 2810 |
2811 EOF | |
2812 | |
2813 } elsif ($uri eq '/set-cookie') { | |
2814 | |
2815 print $client <<EOF; | |
2816 HTTP/1.1 200 OK | |
2817 Connection: close | |
2818 Set-Cookie: a=b | |
2819 Set-Cookie: c=d | |
2820 | |
2821 EOF | |
2822 | |
2823 } | |
2824 | |
2825 } continue { | |
2826 close $client; | |
2827 } | |
2828 } | |
2829 | |
2830 ############################################################################### |