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