Mercurial > hg > nginx-tests
comparison h2_fastcgi_request_buffering.t @ 948:4dc302d8e04f
Tests: changed HTTP2 package to act as a class.
Stopped exporting any subroutines. A subset of them now act as class methods.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 17 Jun 2016 11:36:33 +0300 |
parents | d73bef563aea |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
947:b9e42c554ba7 | 948:4dc302d8e04f |
---|---|
14 | 14 |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | 15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
16 | 16 |
17 use lib 'lib'; | 17 use lib 'lib'; |
18 use Test::Nginx; | 18 use Test::Nginx; |
19 use Test::Nginx::HTTP2 qw/ :DEFAULT :frame :io /; | 19 use Test::Nginx::HTTP2; |
20 | 20 |
21 ############################################################################### | 21 ############################################################################### |
22 | 22 |
23 select STDERR; $| = 1; | 23 select STDERR; $| = 1; |
24 select STDOUT; $| = 1; | 24 select STDOUT; $| = 1; |
195 Timeout => 3, | 195 Timeout => 3, |
196 Reuse => 1 | 196 Reuse => 1 |
197 ) | 197 ) |
198 or die "Can't create listening socket: $!\n"; | 198 or die "Can't create listening socket: $!\n"; |
199 | 199 |
200 my $sess = new_session(8080); | 200 my $s = Test::Nginx::HTTP2->new(); |
201 my $sid = exists $extra{'content-length'} | 201 my $sid = exists $extra{'content-length'} |
202 ? new_stream($sess, { headers => [ | 202 ? $s->new_stream({ headers => [ |
203 { name => ':method', value => 'GET' }, | 203 { name => ':method', value => 'GET' }, |
204 { name => ':scheme', value => 'http' }, | 204 { name => ':scheme', value => 'http' }, |
205 { name => ':path', value => $url, }, | 205 { name => ':path', value => $url, }, |
206 { name => ':authority', value => 'localhost' }, | 206 { name => ':authority', value => 'localhost' }, |
207 { name => 'content-length', | 207 { name => 'content-length', |
208 value => $extra{'content-length'} }], | 208 value => $extra{'content-length'} }], |
209 body_more => 1 }) | 209 body_more => 1 }) |
210 : new_stream($sess, { path => $url, body_more => 1 }); | 210 : $s->new_stream({ path => $url, body_more => 1 }); |
211 | 211 |
212 $client = $server->accept() or return; | 212 $client = $server->accept() or return; |
213 | 213 |
214 log2c("(new connection $client)"); | 214 log2c("(new connection $client)"); |
215 | 215 |
216 $f->{headers} = raw_read($client, '', 1, \&log2i); | 216 $f->{headers} = backend_read($client); |
217 | 217 |
218 my $h = fastcgi_read_record(\$f->{headers}); | 218 my $h = fastcgi_read_record(\$f->{headers}); |
219 my $version = $h->{version}; | 219 my $version = $h->{version}; |
220 my $id = $h->{id}; | 220 my $id = $h->{id}; |
221 | 221 |
222 $f->{upload} = sub { | 222 $f->{upload} = sub { |
223 my ($body, %extra) = @_; | 223 my ($body, %extra) = @_; |
224 my $len = length($body); | 224 my $len = length($body); |
225 my $wait = $extra{wait}; | 225 my $wait = $extra{wait}; |
226 | 226 |
227 h2_body($sess, $body, { %extra }); | 227 $s->h2_body($body, { %extra }); |
228 | 228 |
229 $body = ''; | 229 $body = ''; |
230 | 230 |
231 for (1 .. 10) { | 231 for (1 .. 10) { |
232 my $buf = raw_read($client, '', 1, \&log2i, $wait) | 232 my $buf = backend_read($client, $wait) or return ''; |
233 or return ''; | |
234 | 233 |
235 while (my $h = fastcgi_read_record(\$buf)) { | 234 while (my $h = fastcgi_read_record(\$buf)) { |
236 | 235 |
237 # skip everything unless stdin | 236 # skip everything unless stdin |
238 next if $h->{type} != 5; | 237 next if $h->{type} != 5; |
258 OK | 257 OK |
259 EOF | 258 EOF |
260 | 259 |
261 $client->close; | 260 $client->close; |
262 | 261 |
263 my $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 262 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
264 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 263 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
265 return $frame->{headers}->{':status'}; | 264 return $frame->{headers}->{':status'}; |
266 }; | 265 }; |
267 return $f; | 266 return $f; |
268 } | 267 } |
269 | 268 |
269 sub backend_read { | |
270 my ($s, $timo) = @_; | |
271 my $buf = ''; | |
272 | |
273 if (IO::Select->new($s)->can_read($timo || 3)) { | |
274 $s->sysread($buf, 16384) or return; | |
275 log2i($buf); | |
276 } | |
277 return $buf; | |
278 } | |
279 | |
270 sub log2i { Test::Nginx::log_core('|| <<', @_); } | 280 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
271 sub log2o { Test::Nginx::log_core('|| >>', @_); } | 281 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
272 sub log2c { Test::Nginx::log_core('||', @_); } | 282 sub log2c { Test::Nginx::log_core('||', @_); } |
273 | 283 |
274 ############################################################################### | 284 ############################################################################### |