Mercurial > hg > nginx-tests
comparison h2_proxy_request_buffering_ssl.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 |
---|---|
16 | 16 |
17 BEGIN { use FindBin; chdir($FindBin::Bin); } | 17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
18 | 18 |
19 use lib 'lib'; | 19 use lib 'lib'; |
20 use Test::Nginx; | 20 use Test::Nginx; |
21 use Test::Nginx::HTTP2 qw/ :DEFAULT :frame :io /; | 21 use Test::Nginx::HTTP2; |
22 | 22 |
23 ############################################################################### | 23 ############################################################################### |
24 | 24 |
25 select STDERR; $| = 1; | 25 select STDERR; $| = 1; |
26 select STDOUT; $| = 1; | 26 select STDOUT; $| = 1; |
199 Timeout => 3, | 199 Timeout => 3, |
200 Reuse => 1 | 200 Reuse => 1 |
201 ) | 201 ) |
202 or die "Can't create listening socket: $!\n"; | 202 or die "Can't create listening socket: $!\n"; |
203 | 203 |
204 my $sess = new_session(8080); | 204 my $s = Test::Nginx::HTTP2->new(); |
205 my $sid = exists $extra{'content-length'} | 205 my $sid = exists $extra{'content-length'} |
206 ? new_stream($sess, { headers => [ | 206 ? $s->new_stream({ headers => [ |
207 { name => ':method', value => 'GET' }, | 207 { name => ':method', value => 'GET' }, |
208 { name => ':scheme', value => 'http' }, | 208 { name => ':scheme', value => 'http' }, |
209 { name => ':path', value => $url, }, | 209 { name => ':path', value => $url, }, |
210 { name => ':authority', value => 'localhost' }, | 210 { name => ':authority', value => 'localhost' }, |
211 { name => 'content-length', | 211 { name => 'content-length', |
212 value => $extra{'content-length'} }], | 212 value => $extra{'content-length'} }], |
213 body_more => 1 }) | 213 body_more => 1 }) |
214 : new_stream($sess, { path => $url, body_more => 1 }); | 214 : $s->new_stream({ path => $url, body_more => 1 }); |
215 | 215 |
216 $client = $server->accept() or return; | 216 $client = $server->accept() or return; |
217 | 217 |
218 log2c("(new connection $client)"); | 218 log2c("(new connection $client)"); |
219 | 219 |
220 $f->{headers} = raw_read($client, '', 1, \&log2i); | 220 $f->{headers} = backend_read($client); |
221 | 221 |
222 my $chunked = $f->{headers} =~ /chunked/; | 222 my $chunked = $f->{headers} =~ /chunked/; |
223 | 223 |
224 my $body_read = sub { | 224 $f->{upload} = sub { |
225 my ($s, $buf, $len, $wait) = @_; | 225 my ($body, %extra) = @_; |
226 my $len = length($body); | |
227 my $wait = $extra{wait}; | |
228 | |
229 $s->h2_body($body, { %extra }); | |
230 | |
231 $body = ''; | |
226 | 232 |
227 for (1 .. 10) { | 233 for (1 .. 10) { |
228 $buf = raw_read($s, $buf, length($buf) + 1, \&log2i, | 234 my $buf = backend_read($client, $wait) or return ''; |
229 $wait) or return ''; | 235 $body .= $buf; |
230 | 236 |
231 my $got = 0; | 237 my $got = 0; |
232 $got += $chunked ? hex $_ : $_ for $chunked | 238 $got += $chunked ? hex $_ : $_ for $chunked |
233 ? $buf =~ /(\w+)\x0d\x0a?\w+\x0d\x0a?/g | 239 ? $body =~ /(\w+)\x0d\x0a?\w+\x0d\x0a?/g |
234 : length($buf); | 240 : length($body); |
235 last if $got >= $len; | 241 last if $got >= $len; |
236 } | 242 } |
237 | 243 |
238 return $buf; | 244 return $body; |
239 }; | |
240 | |
241 $f->{upload} = sub { | |
242 my ($body, %extra) = @_; | |
243 | |
244 h2_body($sess, $body, { %extra }); | |
245 | |
246 return $body_read->($client, '', length($body), $extra{wait}); | |
247 }; | 245 }; |
248 $f->{http_end} = sub { | 246 $f->{http_end} = sub { |
249 $client->write(<<EOF); | 247 $client->write(<<EOF); |
250 HTTP/1.1 200 OK | 248 HTTP/1.1 200 OK |
251 Connection: close | 249 Connection: close |
252 | 250 |
253 EOF | 251 EOF |
254 | 252 |
255 $client->close; | 253 $client->close; |
256 | 254 |
257 my $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 255 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
258 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 256 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
259 return $frame->{headers}->{':status'}; | 257 return $frame->{headers}->{':status'}; |
260 }; | 258 }; |
261 return $f; | 259 return $f; |
262 } | 260 } |
263 | 261 |
262 sub backend_read { | |
263 my ($s, $timo) = @_; | |
264 my $buf = ''; | |
265 | |
266 if (IO::Select->new($s)->can_read($timo || 3)) { | |
267 $s->sysread($buf, 16384) or return; | |
268 log2i($buf); | |
269 } | |
270 return $buf; | |
271 } | |
272 | |
264 sub log2i { Test::Nginx::log_core('|| <<', @_); } | 273 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
265 sub log2o { Test::Nginx::log_core('|| >>', @_); } | 274 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
266 sub log2c { Test::Nginx::log_core('||', @_); } | 275 sub log2c { Test::Nginx::log_core('||', @_); } |
267 | 276 |
268 ############################################################################### | 277 ############################################################################### |