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