Mercurial > hg > nginx-tests
annotate spdy.t @ 428:e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
It is explicitly checked that SYN_REPLY is not followed by DATA,
also with proxy_buffering off.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 04 Jul 2014 13:19:13 +0400 |
parents | daea9cf92c14 |
children | 89f7a882d692 |
rev | line source |
---|---|
374 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for SPDY protocol version 3.1. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 use IO::Select; | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
16 use Socket qw/ CRLF /; |
374 | 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 | |
28 eval { | |
29 require Compress::Raw::Zlib; | |
30 Compress::Raw::Zlib->Z_OK; | |
31 Compress::Raw::Zlib->Z_SYNC_FLUSH; | |
32 Compress::Raw::Zlib->Z_NO_COMPRESSION; | |
33 Compress::Raw::Zlib->WANT_GZIP_OR_ZLIB; | |
34 }; | |
35 plan(skip_all => 'Compress::Raw::Zlib not installed') if $@; | |
36 plan(skip_all => 'win32') if $^O eq 'MSWin32'; | |
37 | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
38 my $t = Test::Nginx->new() |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
39 ->has(qw/http proxy cache limit_conn rewrite spdy realip/); |
374 | 40 |
428
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
41 $t->plan(76)->write_file_expand('nginx.conf', <<'EOF'); |
374 | 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:10m; | |
54 limit_conn_zone $binary_remote_addr zone=conn:1m; | |
55 | |
56 server { | |
57 listen 127.0.0.1:8080 spdy; | |
58 listen 127.0.0.1:8081; | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
59 listen 127.0.0.1:8082 proxy_protocol spdy; |
374 | 60 server_name localhost; |
61 | |
62 location /s { | |
63 add_header X-Header X-Foo; | |
64 return 200 'body'; | |
65 } | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
66 location /pp { |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
67 set_real_ip_from 127.0.0.1/32; |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
68 real_ip_header proxy_protocol; |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
69 alias %%TESTDIR%%/t2.html; |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
70 add_header X-PP $remote_addr; |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
71 } |
374 | 72 location /spdy { |
73 return 200 $spdy; | |
74 } | |
75 location /prio { | |
76 return 200 $spdy_request_priority; | |
77 } | |
78 location /chunk_size { | |
79 spdy_chunk_size 1; | |
80 return 200 'body'; | |
81 } | |
82 location /redirect { | |
83 error_page 405 /s; | |
84 return 405; | |
85 } | |
86 location /proxy { | |
87 add_header X-Body "$request_body"; | |
88 proxy_pass http://127.0.0.1:8081/; | |
89 proxy_cache NAME; | |
90 proxy_cache_valid 1m; | |
91 } | |
428
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
92 location /proxy_buffering_off { |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
93 proxy_pass http://127.0.0.1:8081/; |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
94 proxy_cache NAME; |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
95 proxy_cache_valid 1m; |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
96 proxy_buffering off; |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
97 } |
374 | 98 location /t3.html { |
99 limit_conn conn 1; | |
100 } | |
101 } | |
102 } | |
103 | |
104 EOF | |
105 | |
106 $t->run(); | |
107 | |
108 # file size is slightly beyond initial window size: 2**16 + 80 bytes | |
109 | |
110 $t->write_file('t1.html', | |
111 join('', map { sprintf "X%04dXXX", $_ } (1 .. 8202))); | |
112 | |
113 $t->write_file('t2.html', 'SEE-THIS'); | |
114 $t->write_file('t3.html', 'SEE-THIS'); | |
115 | |
116 my %cframe = ( | |
117 2 => \&syn_reply, | |
118 3 => \&rst_stream, | |
119 4 => \&settings, | |
120 6 => \&ping, | |
121 7 => \&goaway, | |
122 9 => \&window_update | |
123 ); | |
124 | |
125 ############################################################################### | |
126 | |
127 # PING | |
128 | |
129 my $sess = new_session(); | |
130 spdy_ping($sess, 0x12345678); | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
131 my $frames = spdy_read($sess, all => [{ type => 'PING' }]); |
374 | 132 |
133 my ($frame) = grep { $_->{type} eq "PING" } @$frames; | |
134 ok($frame, 'PING frame'); | |
135 is($frame->{value}, 0x12345678, 'PING payload'); | |
136 | |
137 # GET | |
138 | |
139 $sess = new_session(); | |
140 my $sid1 = spdy_stream($sess, { path => '/s' }); | |
141 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
142 | |
143 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
144 ok($frame, 'SYN_REPLAY frame'); | |
145 is($frame->{sid}, $sid1, 'SYN_REPLAY stream'); | |
146 is($frame->{headers}->{':status'}, 200, 'SYN_REPLAY status'); | |
147 is($frame->{headers}->{'x-header'}, 'X-Foo', 'SYN_REPLAY header'); | |
148 | |
149 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
150 ok($frame, 'DATA frame'); | |
151 is($frame->{length}, length 'body', 'DATA length'); | |
152 is($frame->{data}, 'body', 'DATA payload'); | |
153 | |
154 # GET in new SPDY stream in same session | |
155 | |
156 my $sid2 = spdy_stream($sess, { path => '/s' }); | |
157 $frames = spdy_read($sess, all => [{ sid => $sid2, fin => 1 }]); | |
158 | |
159 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
160 is($frame->{sid}, $sid2, 'SYN_REPLAY stream 2'); | |
161 is($frame->{headers}->{':status'}, 200, 'SYN_REPLAY status 2'); | |
162 is($frame->{headers}->{'x-header'}, 'X-Foo', 'SYN_REPLAY header 2'); | |
163 | |
164 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
165 ok($frame, 'DATA frame 2'); | |
166 is($frame->{sid}, $sid2, 'SYN_REPLAY stream 2'); | |
167 is($frame->{length}, length 'body', 'DATA length 2'); | |
168 is($frame->{data}, 'body', 'DATA payload 2'); | |
169 | |
170 # HEAD | |
171 | |
172 $sess = new_session(); | |
173 $sid1 = spdy_stream($sess, { path => '/s', method => 'HEAD' }); | |
174 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
175 | |
176 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
177 is($frame->{sid}, $sid1, 'SYN_REPLAY stream HEAD'); | |
178 is($frame->{headers}->{':status'}, 200, 'SYN_REPLAY status HEAD'); | |
179 is($frame->{headers}->{'x-header'}, 'X-Foo', 'SYN_REPLAY header HEAD'); | |
180 | |
181 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
182 is($frame, undef, 'HEAD no body'); | |
183 | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
184 # GET with PROXY protocol |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
185 |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
186 my $proxy = 'PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678' . CRLF; |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
187 $sess = new_session(8082, proxy => $proxy); |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
188 $sid1 = spdy_stream($sess, { path => '/pp' }); |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
189 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
190 |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
191 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
192 ok($frame, 'PROXY SYN_REPLAY frame'); |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
193 is($frame->{headers}->{'x-pp'}, '192.0.2.1', 'PROXY remote addr'); |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
194 |
374 | 195 # request header |
196 | |
197 $sess = new_session(); | |
198 $sid1 = spdy_stream($sess, { path => '/t1.html', | |
199 headers => { "range" => "bytes=10-19" } | |
200 }); | |
201 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
202 | |
203 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
204 is($frame->{headers}->{':status'}, 206, 'SYN_REPLAY status range'); | |
205 | |
206 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
207 is($frame->{length}, 10, 'DATA length range'); | |
208 is($frame->{data}, '002XXXX000', 'DATA payload range'); | |
209 | |
210 # $spdy | |
211 | |
212 $sess = new_session(); | |
213 $sid1 = spdy_stream($sess, { path => '/spdy' }); | |
214 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
215 | |
216 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
217 is($frame->{data}, '3.1', 'spdy variable'); | |
218 | |
219 # spdy_chunk_size=1 | |
220 | |
221 $sess = new_session(); | |
222 $sid1 = spdy_stream($sess, { path => '/chunk_size' }); | |
223 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
224 | |
225 my @data = grep { $_->{type} eq "DATA" } @$frames; | |
226 is(@data, 4, 'chunk_size body chunks'); | |
227 is($data[0]->{data}, 'b', 'chunk_size body 1'); | |
228 is($data[1]->{data}, 'o', 'chunk_size body 2'); | |
229 is($data[2]->{data}, 'd', 'chunk_size body 3'); | |
230 is($data[3]->{data}, 'y', 'chunk_size body 4'); | |
231 | |
232 # redirect | |
233 | |
234 $sess = new_session(); | |
235 $sid1 = spdy_stream($sess, { path => '/redirect' }); | |
236 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
237 | |
238 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
239 is($frame->{headers}->{':status'}, 405, 'SYN_REPLAY status with redirect'); | |
240 | |
241 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
242 ok($frame, 'DATA frame with redirect'); | |
243 is($frame->{data}, 'body', 'DATA payload with redirect'); | |
244 | |
428
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
245 # SYN_REPLY could be received with fin, followed by DATA |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
246 |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
247 $sess = new_session(); |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
248 $sid1 = spdy_stream($sess, { path => '/proxy/t2.html', method => 'HEAD' }); |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
249 |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
250 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
251 push @$frames, $_ for @{spdy_read($sess, all => [{ sid => $sid1 }])}; |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
252 ok(!grep ({ $_->{type} eq "DATA" } @$frames), 'proxy cache HEAD - no body'); |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
253 |
374 | 254 # ensure that HEAD-like requests, i.e., without response body, do not lead to |
255 # client connection close due to cache filling up with upstream response body | |
256 | |
257 TODO: { | |
258 local $TODO = 'premature client connection close'; | |
259 | |
260 $sid2 = spdy_stream($sess, { path => '/' }); | |
261 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
262 ok(grep ({ $_->{type} eq "SYN_REPLY" } @$frames), 'proxy cache headers only'); | |
263 | |
264 } | |
265 | |
428
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
266 # HEAD on empty cache with proxy_buffering off |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
267 |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
268 $sess = new_session(); |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
269 $sid1 = spdy_stream($sess, |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
270 { path => '/proxy_buffering_off/t2.html?1', method => 'HEAD' }); |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
271 |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
272 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
273 push @$frames, $_ for @{spdy_read($sess, all => [{ sid => $sid1 }])}; |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
274 ok(!grep ({ $_->{type} eq "DATA" } @$frames), |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
275 'proxy cache HEAD buffering off - no body'); |
e95c3340d94a
Tests: more SPDY tests for caching HEAD requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
427
diff
changeset
|
276 |
374 | 277 # simple proxy cache test |
278 | |
279 $sess = new_session(); | |
280 $sid1 = spdy_stream($sess, { path => '/proxy/t2.html' }); | |
281 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
282 | |
283 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
284 is($frame->{headers}->{':status'}, '200 OK', 'proxy cache unconditional'); | |
285 | |
286 $sid2 = spdy_stream($sess, { path => '/proxy/t2.html', | |
416
5c25acbc870a
Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
397
diff
changeset
|
287 headers => { "if-none-match" => $frame->{headers}->{'etag'} } |
374 | 288 }); |
289 $frames = spdy_read($sess, all => [{ sid => $sid2, fin => 1 }]); | |
290 | |
291 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
292 is($frame->{headers}->{':status'}, 304, 'proxy cache conditional'); | |
293 | |
294 # request body (uses proxied response) | |
295 | |
296 $sess = new_session(); | |
297 $sid1 = spdy_stream($sess, { path => '/proxy/t2.html', body => 'TEST' }); | |
298 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
299 | |
300 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
301 is($frame->{headers}->{'x-body'}, 'TEST', 'request body'); | |
302 | |
303 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
304 is($frame->{length}, length 'SEE-THIS', 'proxied response length'); | |
305 is($frame->{data}, 'SEE-THIS', 'proxied response'); | |
306 | |
307 # WINDOW_UPDATE (client side) | |
308 | |
309 $sess = new_session(); | |
310 $sid1 = spdy_stream($sess, { path => '/t1.html' }); | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
311 $frames = spdy_read($sess, all => [{ sid => $sid1, length => 2**16 }]); |
374 | 312 |
313 @data = grep { $_->{type} eq "DATA" } @$frames; | |
314 my $sum = eval join '+', map { $_->{length} } @data; | |
315 is($sum, 2**16, 'iws - stream blocked on initial window size'); | |
316 | |
317 spdy_ping($sess, 0xf00ff00f); | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
318 $frames = spdy_read($sess, all => [{ type => 'PING' }]); |
374 | 319 |
320 ($frame) = grep { $_->{type} eq "PING" } @$frames; | |
321 ok($frame, 'iws - PING not blocked'); | |
322 | |
323 spdy_window($sess, 2**16, $sid1); | |
324 $frames = spdy_read($sess); | |
325 is(@$frames, 0, 'iws - updated stream window'); | |
326 | |
327 spdy_window($sess, 2**16); | |
328 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
329 | |
330 @data = grep { $_->{type} eq "DATA" } @$frames; | |
331 $sum = eval join '+', map { $_->{length} } @data; | |
332 is($sum, 80, 'iws - updated connection window'); | |
333 | |
334 # SETTINGS (initial window size, client side) | |
335 | |
336 $sess = new_session(); | |
337 spdy_settings($sess, 7 => 2**17); | |
338 spdy_window($sess, 2**17); | |
339 | |
340 $sid1 = spdy_stream($sess, { path => '/t1.html' }); | |
341 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
342 | |
343 @data = grep { $_->{type} eq "DATA" } @$frames; | |
344 $sum = eval join '+', map { $_->{length} } @data; | |
345 is($sum, 2**16 + 80, 'increased initial window size'); | |
346 | |
347 # probe for negative available space in a flow control window | |
348 | |
349 $sess = new_session(); | |
350 $sid1 = spdy_stream($sess, { path => '/t1.html' }); | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
351 spdy_read($sess, all => [{ sid => $sid1, length => 2**16 }]); |
374 | 352 |
353 spdy_window($sess, 1); | |
354 spdy_settings($sess, 7 => 42); | |
355 spdy_window($sess, 1024, $sid1); | |
356 | |
357 $frames = spdy_read($sess); | |
358 is(@$frames, 0, 'negative window - no data'); | |
359 | |
360 spdy_window($sess, 2**16 - 42 - 1024, $sid1); | |
361 $frames = spdy_read($sess); | |
362 is(@$frames, 0, 'zero window - no data'); | |
363 | |
364 spdy_window($sess, 1, $sid1); | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
365 $frames = spdy_read($sess, all => [{ sid => $sid1, length => 1 }]); |
374 | 366 is(@$frames, 1, 'positive window - data'); |
367 is(@$frames[0]->{length}, 1, 'positive window - data length'); | |
368 | |
369 # stream multiplexing | |
370 | |
371 $sess = new_session(); | |
372 $sid1 = spdy_stream($sess, { path => '/t1.html' }); | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
373 $frames = spdy_read($sess, all => [{ sid => $sid1, length => 2**16 }]); |
374 | 374 |
375 @data = grep { $_->{type} eq "DATA" } @$frames; | |
376 $sum = eval join '+', map { $_->{length} } @data; | |
377 is($sum, 2**16, 'multiple - stream1 data'); | |
378 | |
379 $sid2 = spdy_stream($sess, { path => '/t1.html' }); | |
380 $frames = spdy_read($sess, all => [{ sid => $sid2, fin => 0 }]); | |
381 | |
382 @data = grep { $_->{type} eq "DATA" } @$frames; | |
383 is(@data, 0, 'multiple - stream2 no data'); | |
384 | |
385 spdy_window($sess, 2**17, $sid1); | |
386 spdy_window($sess, 2**17, $sid2); | |
387 spdy_window($sess, 2**17); | |
388 | |
389 $frames = spdy_read($sess, all => [ | |
390 { sid => $sid1, fin => 1 }, | |
391 { sid => $sid2, fin => 1 } | |
392 ]); | |
393 | |
394 @data = grep { $_->{type} eq "DATA" && $_->{sid} == $sid1 } @$frames; | |
395 $sum = eval join '+', map { $_->{length} } @data; | |
396 is($sum, 80, 'multiple - stream1 remain data'); | |
397 | |
398 @data = grep { $_->{type} eq "DATA" && $_->{sid} == $sid2 } @$frames; | |
399 $sum = eval join '+', map { $_->{length} } @data; | |
400 is($sum, 2**16 + 80, 'multiple - stream2 full data'); | |
401 | |
402 # request priority parsing in $spdy_request_priority | |
403 | |
404 $sess = new_session(); | |
405 $sid1 = spdy_stream($sess, { path => '/prio', prio => 0 }); | |
406 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
407 | |
408 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
409 is($frame->{data}, 0, 'priority 0'); | |
410 | |
411 $sid1 = spdy_stream($sess, { path => '/prio', prio => 1 }); | |
412 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
413 | |
414 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
415 is($frame->{data}, 1, 'priority 1'); | |
416 | |
417 $sid1 = spdy_stream($sess, { path => '/prio', prio => 7 }); | |
418 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
419 | |
420 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
421 is($frame->{data}, 7, 'priority 7'); | |
422 | |
423 # stream muliplexing + priority | |
424 | |
425 $sess = new_session(); | |
426 $sid1 = spdy_stream($sess, { path => '/t1.html', prio => 7 }); | |
427 $sid2 = spdy_stream($sess, { path => '/t2.html', prio => 0 }); | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
428 spdy_read($sess, all => [ |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
429 { sid => $sid1, length => 2**16 }, |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
430 { sid => $sid2, fin => 0 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
431 ]); |
374 | 432 |
433 spdy_window($sess, 2**17, $sid1); | |
434 spdy_window($sess, 2**17, $sid2); | |
435 spdy_window($sess, 2**17); | |
436 | |
437 $frames = spdy_read($sess, all => [ | |
438 { sid => $sid1, fin => 1 }, | |
439 { sid => $sid2, fin => 1 } | |
440 ]); | |
441 | |
442 @data = grep { $_->{type} eq "DATA" } @$frames; | |
443 is(join (' ', map { $_->{sid} } @data), "$sid2 $sid1", 'multiple priority 1'); | |
444 | |
445 # and vice versa | |
446 | |
447 $sess = new_session(); | |
448 $sid1 = spdy_stream($sess, { path => '/t1.html', prio => 0 }); | |
449 $sid2 = spdy_stream($sess, { path => '/t2.html', prio => 7 }); | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
450 spdy_read($sess, all => [ |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
451 { sid => $sid1, length => 2**16 }, |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
452 { sid => $sid2, fin => 0 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
453 ]); |
374 | 454 |
455 spdy_window($sess, 2**17, $sid1); | |
456 spdy_window($sess, 2**17, $sid2); | |
457 spdy_window($sess, 2**17); | |
458 | |
459 $frames = spdy_read($sess, all => [ | |
460 { sid => $sid1, fin => 1 }, | |
461 { sid => $sid2, fin => 1 } | |
462 ]); | |
463 | |
464 @data = grep { $_->{type} eq "DATA" } @$frames; | |
465 is(join (' ', map { $_->{sid} } @data), "$sid1 $sid2", 'multiple priority 2'); | |
466 | |
467 # limit_conn | |
468 | |
469 $sess = new_session(); | |
470 spdy_settings($sess, 7 => 1); | |
471 $sid1 = spdy_stream($sess, { path => '/t3.html' }); | |
472 $sid2 = spdy_stream($sess, { path => '/t3.html' }); | |
473 $frames = spdy_read($sess, all => [ | |
474 { sid => $sid1, fin => 0 }, | |
475 { sid => $sid2, fin => 0 } | |
476 ]); | |
477 | |
478 ($frame) = grep { $_->{type} eq "SYN_REPLY" && $_->{sid} == $sid1 } @$frames; | |
479 is($frame->{headers}->{':status'}, 200, 'conn_limit 1'); | |
480 | |
481 ($frame) = grep { $_->{type} eq "SYN_REPLY" && $_->{sid} == $sid2 } @$frames; | |
482 is($frame->{headers}->{':status'}, 503, 'conn_limit 2'); | |
483 | |
484 # limit_conn + client's RST_STREAM | |
485 | |
486 $sess = new_session(); | |
487 spdy_settings($sess, 7 => 1); | |
488 $sid1 = spdy_stream($sess, { path => '/t3.html' }); | |
489 spdy_rst($sess, $sid1, 5); | |
490 $sid2 = spdy_stream($sess, { path => '/t3.html' }); | |
491 $frames = spdy_read($sess, all => [ | |
492 { sid => $sid1, fin => 0 }, | |
493 { sid => $sid2, fin => 0 } | |
494 ]); | |
495 | |
496 ($frame) = grep { $_->{type} eq "SYN_REPLY" && $_->{sid} == $sid1 } @$frames; | |
497 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 1'); | |
498 | |
499 ($frame) = grep { $_->{type} eq "SYN_REPLY" && $_->{sid} == $sid2 } @$frames; | |
500 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 2'); | |
501 | |
502 # GOAWAY on SYN_STREAM with even StreamID | |
503 | |
504 TODO: { | |
505 local $TODO = 'not yet'; | |
506 | |
507 $sess = new_session(); | |
508 spdy_stream($sess, { path => '/s' }, 2); | |
509 $frames = spdy_read($sess); | |
510 | |
511 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
512 ok($frame, 'even stream - GOAWAY frame'); | |
513 is($frame->{code}, 1, 'even stream - error code'); | |
514 is($frame->{sid}, 0, 'even stream - last used stream'); | |
515 | |
516 } | |
517 | |
518 # GOAWAY on SYN_STREAM with backward StreamID | |
519 | |
520 TODO: { | |
521 local $TODO = 'not yet'; | |
522 | |
523 $sess = new_session(); | |
524 $sid1 = spdy_stream($sess, { path => '/s' }, 3); | |
525 spdy_read($sess); | |
526 | |
527 $sid2 = spdy_stream($sess, { path => '/s' }, 1); | |
528 $frames = spdy_read($sess); | |
529 | |
530 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
531 ok($frame, 'backward stream - GOAWAY frame'); | |
532 is($frame->{code}, 1, 'backward stream - error code'); | |
533 is($frame->{sid}, $sid1, 'backward stream - last used stream'); | |
534 | |
535 } | |
536 | |
537 # RST_STREAM on the second SYN_STREAM with same StreamID | |
538 | |
539 TODO: { | |
540 local $TODO = 'not yet'; | |
541 | |
542 $sess = new_session(); | |
543 $sid1 = spdy_stream($sess, { path => '/s' }, 3); | |
544 spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
545 $sid2 = spdy_stream($sess, { path => '/s' }, 3); | |
546 $frames = spdy_read($sess); | |
547 | |
548 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; | |
549 ok($frame, 'dup stream - RST_STREAM frame'); | |
550 is($frame->{code}, 1, 'dup stream - error code'); | |
551 is($frame->{sid}, $sid1, 'dup stream - stream'); | |
552 | |
553 } | |
554 | |
555 # awkward protocol version | |
556 | |
557 $sess = new_session(); | |
558 $sid1 = spdy_stream($sess, { path => '/s', version => 'HTTP/1.10' }); | |
559 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
560 | |
561 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
562 is($frame->{headers}->{':status'}, 200, 'awkward version'); | |
563 | |
564 # missing mandatory request header | |
565 | |
566 $sess = new_session(); | |
567 $sid1 = spdy_stream($sess, { path => '/s', version => '' }); | |
568 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
569 | |
570 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
571 is($frame->{headers}->{':status'}, 400, 'incomplete headers'); | |
572 | |
573 # GOAWAY before closing a connection by server | |
574 | |
575 $t->stop(); | |
576 | |
577 TODO: { | |
578 local $TODO = 'not yet'; | |
579 | |
580 $frames = spdy_read($sess); | |
581 | |
582 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
583 ok($frame, 'GOAWAY on connection close'); | |
584 | |
585 } | |
586 | |
587 ############################################################################### | |
588 | |
589 sub spdy_ping { | |
590 my ($sess, $payload) = @_; | |
591 | |
592 raw_write($sess->{socket}, pack("N3", 0x80030006, 0x4, $payload)); | |
593 } | |
594 | |
595 sub spdy_rst { | |
596 my ($sess, $sid, $error) = @_; | |
597 | |
598 raw_write($sess->{socket}, pack("N4", 0x80030003, 0x8, $sid, $error)); | |
599 } | |
600 | |
601 sub spdy_window { | |
602 my ($sess, $win, $stream) = @_; | |
603 | |
604 $stream = 0 unless defined $stream; | |
605 raw_write($sess->{socket}, pack("N4", 0x80030009, 8, $stream, $win)); | |
606 } | |
607 | |
608 sub spdy_settings { | |
609 my ($sess, %extra) = @_; | |
610 | |
611 my $cnt = keys %extra; | |
612 my $len = 4 + 8 * $cnt; | |
613 | |
614 my $buf = pack "N3", 0x80030004, $len, $cnt; | |
615 $buf .= join '', map { pack "N2", $_, $extra{$_} } keys %extra; | |
616 raw_write($sess->{socket}, $buf); | |
617 } | |
618 | |
619 sub spdy_read { | |
620 my ($sess, %extra) = @_; | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
621 my ($length, @got); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
622 my $s = $sess->{socket}; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
623 my $buf = ''; |
374 | 624 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
625 eval { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
626 local $SIG{ALRM} = sub { die "timeout\n" }; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
627 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
374 | 628 again: |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
629 alarm(1); |
374 | 630 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
631 $buf = raw_read($s, $buf, 8); |
379
f42de3a9fd74
Tests: avoid uninitialized warnings in spdy.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
377
diff
changeset
|
632 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
633 my $type = unpack("B", $buf); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
634 $length = 8 + hex unpack("x5 H6", $buf); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
635 $buf = raw_read($s, $buf, $length); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
636 |
374 | 637 if ($type == 0) { |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
638 push @got, dframe($buf); |
374 | 639 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
640 } else { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
641 my $ctype = unpack("x2 n", $buf); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
642 push @got, $cframe{$ctype}($sess, $buf); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
643 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
644 $buf = substr($buf, $length); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
645 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
646 goto again if test_fin($got[-1], $extra{all}); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
647 alarm(0); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
648 }; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
649 alarm(0); |
374 | 650 return \@got; |
651 } | |
652 | |
653 sub test_fin { | |
654 my ($frame, $all) = @_; | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
655 my @test = @{$all}; |
374 | 656 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
657 # wait for the specified DATA length |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
658 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
659 for (@test) { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
660 if ($_->{length} && $frame->{type} eq 'DATA') { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
661 # check also for StreamID if needed |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
662 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
663 if (!$_->{sid} || $_->{sid} == $frame->{sid}) { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
664 $_->{length} -= $frame->{length}; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
665 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
666 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
667 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
668 @test = grep { !(defined $_->{length} && $_->{length} == 0) } @test; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
669 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
670 # wait for the fin flag |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
671 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
672 @test = grep { !(defined $_->{fin} |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
673 && $_->{sid} == $frame->{sid} && $_->{fin} == $frame->{fin}) |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
674 } @test if defined $frame->{fin}; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
675 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
676 # wait for the specified frame |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
677 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
678 @test = grep { !($_->{type} && $_->{type} eq $frame->{type}) } @test; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
679 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
680 @{$all} = @test; |
374 | 681 } |
682 | |
683 sub dframe { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
684 my ($buf) = @_; |
374 | 685 my %frame; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
686 my $skip = 0; |
374 | 687 |
688 my $stream = unpack "\@$skip B32", $buf; $skip += 4; | |
689 substr($stream, 0, 1) = 0; | |
690 $stream = unpack("N", pack("B32", $stream)); | |
691 $frame{sid} = $stream; | |
692 | |
693 my $flags = unpack "\@$skip B8", $buf; $skip += 1; | |
694 $frame{fin} = substr($flags, 7, 1); | |
695 | |
696 my $length = hex (unpack "\@$skip H6", $buf); $skip += 3; | |
697 $frame{length} = $length; | |
698 | |
699 $frame{data} = substr($buf, $skip, $length); | |
700 $frame{type} = "DATA"; | |
701 return \%frame; | |
702 } | |
703 | |
704 sub spdy_stream { | |
705 my ($ctx, $uri, $stream) = @_; | |
706 my ($input, $output, $buf); | |
707 my ($d, $status); | |
708 | |
709 my $host = $uri->{host} || '127.0.0.1:8080'; | |
710 my $method = $uri->{method} || 'GET'; | |
711 my $headers = $uri->{headers} || {}; | |
712 my $body = $uri->{body}; | |
713 my $prio = defined $uri->{prio} ? $uri->{prio} : 4; | |
714 my $version = defined $uri->{version} ? $uri->{version} : "HTTP/1.1"; | |
715 | |
716 if ($stream) { | |
717 $ctx->{last_stream} = $stream; | |
718 } else { | |
719 $ctx->{last_stream} += 2; | |
720 } | |
721 | |
722 $buf = pack("NC", 0x80030001, not $body); | |
723 $buf .= pack("xxx"); # Length stub | |
724 $buf .= pack("N", $ctx->{last_stream}); # Stream-ID | |
725 $buf .= pack("N", 0); # Assoc. Stream-ID | |
726 $buf .= pack("n", $prio << 13); | |
727 | |
728 my $ent = 4 + keys %{$headers}; | |
729 $ent++ if $body; | |
730 $ent++ if $version; | |
731 | |
732 $input = pack("N", $ent); | |
733 $input .= hpack(":host", $host); | |
734 $input .= hpack(":method", $method); | |
735 $input .= hpack(":path", $uri->{path}); | |
736 $input .= hpack(":scheme", "http"); | |
737 if ($version) { | |
738 $input .= hpack(":version", $version); | |
739 } | |
740 if ($body) { | |
741 $input .= hpack("content-length", length $body); | |
742 } | |
743 $input .= join '', map { hpack($_, $headers->{$_}) } keys %{$headers}; | |
744 | |
745 $d = $ctx->{zlib}->{d}; | |
746 $status = $d->deflate($input => \my $start); | |
747 $status == Compress::Raw::Zlib->Z_OK or fail "deflate failed"; | |
748 $status = $d->flush(\my $tail => Compress::Raw::Zlib->Z_SYNC_FLUSH); | |
749 $status == Compress::Raw::Zlib->Z_OK or fail "flush failed"; | |
750 $output = $start . $tail; | |
751 | |
426
7cb6af00afdd
Tests: fixed SPDY tests with large header length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
425
diff
changeset
|
752 # set length, attach headers and optional body |
7cb6af00afdd
Tests: fixed SPDY tests with large header length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
425
diff
changeset
|
753 |
7cb6af00afdd
Tests: fixed SPDY tests with large header length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
425
diff
changeset
|
754 $buf |= pack "x4N", length($output) + 10; |
374 | 755 $buf .= $output; |
756 | |
757 if (defined $body) { | |
758 $buf .= pack "NCxn", $ctx->{last_stream}, 0x01, length $body; | |
759 $buf .= $body; | |
760 } | |
761 | |
762 raw_write($ctx->{socket}, $buf); | |
763 return $ctx->{last_stream}; | |
764 } | |
765 | |
766 sub syn_reply { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
767 my ($ctx, $buf) = @_; |
374 | 768 my ($i, $status); |
769 my %payload; | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
770 my $skip = 4; |
374 | 771 |
772 my $flags = unpack "\@$skip B8", $buf; $skip += 1; | |
773 $payload{fin} = substr($flags, 7, 1); | |
774 | |
775 my $length = hex unpack "\@$skip H6", $buf; $skip += 3; | |
776 $payload{length} = $length; | |
777 $payload{type} = 'SYN_REPLY'; | |
778 | |
779 my $stream = unpack "\@$skip B32", $buf; $skip += 4; | |
780 substr($stream, 0, 1) = 0; | |
781 $stream = unpack("N", pack("B32", $stream)); | |
782 $payload{sid} = $stream; | |
783 | |
784 my $input = substr($buf, $skip, $length - 4); | |
785 $i = $ctx->{zlib}->{i}; | |
786 | |
787 $status = $i->inflate($input => \my $out); | |
788 fail "Failed: $status" unless $status == Compress::Raw::Zlib->Z_OK; | |
789 $payload{headers} = hunpack($out); | |
790 return \%payload; | |
791 } | |
792 | |
793 sub rst_stream { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
794 my ($ctx, $buf) = @_; |
374 | 795 my %payload; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
796 my $skip = 5; |
374 | 797 |
798 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3; | |
799 $payload{type} = 'RST_STREAM'; | |
800 $payload{sid} = unpack "\@$skip N", $buf; $skip += 4; | |
801 $payload{code} = unpack "\@$skip N", $buf; | |
802 return \%payload; | |
803 } | |
804 | |
805 sub settings { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
806 my ($ctx, $buf) = @_; |
374 | 807 my %payload; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
808 my $skip = 4; |
374 | 809 |
810 $payload{flags} = unpack "\@$skip H", $buf; $skip += 1; | |
811 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3; | |
812 $payload{type} = 'SETTINGS'; | |
813 | |
814 my $nent = unpack "\@$skip N", $buf; $skip += 4; | |
815 for (1 .. $nent) { | |
816 my $flags = hex unpack "\@$skip H2", $buf; $skip += 1; | |
817 my $id = hex unpack "\@$skip H6", $buf; $skip += 3; | |
818 $payload{$id}{flags} = $flags; | |
819 $payload{$id}{value} = unpack "\@$skip N", $buf; $skip += 4; | |
820 } | |
821 return \%payload; | |
822 } | |
823 | |
824 sub ping { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
825 my ($ctx, $buf) = @_; |
374 | 826 my %payload; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
827 my $skip = 5; |
374 | 828 |
829 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3; | |
830 $payload{type} = 'PING'; | |
831 $payload{value} = unpack "\@$skip N", $buf; | |
832 return \%payload; | |
833 } | |
834 | |
835 sub goaway { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
836 my ($ctx, $buf) = @_; |
374 | 837 my %payload; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
838 my $skip = 5; |
374 | 839 |
840 $payload{length} = hex unpack "\@$skip H6", $buf; $skip += 3; | |
841 $payload{type} = 'GOAWAY'; | |
842 $payload{sid} = unpack "\@$skip N", $buf; $skip += 4; | |
843 $payload{code} = unpack "\@$skip N", $buf; | |
844 return \%payload; | |
845 } | |
846 | |
847 sub window_update { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
848 my ($ctx, $buf) = @_; |
374 | 849 my %payload; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
850 my $skip = 5; |
374 | 851 |
852 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3; | |
853 $payload{type} = 'WINDOW_UPDATE'; | |
854 | |
855 my $stream = unpack "\@$skip B32", $buf; $skip += 4; | |
856 substr($stream, 0, 1) = 0; | |
857 $stream = unpack("N", pack("B32", $stream)); | |
858 $payload{sid} = $stream; | |
859 | |
860 my $value = unpack "\@$skip B32", $buf; | |
861 substr($value, 0, 1) = 0; | |
862 $payload{wdelta} = unpack("N", pack("B32", $value)); | |
863 return \%payload; | |
864 } | |
865 | |
866 sub hpack { | |
867 my ($name, $value) = @_; | |
868 | |
869 pack("N", length($name)) . $name . pack("N", length($value)) . $value; | |
870 } | |
871 | |
872 sub hunpack { | |
873 my ($data) = @_; | |
874 my %headers; | |
875 my $skip = 0; | |
876 | |
877 my $nent = unpack "\@$skip N", $data; $skip += 4; | |
878 for (1 .. $nent) { | |
879 my $len = unpack("\@$skip N", $data); $skip += 4; | |
880 my $name = unpack("\@$skip A$len", $data); $skip += $len; | |
881 | |
882 $len = unpack("\@$skip N", $data); $skip += 4; | |
883 my $value = unpack("\@$skip A$len", $data); $skip += $len; | |
884 | |
885 $headers{$name} = $value; | |
886 } | |
887 return \%headers; | |
888 } | |
889 | |
890 sub raw_read { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
891 my ($s, $buf, $len) = @_; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
892 my $got = ''; |
374 | 893 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
894 while (length($buf) < $len) { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
895 $s->sysread($got, $len - length($buf)) or die; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
896 log_in($got); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
897 $buf .= $got; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
898 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
899 return $buf; |
374 | 900 } |
901 | |
902 sub raw_write { | |
903 my ($s, $message) = @_; | |
904 | |
905 local $SIG{PIPE} = 'IGNORE'; | |
906 | |
907 while (IO::Select->new($s)->can_write(0.4)) { | |
908 log_out($message); | |
909 my $n = $s->syswrite($message); | |
910 last unless $n; | |
911 $message = substr($message, $n); | |
912 last unless length $message; | |
913 } | |
914 } | |
915 | |
916 sub new_session { | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
917 my ($port, %extra) = @_; |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
918 my ($d, $i, $status, $s); |
374 | 919 |
920 ($d, $status) = Compress::Raw::Zlib::Deflate->new( | |
921 -WindowBits => 12, | |
922 -Dictionary => dictionary(), | |
923 -Level => Compress::Raw::Zlib->Z_NO_COMPRESSION | |
924 ); | |
925 fail "Zlib failure: $status" unless $d; | |
926 | |
927 ($i, $status) = Compress::Raw::Zlib::Inflate->new( | |
928 -WindowBits => Compress::Raw::Zlib->WANT_GZIP_OR_ZLIB, | |
929 -Dictionary => dictionary() | |
930 ); | |
931 fail "Zlib failure: $status" unless $i; | |
932 | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
933 $s = new_socket($port); |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
934 |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
935 if ($extra{proxy}) { |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
936 raw_write($s, $extra{proxy}); |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
937 } |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
938 |
374 | 939 return { zlib => { i => $i, d => $d }, |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
940 socket => $s, last_stream => -1 }; |
374 | 941 } |
942 | |
943 sub new_socket { | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
944 my ($port) = @_; |
374 | 945 my $s; |
946 | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
947 $port = 8080 unless defined $port; |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
948 |
374 | 949 eval { |
950 local $SIG{ALRM} = sub { die "timeout\n" }; | |
951 local $SIG{PIPE} = sub { die "sigpipe\n" }; | |
952 alarm(2); | |
953 $s = IO::Socket::INET->new( | |
954 Proto => 'tcp', | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
955 PeerAddr => "127.0.0.1:$port", |
374 | 956 ); |
957 alarm(0); | |
958 }; | |
959 alarm(0); | |
960 | |
961 if ($@) { | |
962 log_in("died: $@"); | |
963 return undef; | |
964 } | |
965 | |
966 return $s; | |
967 } | |
968 | |
969 sub dictionary { | |
970 join('', (map pack('N/a*', $_), qw( | |
971 options | |
972 head | |
973 post | |
974 put | |
975 delete | |
976 trace | |
977 accept | |
978 accept-charset | |
979 accept-encoding | |
980 accept-language | |
981 accept-ranges | |
982 age | |
983 allow | |
984 authorization | |
985 cache-control | |
986 connection | |
987 content-base | |
988 content-encoding | |
989 content-language | |
990 content-length | |
991 content-location | |
992 content-md5 | |
993 content-range | |
994 content-type | |
995 date | |
996 etag | |
997 expect | |
998 expires | |
999 from | |
1000 host | |
1001 if-match | |
1002 if-modified-since | |
1003 if-none-match | |
1004 if-range | |
1005 if-unmodified-since | |
1006 last-modified | |
1007 location | |
1008 max-forwards | |
1009 pragma | |
1010 proxy-authenticate | |
1011 proxy-authorization | |
1012 range | |
1013 referer | |
1014 retry-after | |
1015 server | |
1016 te | |
1017 trailer | |
1018 transfer-encoding | |
1019 upgrade | |
1020 user-agent | |
1021 vary | |
1022 via | |
1023 warning | |
1024 www-authenticate | |
1025 method | |
1026 get | |
1027 status), "200 OK", | |
1028 qw(version HTTP/1.1 url public set-cookie keep-alive origin)), | |
1029 "100101201202205206300302303304305306307402405406407408409410", | |
1030 "411412413414415416417502504505", | |
1031 "203 Non-Authoritative Information", | |
1032 "204 No Content", | |
1033 "301 Moved Permanently", | |
1034 "400 Bad Request", | |
1035 "401 Unauthorized", | |
1036 "403 Forbidden", | |
1037 "404 Not Found", | |
1038 "500 Internal Server Error", | |
1039 "501 Not Implemented", | |
1040 "503 Service Unavailable", | |
1041 "Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec", | |
1042 " 00:00:00", | |
1043 " Mon, Tue, Wed, Thu, Fri, Sat, Sun, GMT", | |
1044 "chunked,text/html,image/png,image/jpg,image/gif,", | |
1045 "application/xml,application/xhtml+xml,text/plain,", | |
1046 "text/javascript,public", "privatemax-age=gzip,deflate,", | |
1047 "sdchcharset=utf-8charset=iso-8859-1,utf-,*,enq=0." | |
1048 ); | |
1049 } | |
1050 | |
1051 ############################################################################### |