Mercurial > hg > nginx-tests
annotate spdy.t @ 442:cc4697d6bd16
Tests: added SPDY tests for header field with multiple values.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 24 Jul 2014 21:57:24 +0400 |
parents | 89f7a882d692 |
children | d1c4b0d15484 |
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 => '/' }); | |
308 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
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 | |
531 # limit_conn + client's RST_STREAM | |
532 | |
533 $sess = new_session(); | |
534 spdy_settings($sess, 7 => 1); | |
535 $sid1 = spdy_stream($sess, { path => '/t3.html' }); | |
536 spdy_rst($sess, $sid1, 5); | |
537 $sid2 = spdy_stream($sess, { path => '/t3.html' }); | |
538 $frames = spdy_read($sess, all => [ | |
539 { sid => $sid1, fin => 0 }, | |
540 { sid => $sid2, fin => 0 } | |
541 ]); | |
542 | |
543 ($frame) = grep { $_->{type} eq "SYN_REPLY" && $_->{sid} == $sid1 } @$frames; | |
544 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 1'); | |
545 | |
546 ($frame) = grep { $_->{type} eq "SYN_REPLY" && $_->{sid} == $sid2 } @$frames; | |
547 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 2'); | |
548 | |
549 # GOAWAY on SYN_STREAM with even StreamID | |
550 | |
551 TODO: { | |
552 local $TODO = 'not yet'; | |
553 | |
554 $sess = new_session(); | |
555 spdy_stream($sess, { path => '/s' }, 2); | |
556 $frames = spdy_read($sess); | |
557 | |
558 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
559 ok($frame, 'even stream - GOAWAY frame'); | |
560 is($frame->{code}, 1, 'even stream - error code'); | |
561 is($frame->{sid}, 0, 'even stream - last used stream'); | |
562 | |
563 } | |
564 | |
565 # GOAWAY on SYN_STREAM with backward StreamID | |
566 | |
567 TODO: { | |
568 local $TODO = 'not yet'; | |
569 | |
570 $sess = new_session(); | |
571 $sid1 = spdy_stream($sess, { path => '/s' }, 3); | |
572 spdy_read($sess); | |
573 | |
574 $sid2 = spdy_stream($sess, { path => '/s' }, 1); | |
575 $frames = spdy_read($sess); | |
576 | |
577 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
578 ok($frame, 'backward stream - GOAWAY frame'); | |
579 is($frame->{code}, 1, 'backward stream - error code'); | |
580 is($frame->{sid}, $sid1, 'backward stream - last used stream'); | |
581 | |
582 } | |
583 | |
584 # RST_STREAM on the second SYN_STREAM with same StreamID | |
585 | |
586 TODO: { | |
587 local $TODO = 'not yet'; | |
588 | |
589 $sess = new_session(); | |
590 $sid1 = spdy_stream($sess, { path => '/s' }, 3); | |
591 spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
592 $sid2 = spdy_stream($sess, { path => '/s' }, 3); | |
593 $frames = spdy_read($sess); | |
594 | |
595 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; | |
596 ok($frame, 'dup stream - RST_STREAM frame'); | |
597 is($frame->{code}, 1, 'dup stream - error code'); | |
598 is($frame->{sid}, $sid1, 'dup stream - stream'); | |
599 | |
600 } | |
601 | |
602 # awkward protocol version | |
603 | |
604 $sess = new_session(); | |
605 $sid1 = spdy_stream($sess, { path => '/s', version => 'HTTP/1.10' }); | |
606 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
607 | |
608 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
609 is($frame->{headers}->{':status'}, 200, 'awkward version'); | |
610 | |
611 # missing mandatory request header | |
612 | |
613 $sess = new_session(); | |
614 $sid1 = spdy_stream($sess, { path => '/s', version => '' }); | |
615 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
616 | |
617 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
618 is($frame->{headers}->{':status'}, 400, 'incomplete headers'); | |
619 | |
620 # GOAWAY before closing a connection by server | |
621 | |
622 $t->stop(); | |
623 | |
624 TODO: { | |
625 local $TODO = 'not yet'; | |
626 | |
627 $frames = spdy_read($sess); | |
628 | |
629 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
630 ok($frame, 'GOAWAY on connection close'); | |
631 | |
632 } | |
633 | |
634 ############################################################################### | |
635 | |
636 sub spdy_ping { | |
637 my ($sess, $payload) = @_; | |
638 | |
639 raw_write($sess->{socket}, pack("N3", 0x80030006, 0x4, $payload)); | |
640 } | |
641 | |
642 sub spdy_rst { | |
643 my ($sess, $sid, $error) = @_; | |
644 | |
645 raw_write($sess->{socket}, pack("N4", 0x80030003, 0x8, $sid, $error)); | |
646 } | |
647 | |
648 sub spdy_window { | |
649 my ($sess, $win, $stream) = @_; | |
650 | |
651 $stream = 0 unless defined $stream; | |
652 raw_write($sess->{socket}, pack("N4", 0x80030009, 8, $stream, $win)); | |
653 } | |
654 | |
655 sub spdy_settings { | |
656 my ($sess, %extra) = @_; | |
657 | |
658 my $cnt = keys %extra; | |
659 my $len = 4 + 8 * $cnt; | |
660 | |
661 my $buf = pack "N3", 0x80030004, $len, $cnt; | |
662 $buf .= join '', map { pack "N2", $_, $extra{$_} } keys %extra; | |
663 raw_write($sess->{socket}, $buf); | |
664 } | |
665 | |
666 sub spdy_read { | |
667 my ($sess, %extra) = @_; | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
668 my ($length, @got); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
669 my $s = $sess->{socket}; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
670 my $buf = ''; |
374 | 671 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
672 eval { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
673 local $SIG{ALRM} = sub { die "timeout\n" }; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
674 local $SIG{PIPE} = sub { die "sigpipe\n" }; |
374 | 675 again: |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
676 alarm(1); |
374 | 677 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
678 $buf = raw_read($s, $buf, 8); |
379
f42de3a9fd74
Tests: avoid uninitialized warnings in spdy.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
377
diff
changeset
|
679 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
680 my $type = unpack("B", $buf); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
681 $length = 8 + hex unpack("x5 H6", $buf); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
682 $buf = raw_read($s, $buf, $length); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
683 |
374 | 684 if ($type == 0) { |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
685 push @got, dframe($buf); |
374 | 686 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
687 } else { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
688 my $ctype = unpack("x2 n", $buf); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
689 push @got, $cframe{$ctype}($sess, $buf); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
690 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
691 $buf = substr($buf, $length); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
692 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
693 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
|
694 alarm(0); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
695 }; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
696 alarm(0); |
374 | 697 return \@got; |
698 } | |
699 | |
700 sub test_fin { | |
701 my ($frame, $all) = @_; | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
702 my @test = @{$all}; |
374 | 703 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
704 # wait for the specified DATA length |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
705 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
706 for (@test) { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
707 if ($_->{length} && $frame->{type} eq 'DATA') { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
708 # check also for StreamID if needed |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
709 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
710 if (!$_->{sid} || $_->{sid} == $frame->{sid}) { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
711 $_->{length} -= $frame->{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 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
714 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
715 @test = grep { !(defined $_->{length} && $_->{length} == 0) } @test; |
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 # wait for the fin flag |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
718 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
719 @test = grep { !(defined $_->{fin} |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
720 && $_->{sid} == $frame->{sid} && $_->{fin} == $frame->{fin}) |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
721 } @test if defined $frame->{fin}; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
722 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
723 # wait for the specified frame |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
724 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
725 @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
|
726 |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
727 @{$all} = @test; |
374 | 728 } |
729 | |
730 sub dframe { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
731 my ($buf) = @_; |
374 | 732 my %frame; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
733 my $skip = 0; |
374 | 734 |
735 my $stream = unpack "\@$skip B32", $buf; $skip += 4; | |
736 substr($stream, 0, 1) = 0; | |
737 $stream = unpack("N", pack("B32", $stream)); | |
738 $frame{sid} = $stream; | |
739 | |
740 my $flags = unpack "\@$skip B8", $buf; $skip += 1; | |
741 $frame{fin} = substr($flags, 7, 1); | |
742 | |
743 my $length = hex (unpack "\@$skip H6", $buf); $skip += 3; | |
744 $frame{length} = $length; | |
745 | |
746 $frame{data} = substr($buf, $skip, $length); | |
747 $frame{type} = "DATA"; | |
748 return \%frame; | |
749 } | |
750 | |
751 sub spdy_stream { | |
752 my ($ctx, $uri, $stream) = @_; | |
753 my ($input, $output, $buf); | |
754 my ($d, $status); | |
755 | |
756 my $host = $uri->{host} || '127.0.0.1:8080'; | |
757 my $method = $uri->{method} || 'GET'; | |
758 my $headers = $uri->{headers} || {}; | |
759 my $body = $uri->{body}; | |
760 my $prio = defined $uri->{prio} ? $uri->{prio} : 4; | |
761 my $version = defined $uri->{version} ? $uri->{version} : "HTTP/1.1"; | |
762 | |
763 if ($stream) { | |
764 $ctx->{last_stream} = $stream; | |
765 } else { | |
766 $ctx->{last_stream} += 2; | |
767 } | |
768 | |
769 $buf = pack("NC", 0x80030001, not $body); | |
770 $buf .= pack("xxx"); # Length stub | |
771 $buf .= pack("N", $ctx->{last_stream}); # Stream-ID | |
772 $buf .= pack("N", 0); # Assoc. Stream-ID | |
773 $buf .= pack("n", $prio << 13); | |
774 | |
775 my $ent = 4 + keys %{$headers}; | |
776 $ent++ if $body; | |
777 $ent++ if $version; | |
778 | |
779 $input = pack("N", $ent); | |
780 $input .= hpack(":host", $host); | |
781 $input .= hpack(":method", $method); | |
782 $input .= hpack(":path", $uri->{path}); | |
783 $input .= hpack(":scheme", "http"); | |
784 if ($version) { | |
785 $input .= hpack(":version", $version); | |
786 } | |
787 if ($body) { | |
788 $input .= hpack("content-length", length $body); | |
789 } | |
790 $input .= join '', map { hpack($_, $headers->{$_}) } keys %{$headers}; | |
791 | |
792 $d = $ctx->{zlib}->{d}; | |
793 $status = $d->deflate($input => \my $start); | |
794 $status == Compress::Raw::Zlib->Z_OK or fail "deflate failed"; | |
795 $status = $d->flush(\my $tail => Compress::Raw::Zlib->Z_SYNC_FLUSH); | |
796 $status == Compress::Raw::Zlib->Z_OK or fail "flush failed"; | |
797 $output = $start . $tail; | |
798 | |
426
7cb6af00afdd
Tests: fixed SPDY tests with large header length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
425
diff
changeset
|
799 # 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
|
800 |
7cb6af00afdd
Tests: fixed SPDY tests with large header length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
425
diff
changeset
|
801 $buf |= pack "x4N", length($output) + 10; |
374 | 802 $buf .= $output; |
803 | |
804 if (defined $body) { | |
805 $buf .= pack "NCxn", $ctx->{last_stream}, 0x01, length $body; | |
806 $buf .= $body; | |
807 } | |
808 | |
809 raw_write($ctx->{socket}, $buf); | |
810 return $ctx->{last_stream}; | |
811 } | |
812 | |
813 sub syn_reply { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
814 my ($ctx, $buf) = @_; |
374 | 815 my ($i, $status); |
816 my %payload; | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
817 my $skip = 4; |
374 | 818 |
819 my $flags = unpack "\@$skip B8", $buf; $skip += 1; | |
820 $payload{fin} = substr($flags, 7, 1); | |
821 | |
822 my $length = hex unpack "\@$skip H6", $buf; $skip += 3; | |
823 $payload{length} = $length; | |
824 $payload{type} = 'SYN_REPLY'; | |
825 | |
826 my $stream = unpack "\@$skip B32", $buf; $skip += 4; | |
827 substr($stream, 0, 1) = 0; | |
828 $stream = unpack("N", pack("B32", $stream)); | |
829 $payload{sid} = $stream; | |
830 | |
831 my $input = substr($buf, $skip, $length - 4); | |
832 $i = $ctx->{zlib}->{i}; | |
833 | |
834 $status = $i->inflate($input => \my $out); | |
835 fail "Failed: $status" unless $status == Compress::Raw::Zlib->Z_OK; | |
836 $payload{headers} = hunpack($out); | |
837 return \%payload; | |
838 } | |
839 | |
840 sub rst_stream { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
841 my ($ctx, $buf) = @_; |
374 | 842 my %payload; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
843 my $skip = 5; |
374 | 844 |
845 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3; | |
846 $payload{type} = 'RST_STREAM'; | |
847 $payload{sid} = unpack "\@$skip N", $buf; $skip += 4; | |
848 $payload{code} = unpack "\@$skip N", $buf; | |
849 return \%payload; | |
850 } | |
851 | |
852 sub settings { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
853 my ($ctx, $buf) = @_; |
374 | 854 my %payload; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
855 my $skip = 4; |
374 | 856 |
857 $payload{flags} = unpack "\@$skip H", $buf; $skip += 1; | |
858 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3; | |
859 $payload{type} = 'SETTINGS'; | |
860 | |
861 my $nent = unpack "\@$skip N", $buf; $skip += 4; | |
862 for (1 .. $nent) { | |
863 my $flags = hex unpack "\@$skip H2", $buf; $skip += 1; | |
864 my $id = hex unpack "\@$skip H6", $buf; $skip += 3; | |
865 $payload{$id}{flags} = $flags; | |
866 $payload{$id}{value} = unpack "\@$skip N", $buf; $skip += 4; | |
867 } | |
868 return \%payload; | |
869 } | |
870 | |
871 sub ping { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
872 my ($ctx, $buf) = @_; |
374 | 873 my %payload; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
874 my $skip = 5; |
374 | 875 |
876 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3; | |
877 $payload{type} = 'PING'; | |
878 $payload{value} = unpack "\@$skip N", $buf; | |
879 return \%payload; | |
880 } | |
881 | |
882 sub goaway { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
883 my ($ctx, $buf) = @_; |
374 | 884 my %payload; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
885 my $skip = 5; |
374 | 886 |
887 $payload{length} = hex unpack "\@$skip H6", $buf; $skip += 3; | |
888 $payload{type} = 'GOAWAY'; | |
889 $payload{sid} = unpack "\@$skip N", $buf; $skip += 4; | |
890 $payload{code} = unpack "\@$skip N", $buf; | |
891 return \%payload; | |
892 } | |
893 | |
894 sub window_update { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
895 my ($ctx, $buf) = @_; |
374 | 896 my %payload; |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
897 my $skip = 5; |
374 | 898 |
899 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3; | |
900 $payload{type} = 'WINDOW_UPDATE'; | |
901 | |
902 my $stream = unpack "\@$skip B32", $buf; $skip += 4; | |
903 substr($stream, 0, 1) = 0; | |
904 $stream = unpack("N", pack("B32", $stream)); | |
905 $payload{sid} = $stream; | |
906 | |
907 my $value = unpack "\@$skip B32", $buf; | |
908 substr($value, 0, 1) = 0; | |
909 $payload{wdelta} = unpack("N", pack("B32", $value)); | |
910 return \%payload; | |
911 } | |
912 | |
913 sub hpack { | |
914 my ($name, $value) = @_; | |
915 | |
916 pack("N", length($name)) . $name . pack("N", length($value)) . $value; | |
917 } | |
918 | |
919 sub hunpack { | |
920 my ($data) = @_; | |
921 my %headers; | |
922 my $skip = 0; | |
923 | |
924 my $nent = unpack "\@$skip N", $data; $skip += 4; | |
925 for (1 .. $nent) { | |
926 my $len = unpack("\@$skip N", $data); $skip += 4; | |
927 my $name = unpack("\@$skip A$len", $data); $skip += $len; | |
928 | |
929 $len = unpack("\@$skip N", $data); $skip += 4; | |
930 my $value = unpack("\@$skip A$len", $data); $skip += $len; | |
931 | |
932 $headers{$name} = $value; | |
933 } | |
934 return \%headers; | |
935 } | |
936 | |
937 sub raw_read { | |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
938 my ($s, $buf, $len) = @_; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
939 my $got = ''; |
374 | 940 |
425
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
941 while (length($buf) < $len) { |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
942 $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
|
943 log_in($got); |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
944 $buf .= $got; |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
945 } |
cc7da696a330
Tests: reduced execution time of SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
416
diff
changeset
|
946 return $buf; |
374 | 947 } |
948 | |
949 sub raw_write { | |
950 my ($s, $message) = @_; | |
951 | |
952 local $SIG{PIPE} = 'IGNORE'; | |
953 | |
954 while (IO::Select->new($s)->can_write(0.4)) { | |
955 log_out($message); | |
956 my $n = $s->syswrite($message); | |
957 last unless $n; | |
958 $message = substr($message, $n); | |
959 last unless length $message; | |
960 } | |
961 } | |
962 | |
963 sub new_session { | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
964 my ($port, %extra) = @_; |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
965 my ($d, $i, $status, $s); |
374 | 966 |
967 ($d, $status) = Compress::Raw::Zlib::Deflate->new( | |
968 -WindowBits => 12, | |
969 -Dictionary => dictionary(), | |
970 -Level => Compress::Raw::Zlib->Z_NO_COMPRESSION | |
971 ); | |
972 fail "Zlib failure: $status" unless $d; | |
973 | |
974 ($i, $status) = Compress::Raw::Zlib::Inflate->new( | |
975 -WindowBits => Compress::Raw::Zlib->WANT_GZIP_OR_ZLIB, | |
976 -Dictionary => dictionary() | |
977 ); | |
978 fail "Zlib failure: $status" unless $i; | |
979 | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
980 $s = new_socket($port); |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
981 |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
982 if ($extra{proxy}) { |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
983 raw_write($s, $extra{proxy}); |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
984 } |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
985 |
374 | 986 return { zlib => { i => $i, d => $d }, |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
987 socket => $s, last_stream => -1 }; |
374 | 988 } |
989 | |
990 sub new_socket { | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
991 my ($port) = @_; |
374 | 992 my $s; |
993 | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
994 $port = 8080 unless defined $port; |
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
995 |
374 | 996 eval { |
997 local $SIG{ALRM} = sub { die "timeout\n" }; | |
998 local $SIG{PIPE} = sub { die "sigpipe\n" }; | |
999 alarm(2); | |
1000 $s = IO::Socket::INET->new( | |
1001 Proto => 'tcp', | |
427
daea9cf92c14
Tests: added proxy protocol tests over SPDY.
Sergey Kandaurov <pluknet@nginx.com>
parents:
426
diff
changeset
|
1002 PeerAddr => "127.0.0.1:$port", |
374 | 1003 ); |
1004 alarm(0); | |
1005 }; | |
1006 alarm(0); | |
1007 | |
1008 if ($@) { | |
1009 log_in("died: $@"); | |
1010 return undef; | |
1011 } | |
1012 | |
1013 return $s; | |
1014 } | |
1015 | |
1016 sub dictionary { | |
1017 join('', (map pack('N/a*', $_), qw( | |
1018 options | |
1019 head | |
1020 post | |
1021 put | |
1022 delete | |
1023 trace | |
1024 accept | |
1025 accept-charset | |
1026 accept-encoding | |
1027 accept-language | |
1028 accept-ranges | |
1029 age | |
1030 allow | |
1031 authorization | |
1032 cache-control | |
1033 connection | |
1034 content-base | |
1035 content-encoding | |
1036 content-language | |
1037 content-length | |
1038 content-location | |
1039 content-md5 | |
1040 content-range | |
1041 content-type | |
1042 date | |
1043 etag | |
1044 expect | |
1045 expires | |
1046 from | |
1047 host | |
1048 if-match | |
1049 if-modified-since | |
1050 if-none-match | |
1051 if-range | |
1052 if-unmodified-since | |
1053 last-modified | |
1054 location | |
1055 max-forwards | |
1056 pragma | |
1057 proxy-authenticate | |
1058 proxy-authorization | |
1059 range | |
1060 referer | |
1061 retry-after | |
1062 server | |
1063 te | |
1064 trailer | |
1065 transfer-encoding | |
1066 upgrade | |
1067 user-agent | |
1068 vary | |
1069 via | |
1070 warning | |
1071 www-authenticate | |
1072 method | |
1073 get | |
1074 status), "200 OK", | |
1075 qw(version HTTP/1.1 url public set-cookie keep-alive origin)), | |
1076 "100101201202205206300302303304305306307402405406407408409410", | |
1077 "411412413414415416417502504505", | |
1078 "203 Non-Authoritative Information", | |
1079 "204 No Content", | |
1080 "301 Moved Permanently", | |
1081 "400 Bad Request", | |
1082 "401 Unauthorized", | |
1083 "403 Forbidden", | |
1084 "404 Not Found", | |
1085 "500 Internal Server Error", | |
1086 "501 Not Implemented", | |
1087 "503 Service Unavailable", | |
1088 "Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec", | |
1089 " 00:00:00", | |
1090 " Mon, Tue, Wed, Thu, Fri, Sat, Sun, GMT", | |
1091 "chunked,text/html,image/png,image/jpg,image/gif,", | |
1092 "application/xml,application/xhtml+xml,text/plain,", | |
1093 "text/javascript,public", "privatemax-age=gzip,deflate,", | |
1094 "sdchcharset=utf-8charset=iso-8859-1,utf-,*,enq=0." | |
1095 ); | |
1096 } | |
1097 | |
1098 ############################################################################### |