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