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