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